Running phpcs check returns the below error:

FILE: src/Plugin/search_api_autocomplete/suggester/BackendTrait.php
--------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------
 38 | ERROR | "$this" can no longer be used in a plain function or method since PHP 7.1.
--------------------------------------------------------------
CommentFileSizeAuthor
#10 3150197.patch1.13 KBmkalkbrenner
#4 3150197-4.patch497 bytessuzymasri
#2 3150197-2.patch510 bytessuzymasri
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

suzymasri created an issue. See original summary.

suzymasri’s picture

Status: Active » Needs review
FileSize
510 bytes

Patch attached.

mkalkbrenner’s picture

Status: Needs review » Needs work

The patch isn't correct.

We use the Search API internal logger here, not Drupal's.

suzymasri’s picture

FileSize
497 bytes

Thanks @mkalkbrenner, corrected patch attached.

Let me know if you have any other notes.

suzymasri’s picture

Status: Needs work » Needs review
mkalkbrenner’s picture

This way you skip a lot of logic:

  protected function logException(\Exception $exception, $message = NULL, array $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) {
    // Use a default value if $message is not set.
    if (empty($message)) {
      $message = '%type: @message in %function (line %line of %file).';
    }

    if ($link) {
      $variables['link'] = $link;
    }

    $variables += Error::decodeException($exception);

    $this->getLogger()->log($severity, $message, $variables);
  }

The code works as it is. I think the correct fix is to actively tell PHPCS that this isn't an error!

mkalkbrenner’s picture

Status: Needs review » Needs work

mkalkbrenner’s picture

Title: PHPCS Error » BackendTrait for Suggesters fails on logging Exceptions
Category: Task » Bug report
Issue tags: -PHP 7.3

You're right. I didn't notice that getBackend() has to be static as it is called in a static context.

mkalkbrenner’s picture

Status: Needs work » Needs review
FileSize
1.13 KB

  • mkalkbrenner committed a45f8ea on 4.x
    Issue #3150197 by suzymasri, mkalkbrenner, kfritsche: BackendTrait for...
mkalkbrenner’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

suzymasri’s picture

Thanks a lot @mkalkbrenner for helping out!