Problem/Motivation

Postponed until #3270464: Investigate search_api_opensearch as base for elasticsearch_connector has been committed.

PHPStan statically analyzes the code in the module to help identify bugs/issues early.

By increasing the PHPStan level, we increase the number of tests that it runs, and can therefore identify more issues.

Proposed resolution

Increase the PHPStan level to rule level "2".

Fix any major issues (ignore other issues by adding to phpstan-baseline.neon

Explain why we're ignoring certain rules in the phpstan-baseline.neon

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit
  5. Release — released in 8.0.0-alpha1

User interface changes

None.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sokru created an issue. See original summary.

sokru’s picture

Issue summary: View changes
Status: Postponed » Active

BramDriesen made their first commit to this issue’s fork.

bramdriesen’s picture

Status: Active » Needs review
sokru’s picture

Status: Needs review » Needs work

Increasing the PHPStan level creates 48 new errors (see https://git.drupalcode.org/issue/elasticsearch_connector-3426825/-/jobs/...), we should fix them in this issue.

bramdriesen’s picture

3 errors remaining. Not sure what the easiest way to fix those is.

mparker17 made their first commit to this issue’s fork.

mparker17’s picture

@BramDriesen, thank you very much for your hard work!


The remaining issues in src/Plugin/search_api/backend/ElasticSearchBackend.php...

  1. Line 216: Call to an undefined method Drupal\Core\Plugin\PluginFormInterface::getLabel().
  2. Line 217: Call to an undefined method Drupal\Core\Plugin\PluginFormInterface::getDescription().

... are because we were checking if $connector instanceof PluginFormInterface; and PluginFormInterface which doesn't define getLabel() nor getDescription() methods (and it doesn't inherit from any interfaces that define these methods either).

However, if we instead check whether $connector instanceof ElasticSearchConnectorInterface, the PHPStan lints will go away, because ElasticSearchConnectorInterface extends PluginFormInterface (i.e.: so this check is equivalent to the previous check) AND it defines both a getLabel() method and a getDescription() method.


There is one more lint in src/SearchAPI/Query/FilterBuilder.php, "Call to an undefined method Drupal\search_api\Query\ConditionGroupInterface::__toString()." - I will check this out in a bit.

mparker17’s picture

Regarding the Call to an undefined method Drupal\search_api\Query\ConditionGroupInterface::__toString(). lint in src/SearchAPI/Query/FilterBuilder.php, seems like Search API's API could use an improvement, so I've filed #3428603: Declare that ConditionGroupInterface or ConditionGroup implements \Stringable, and we can add this lint to the baseline for now.

mparker17’s picture

Status: Needs work » Needs review

Alright! PHPStan is passing. Moving to Needs Review.

@sokru, did you also want @BramDriesen and/or myself or to address some of the existing items in phpstan-baseline.neon?

mparker17’s picture

Status: Needs review » Reviewed & tested by the community

I was able to fix a deprecated function call, but the other lints in phpstan-baseline.neon are hard to figure out how to change safely, so I'm leaving them here. We should collaborate with the search_api_opensearch maintainers to figure out whether we can delete the code causing those errors.

For now, though, this is RTBC from me, and I'd like another maintainer to review (and ask questions), instead of me merging directly.

  • sokru committed 8be8e726 on 8.0.x authored by BramDriesen
    Issue #3426825 by mparker17, BramDriesen, sokru: Increase PHPstan level...
sokru’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! I agree with decision to leave existing lints to phpstan-baseline.neon, we could research it on separate issue and collaborate with search_api_opensearch module maintainers, and maybe doing it before increasing the level further. It seems we get related errors when reaching level 5.

Also thanks for creating #3428603: Declare that ConditionGroupInterface or ConditionGroup implements \Stringable, maybe we should ask feedback from #search or #contribute on Drupal.org's Slack if we don't get any replies in few weeks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mparker17’s picture

Issue summary: View changes

Update the issue summary to document changes made in this ticket.

mparker17’s picture

Issue summary: View changes