0

I am working on an analytics plugin for Shopware to expand the statistics section. Everything works as expected, but when I wanted to commit the code for the controller I got the above mentioned error.

I can't seem to find the problem and would be thankful for any input.

<?php

class Shopware_Controllers_Backend_CustomStatistics extends Shopware_Controllers_Backend_ExtJs
{
  public function getPreorderSubsAction() {
    $connection = $this->container->get('dbal_connection');
    $query = $connection->createQueryBuilder();
    $query->select([
      'ps.abo',
      'smao.name',
      'ROUND(SUM(ps.preordered * ps.unit_price),2) AS preorder_value'
      ])
      ->from('vw_PreorderSubs', 'ps')
      ->join('ps','salt_model_abo', 'smao','ps.abo = smao.id')
      ->groupBy('ps.abo');

    $data = $query->execute()->fetchAll();

    $this->View()->assign([
        'success' => true,
        'data' => $data,
        'count' => count($data)
    ]);
  }
}

The corresponding code from the codesniffer:


// Check if this line is ignoring all message codes.
        if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
            return false;
        }

        // Work out which sniff generated the message.
        $parts = explode('.', $code);
        if ($parts[0] === 'Internal') {
            // An internal message.
            $listenerCode = Util\Common::getSniffCode($this->activeListener);
            $sniffCode    = $code;
            $checkCodes   = [$sniffCode];
        } else {
            if ($parts[0] !== $code) {
                // The full message code has been passed in.
                $sniffCode    = $code;
                $listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
            } else {
                $listenerCode = Util\Common::getSniffCode($this->activeListener);
                $sniffCode    = $listenerCode.'.'.$code;
                $parts        = explode('.', $sniffCode);
            }

            $checkCodes = [
                $sniffCode,
                $parts[0].'.'.$parts[1].'.'.$parts[2],
                $parts[0].'.'.$parts[1],
                $parts[0],
            ];
        }//end if

Line 863 is

$parts[0].'.'.$parts[1].'.'.$parts[2],
mel_p
  • 1
  • 2
  • Which is the exact line it's pointing to? – aynber Feb 17 '22 at 14:58
  • it is not pointing to any line, the error message just reads: 1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: Undefined offset: 2 in home/foldername/PHP_CodeSniffer/src/Files/File.php on line 863 – mel_p Feb 17 '22 at 15:02
  • `line 863` **is** the line. What is line 863 in file Files/File.php? – aynber Feb 17 '22 at 15:10
  • Oh, thank you! I added the code from the Files.php in the original question! – mel_p Feb 17 '22 at 15:15

1 Answers1

0

It appears that a misplaced { was the cause for the error:

<?php

class Shopware_Controllers_Backend_CustomStatistics extends Shopware_Controllers_Backend_ExtJs {
  /**
   * calls the getPreorderSubsAction function that connects with the database and
   * delivers the content for the new statistics table
   *
   * @return void
   */
  public function getPreorderSubsAction() {
    $connection = $this->container->get('dbal_connection');
    $query = $connection->createQueryBuilder();
    $query->select([
      'ps.abo',
      'smao.name',
      'ROUND(SUM(ps.preordered * ps.unit_price),2) AS preorder_value'
      ])
      ->from('vw_PreorderSubs', 'ps')
      ->join('ps','salt_model_abo', 'smao','ps.abo = smao.id')
      ->groupBy('ps.abo');

    $data = $query->execute()->fetchAll();

    $this->View()->assign([
        'success' => true,
        'data' => $data,
        'count' => count($data)
    ]);
  }
}

This works now.

mel_p
  • 1
  • 2