Skip to content

Magento2.Commenting.ClassPropertyPHPDocFormatting throws an error when processing typed class properties #315

Closed
@bgorski

Description

@bgorski

Preconditions

Steps to reproduce

  1. Try processing a class that has typed properties. Here's a sample:
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\TestFramework\Store;

class StoreManager
{
    /**
     * @var \Magento\Store\Model\StoreManager
     */
    private \Magento\Store\Model\StoreManager $decoratedStoreManager;

    /**
     * Constructor
     *
     * @param \Magento\Store\Model\StoreManager $decoratedStoreManager
     */
    public function __construct(
        \Magento\Store\Model\StoreManager $decoratedStoreManager
    ) {
        $this->decoratedStoreManager = $decoratedStoreManager;
    }

    /**
     * Test
     *
     * @return null
     */
    public function test() {
        return null;
    }
}

Expected result

  1. The class can be processed

Actual result

  1. Processing fails with the following error:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: Undefined index: comment_opener in /home/bgorski/devilbox/data/www/github-magento2-ce/htdocs/vendor/magento/magento-coding-standard/Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php on
   |       | line 71
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


This prevents phpcs from processing the class any further.

That's the token wrongly interpreted as a comment closing:

array(8) {
  ["code"]=>
  int(393)
  ["type"]=>
  string(14) "T_NS_SEPARATOR"
  ["content"]=>
  string(1) "\"
  ["line"]=>
  int(13)
  ["column"]=>
  int(33)
  ["length"]=>
  int(1)
  ["level"]=>
  int(1)
  ["conditions"]=>
  array(1) {
    [26]=>
    int(364)
  }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions