简体   繁体   English

PHP_Codesniffer 说“Undefined offset: 2 in /PHP_Codesniffer/src/Files/File.php on line 863”

[英]PHP_Codesniffer says "Undefined offset: 2 in /PHP_Codesniffer/src/Files/File.php on line 863"

I am working on an analytics plugin for Shopware to expand the statistics section.我正在为 Shopware 开发一个分析插件来扩展统计部分。 Everything works as expected, but when I wanted to commit the code for the controller I got the above mentioned error.一切都按预期工作,但是当我想提交 controller 的代码时,出现了上述错误。

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:来自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第863行是

$parts[0].'.'.$parts[1].'.'.$parts[2],

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.这现在有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM