Skip to content

Fix magento/magento-coding-standard#214 with class not found #215

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

Conversation

edspc
Copy link

@edspc edspc commented Aug 9, 2021

Just copied the original classes from the framework to fix the problem.

@edspc edspc force-pushed the tokenizer_parameter_not_found branch from ea4f0dc to 825857b Compare August 9, 2021 15:50
*/
public function setString($value)
{
//phpcs:ignore Magento2.Functions.DiscouragedFunction
Copy link
Author

@edspc edspc Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally added this line for the pipeline.

@ihor-sviziev
Copy link
Collaborator

ihor-sviziev commented Aug 10, 2021

Hi @edspc,
Could you provide some info, how to reproduce the issue?
So far, the issue isn't reproducing on the develop branch while testing this repo via phpcs using vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php:
https://github.com/magento/magento-coding-standard/runs/3252930009?check_suite_focus=true
image

Note: that's 2nd PR after #211 that fixes issues in this class, but we don't see these failures during the test runs. It seems like we should add some additional checks to them.

@edspc
Copy link
Author

edspc commented Aug 10, 2021

Hi, @ihor-sviziev,
We have faced that fatal exception while running PHPCS for a .phtml file containing the following code:

{{getBlockLabel(type, block)}}

Currently, HtmlDirectiveSniff in develop branch has two references for non-existent classes (one & two).

Copy link
Collaborator

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔ Approved

Before:
❌ We have fatal error

$ vendor/bin/phpcs --standard=Magento2 /var/www/html/magento2/dev/tests/static/framework/tests/unit/testsuite/Magento/Sniffs/Html/_files --extensions=html
PHP Fatal error:  Uncaught Error: Class 'Magento2\Sniffs\Html\Template\Tokenizer\Variable' not found in /var/www/html/magento-coding-standard/Magento2/Sniffs/Html/HtmlDirectiveSniff.php:188
Stack trace:
#0 /var/www/html/magento-coding-standard/Magento2/Sniffs/Html/HtmlDirectiveSniff.php(83): Magento2\Sniffs\Html\HtmlDirectiveSniff->validateVariableUsage()
#1 /var/www/html/magento-coding-standard/Magento2/Sniffs/Html/HtmlDirectiveSniff.php(63): Magento2\Sniffs\Html\HtmlDirectiveSniff->processIfDirectives()
#2 /var/www/html/magento-coding-standard/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Html\HtmlDirectiveSniff->process()
#3 /var/www/html/magento-coding-standard/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#4 /var/www/html/magento-coding-standard/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process()
#5 /var/www/html/m in /var/www/html/magento-coding-standard/Magento2/Sniffs/Html/HtmlDirectiveSniff.php on line 188

After:
✔ We don't have any fatal error

$ vendor/bin/phpcs --standard=Magento2 /var/www/html/magento2/dev/tests/static/framework/tests/unit/testsuite/Magento/Sniffs/Html/_files --extensions=html

FILE: /var/www/html/magento2/dev/tests/static/framework/tests/unit/testsuite/Magento/Sniffs/Html/_files/test-html-directive.html
----------------------------------------------------------------------------------------------------------------------------------------
FOUND 20 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badif().bad"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badif3()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badDepend().bad"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badForLoop()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.bad()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.bad()|alsobad"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.bad($bad.param())"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.bad.baz()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.bad.trans()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "bad.bad()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "bad.multiline()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badif2()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badif4()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badif5()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.baddepend2()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
   |       | Found "foo.badFor()"
 1 | ERROR | Template directives may not invoke methods. Only scalar array access is allowed.
 
 ...
 
 FILE: /var/www/html/magento2/dev/tests/static/framework/tests/unit/testsuite/Magento/Sniffs/Html/_files/test-html-binding.html
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | Variables/functions used for HTML binding must have UnsanitizedHtml suffix - "testError()" doesn't,
   |       | consider using text binding if the value is supposed to be text
 1 | ERROR | Variables/functions used for HTML binding must have UnsanitizedHtml suffix - "test.getSomething().value.error()" doesn't,
   |       | consider using text binding if the value is supposed to be text
 1 | ERROR | Variables/functions used for HTML binding must have UnsanitizedHtml suffix - "bind_stuff(1, 2)" doesn't,
   |       | consider using text binding if the value is supposed to be text
 1 | ERROR | Variables/functions used for HTML binding must have UnsanitizedHtml suffix - "testError()" doesn't,
   |       | consider using text binding if the value is supposed to be text
 1 | ERROR | Variables/functions used for HTML binding must have UnsanitizedHtml suffix - "test.getSomething().value.error(1)" doesn't,
   |       | consider using text binding if the value is supposed to be text
 1 | ERROR | Variables/functions used for HTML binding must have UnsanitizedHtml suffix - "bind_stuff()" doesn't,
   |       | consider using text binding if the value is supposed to be text
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 42ms; Memory: 8MB

@sivaschenko
Copy link
Member

@magento import pr to magento-commerce/magento-coding-standard

@magento-engcom-team
Copy link
Contributor

@sivaschenko the pull request successfully imported.

@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 1ca7ced into magento:develop Aug 20, 2021
magento-devops-reposync-svc pushed a commit that referenced this pull request May 2, 2023
ACP2E-1871: Extend PHPCompatibility.FunctionUse.RemovedFunctions to add deprecated/removed functions in PHP8.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants