apigee / apigee-edge-drupal

The Apigee Edge module enables you to integrate a Drupal 9 or 8 site with Apigee.
https://www.drupal.org/project/apigee_edge
GNU General Public License v2.0
32 stars 45 forks source link

Null value compatibility with PHP 8.1 #972

Closed specoto closed 10 months ago

specoto commented 11 months ago
divya-intelli commented 11 months ago

Hi @specoto , please add more details about the issue.

specoto commented 11 months ago

Hi, I have this error on 3.0.2 tag:

Error message Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\apigee_edge_teams\EventSubscriber\TeamStatusWarningSubscriber->onRespond() (line 102 of modules/contrib/apigee_edge/modules/apigee_edge_teams/src/EventSubscriber/TeamStatusWarningSubscriber.php).

Basically we need to have a (string) cast to the first strpos() argument on line 102 if ($this->currentUser->isAuthenticated() && strpos((string) $this->routeMatch->getRouteName(), 'entity.team_app.') === 0) {

specoto commented 11 months ago

I don't seem to have rights for PRs do here is the diff: `diff --git a/modules/apigee_edge_teams/src/EventSubscriber/TeamStatusWarningSubscriber.php b/modules/apigee_edge_teams/src/EventSubscriber/TeamStatusWarningSubscriber.php index 8ebf33ad..bace71dc 100644 --- a/modules/apigee_edge_teams/src/EventSubscriber/TeamStatusWarningSubscriber.php +++ b/modules/apigee_edge_teams/src/EventSubscriber/TeamStatusWarningSubscriber.php @@ -99,7 +99,7 @@ class TeamStatusWarningSubscriber implements EventSubscriberInterface { */ public function onRespond(ResponseEvent $event) { // Anonymous user's does not have access to these routes.

kedarkhaire commented 11 months ago

Hi @specoto Let us know, the steps to reproduce the error, we will look into it. Please add the page also where the issue is seen.

Also please check CONTRIBUTING.md for knowing the contributing workflow. Thanks!

specoto commented 11 months ago

Hi this happens when apigee_edge_teams module is enabled and PHP 8.1 is installed, the error is visible in recent logs when navigating drupal installation.

Thanks!

mxr576 commented 11 months ago

Enabled via Drush, right?

My assumption that the current route is only available in the HTML presentation layer, not in others. Therefore $this->routeMatch->getRouteName() can be null.

specoto commented 11 months ago

Hi @mxr576 after additional debug I see that a rest resource route has been broken (locally )and probably is the cause of this error, however it is still worth adding the cast as prevention and defensive programming. Rector also recommends this approach with a rule: https://github.com/rectorphp/rector/blob/main/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php

kedarkhaire commented 11 months ago

Hi @specoto We tried to replicate the issue by enabling the Apigee Edge teams module from UI as well as via drush, but we don't see mentioned errors on the logs.

kedarkhaire commented 11 months ago

Hi @specoto We checked the other way to see the issue. Following are the steps to reproduce-

Please feel free to create the PR and we will review. Also please check CONTRIBUTING.md for knowing the contributing workflow.

Do let us know for any issue. Thanks!