Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bgorski opened this issue Oct 21, 2021 · 4 comments · Fixed by #317
Assignees
Labels
bug Something isn't working Progress: done

Comments

@bgorski
Copy link

bgorski commented Oct 21, 2021

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)
  }
}
@bgorski bgorski added the bug Something isn't working label Oct 21, 2021
@m2-assistant
Copy link

m2-assistant bot commented Oct 21, 2021

Hi @bgorski. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


@barbazul
Copy link

Looks like a duplicate of #280

@bgorski
Copy link
Author

bgorski commented Oct 22, 2021

@barbazul it's not. While typed properties cause the sniff to fail in both tickets, in there different behavior is reported, it's marked as fixed and closed.
In here, the sniff fails to process the code completely.

@sivaschenko
Copy link
Member

Thanks for reporting @bgorski , fixed in #317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Progress: done
Projects
None yet
3 participants