Problem/Motivation

Recent pipelines report phpstan findings

Steps to reproduce

See for example https://git.drupalcode.org/issue/search_api-3616718/-/jobs/11546838

Proposed resolution

Fix phpstan findings in recent pipelines

Remaining tasks

  1. Write a merge request
  2. Review
  3. Commit

Issue fork search_api-3616723

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

idebr created an issue. See original summary.

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

yusuf_khan’s picture

Status: Active » Needs review
daften’s picture

Status: Needs review » Needs work

I was checking my pipelines and saw one of my issues failed and ended up on this issue. Thanks for tackling this.

Some feedback that I see:

  • You are also fixing phpunit, so updating the title and description and link to a job with failing phpunit tests should make this issue clearer.
  • Adding @ in front of trigger_error doesn't seem related to phpstan or phpunit failed jobs (but perhaps I'm missing something)
  • The change to src/Plugin/views/field/SearchApiEntity.php seems unrelated to phpstan report linked
  • Some changes mean the module will only support Drupal 11.3 and up, so a .info.yml file change will be needed I think. Another option is to selectively ignore certain items e.g. the CacheableMetadata to ensure compatibility with older Drupal versions (for now)

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

benstallings’s picture

Status: Needs work » Needs review

That's good feedback, @daften! I left the change to SearchApiEntity.php in place because it is flagged by phpcs, if not by phpstan.

drunken monkey made their first commit to this issue’s fork.

drunken monkey’s picture

I hope I was now able to fix all the warnings/errors reported by static analysis. For the PHPUnit failures I’ll follow up in #3624636: Fix failing pipelines.

abhisekmazumdar’s picture

FYI, since the latest commit here (d6ef078a) the Drupal AI module's pipelines fail on Drupal 11.4 with:

TypeError: SearchApiViewsHooks::__construct(): Argument #9 ($memoryCache) must be of type MemoryCacheInterface, MemoryBackend given

It looks like cache.static returns a plain MemoryBackend, which doesn't implement MemoryCacheInterface. Type-hinting CacheBackendInterface might be enough, since only get() and set() are used.

Failing job: https://git.drupalcode.org/project/ai/-/jobs/12712634

scott_euser’s picture

Thanks! Diff fixes the fatal error with the type-hint change.

Quick AI check on it and it flagged this though:

Separately, getHandlerMapping() and getFieldHandlerMapping() compare the raw get() return value with is_array(), but CacheBackendInterface::get() returns an object or FALSE, so the static cache never hits. Suggest $mapping = $this->memoryCache->get($cid)->data ?? NULL; (and the same for $mappings).

I have not checked it but could check it asap if it sounds wrong (school pickup time!)

  • drunken monkey committed 428f3439 on 8.x-1.x
    fix: #3616723 Follow-up: Fixed bugs introduced in previous commit.
    
    By:...
drunken monkey’s picture

Status: Needs review » Fixed

Merged a bit too hastily, but now static analysis should pass again for all tested configurations and no new bugs should have been introduced.
Thanks, everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

drunken monkey’s picture

Status: Fixed » Needs work

Oops, sorry, didn’t see the last comments before posting.
The comments about getHandlerMapping() and getFieldHandlerMapping() seem worth pursuing.

drunken monkey’s picture

Status: Needs work » Needs review
scott_euser’s picture

Status: Needs review » Reviewed & tested by the community

Np looks good to me, thank you!

  • drunken monkey committed b00aa789 on 8.x-1.x
    fix: #3616723 Follow-up: Fixed static caching in SearchApiViewsHooks....
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reviewing, merged!
Hopefully at least nothing is worse off than before now …

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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