Skip to content
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

phpcs error on rule classes - must be of the type integer #20186

Closed
ipascual opened this issue Jan 10, 2019 · 15 comments
Closed

phpcs error on rule classes - must be of the type integer #20186

ipascual opened this issue Jan 10, 2019 · 15 comments
Assignees
Labels
Component: StaticTest Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@ipascual
Copy link

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.

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jan 10, 2019
@magento-engcom-team
Copy link
Contributor

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

@ipascual
Copy link
Author

@magento-engcom-team give me 2.3 instance

@orlangur orlangur self-assigned this Jan 10, 2019
@magento-engcom-team
Copy link
Contributor

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: 👇

  • 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.

@ghost ghost self-assigned this Jan 11, 2019
@magento-engcom-team
Copy link
Contributor

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: 👇

  • 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.

@ghost ghost added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Jan 14, 2019
@ghost
Copy link

ghost commented Jan 14, 2019

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

@ghost ghost closed this as completed Jan 14, 2019
@haelbichalex
Copy link

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

@dng-dev
Copy link
Contributor

dng-dev commented Mar 28, 2019

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.

@orlangur orlangur reopened this Mar 30, 2019
@ghost ghost assigned ghost and unassigned orlangur and ghost Mar 30, 2019
@ghost ghost added the Component: StaticTest label Apr 1, 2019
@ghost ghost assigned Nazar65 Apr 1, 2019
@ghost ghost added Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Apr 1, 2019
@ghost ghost removed their assignment Apr 1, 2019
@magento-engcom-team
Copy link
Contributor

✅ 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.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Apr 1, 2019
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Apr 9, 2019
@magento-engcom-team
Copy link
Contributor

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

The fix will be available with the upcoming 2.3.2 release.

@mattijv
Copy link
Contributor

mattijv commented May 17, 2019

@magento-engcom-team Unfortunately #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 #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.

@mattijv mattijv reopened this May 17, 2019
@ghost ghost unassigned Nazar65 May 17, 2019
@ghost ghost removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels May 17, 2019
@Nazar65
Copy link
Member

Nazar65 commented May 17, 2019

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

@mattijv
Copy link
Contributor

mattijv commented May 17, 2019

@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{}

@Nazar65
Copy link
Member

Nazar65 commented May 17, 2019

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

@Nazar65 Nazar65 self-assigned this May 17, 2019
@m2-assistant
Copy link

m2-assistant bot commented May 17, 2019

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: 👇

  • 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

@magento-engcom-team
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: StaticTest Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests

7 participants