Problem/Motivation

PHPStan (level 5) reports an error in src/Controller/CollectionExportController.php:

------ ----------------------------------------------------------------------------------------------------
 Line   src/Controller/CollectionExportController.php
------ ----------------------------------------------------------------------------------------------------
 68     Using nullsafe method call on non-nullable type Drupal\search_api\ServerInterface. Use -> instead.
        nullsafe.neverNull
------ ----------------------------------------------------------------------------------------------------

In __invoke(), the server instance is fetched and then its backend is checked with an instanceof guard that throws when it is not the Typesense backend. Because a null server would yield a null backend (which is not an instance of SearchApiTypesenseBackend and therefore throws), PHPStan narrows $search_api_server to a non-nullable ServerInterface from that point on. The nullsafe operator on line 68 is consequently redundant, and PHPStan fails the build.

Steps to reproduce

Run static analysis on the module:

ddev phpstan src

Proposed resolution

Drop the nullsafe operator on line 68.

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

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Status: Active » Needs review

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

lussoluca’s picture

Status: Needs review » Fixed

Released in 1.2.0-beta3, thanks!

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.

nitinkumar_7’s picture

I just finished testing and was writing up my review comment when it got marked as fixed : )

lussoluca’s picture

Cool :-),
Hopefully the fix works

nitinkumar_7’s picture

Yes, it's working perfectly. Thank you for the credit!