Magento2: phpcs error on rule classes - must be of the type integer

Created on 10 Jan 2019  路  15Comments  路  Source: magento/magento2

Preconditions (*)

  1. You need code under app/code

Steps to reproduce (*)

  1. ./vendor/bin/phpcs --standard=./dev/tests/static/framework/Magento/ app/code/

Expected result (*)

  1. phpcs should report in the terminal all errors and warnings.

Actual result (*)

  1. Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Sniffs\Annotation\ClassAnnotationStructureSniff::validateAnnotationBlockExists() must be of the type integer, boolean given, called in /var/www/magento2/dev/tests/static/framework/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php on line 100 and defined in /var/www/magento2/dev/tests/static/framework/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php:76

Solution

For some reason, the functions are using Variable Typing for integers, however some scenarios is sending boolean. I fixed my local removing the variable typing of any "int" in method signature.

StaticTest Fixed in 2.3.x Clear Description Format is valid

Most helpful comment

Hi @ipascual, @Nazar65.

Thank you for your report and collaboration!

The issue was fixed by Magento team.

The fix will be available with the upcoming 2.3.3 release.

All 15 comments

Hi @ipascual. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

@ipascual do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

@magento-engcom-team give me 2.3 instance

Hi @orlangur. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi @ipascual thank you for you report, you need to use following
./vendor/bin/phpcs --standard=./dev/tests/static/framework/Magento/ruleset.xml app/code/Magento/Amqp

I have the exact same issue. I'm already using the dev/tests/static/framework/Magento/ruleset.xml file. How can I fix it?

using Version 2.3.1

I have the same with all anotation sniffs.
Magento.Annotation.MethodArguments
Magento.Annotation.MethodAnnotationStructure
Magento.Annotation.ClassAnnotationStructure

every rule i excluded via * for now.

:white_check_mark: Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-98993, MAGETWO-98994 were created

Issue Available: @engcom-backlog-nazar, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Hi @ipascual. Thank you for your report.
The issue has been fixed in magento/magento2#22081 by @Nazar65 in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

@magento-engcom-team Unfortunately https://github.com/magento/magento2/pull/22081 does in no way fix the real issue in the Sniff, but pushes the problem a few lines down in the code.

The issue is that the PHP_CodeSniffer\Files\File::findPrevious method returns either a pointer to the previous token of a type or false if none is found. This case is triggered when the CodeSniffer is running on a file with no closing comment tags.

Earlier the issue was because this false was passed to a function which expected an int instead. What https://github.com/magento/magento2/pull/22081 does is to cast the boolean into an integer, which obviously is not correct (as the Sniff now treats the code like there is a comment closing token at position 0 when in fact there is none in the file).

Now the Sniff returns a new error as it's trying to get the closing comment from the token list:

An error occurred during processing; checking has been aborted.
The error message was: Undefined index: comment_closer in
dev/tests/static/framework/Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php on line 102

Steps to reproduce the error:

  1. clean Magento installation on 2.3-develop branch
  2. create a Foo.php file with the following contents
<?php
class Foo{}
  1. run the phpcs on that file with the Magento ruleset ./vendor/bin/phpcs --standard=./dev/tests/static/framework/Magento/ Foo.php

Expected result:

Normal PHP_CodeSniffer warnings about missing docblocks etc.

Actual result:

The above mentioned error.

Suggested fix

Change the Sniff so that if the pointer returned from PHP_CodeSniffer\Files\File::findPrevious is false, a warning is generated instead of passing the false value as an integer to the next function.

Hi @mattijv i'm have following result -> can you explain ?
DeepinScreenshot_select-area_20190517150259

@Nazar65 My bad, seems like there is another edge case that the code hits first with my example. The reason again is most likely the same (i.e. false being cast to 0) which leads to the $stackPtr - 2 calculation returning -1 as the token index.

If you add an empty line between <?php and class Foo{} you get the error I reported.

<?php

class Foo{}

@mattijv yeap, thx, i will work on it.

Hi @Nazar65. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x


Hi @ipascual, @Nazar65.

Thank you for your report and collaboration!

The issue was fixed by Magento team.

The fix will be available with the upcoming 2.3.3 release.

Was this page helpful?
0 / 5 - 0 ratings