Skip to content

Fix TypeError for phpcs->addWarning() #205

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

Merged
merged 4 commits into from
Jul 28, 2021

Conversation

fredden
Copy link
Member

@fredden fredden commented May 24, 2021

Argument 4 of PHP_CodeSniffer->addWarning() must be an array; integer given.

https://github.com/squizlabs/PHP_CodeSniffer/blob/a71aad2074891a5fc4b2f7e891282c9333830efd/src/Files/File.php#L683

    Fatal error: Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, int given in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php:1056
    Stack trace:
    #0 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(1056): vsprintf('Direct throw of...', 531)
    #1 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(706): PHP_CodeSniffer\Files\File->addMessage(false, 'Direct throw of...', 67, 4, 'FoundDirectThro...', 531, 8, false)
    #2 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Exceptions/DirectThrowSniff.php(48): PHP_CodeSniffer\Files\File->addWarning('Direct throw of...', 526, 'FoundDirectThro...', 531)
    #3 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Exceptions\DirectThrowSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 526)
    #4 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
    #5 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process()
    #6 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
    #7 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
    #8 /srv/www/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
    #9 {main}
      thrown in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 1056

fredden added 2 commits May 24, 2021 16:21
    Fatal error: Uncaught TypeError: vsprintf(): Argument magento#2 ($values) must be of type array, int given in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php:1056
    Stack trace:
    #0 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(1056): vsprintf('Direct throw of...', 531)
    magento#1 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(706): PHP_CodeSniffer\Files\File->addMessage(false, 'Direct throw of...', 67, 4, 'FoundDirectThro...', 531, 8, false)
    magento#2 /srv/www/vendor/magento/magento-coding-standard/Magento2/Sniffs/Exceptions/DirectThrowSniff.php(48): PHP_CodeSniffer\Files\File->addWarning('Direct throw of...', 526, 'FoundDirectThro...', 531)
    magento#3 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Exceptions\DirectThrowSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 526)
    magento#4 /srv/www/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
    #5 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process()
    magento#6 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
    magento#7 /srv/www/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
    magento#8 /srv/www/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
    magento#9 {main}
      thrown in /srv/www/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 1056
@ihor-sviziev
Copy link
Collaborator

@sivaschenko please review

@ihor-sviziev
Copy link
Collaborator

Hi @fredden,
Could you provide some steps to reproduce?

@fredden
Copy link
Member Author

fredden commented Jul 26, 2021

Easiest way to reproduce is to run php -r 'var_dump(vsprintf("%d", [1]));' and php -r 'var_dump(vsprintf("%d", 1));' with PHP v8.0. With PHP v8.0, running vendor/bin/phpunit shows the error.

Screenshot_2021-07-27_00-41-59

ihor-sviziev added a commit to ihor-sviziev/magento-coding-standard that referenced this pull request Jul 27, 2021
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.

Hi,

I tested these changes on top of PHP 8 - works fine.
Before these changes:
❌ We have an error
image
https://github.com/magento/magento-coding-standard/runs/3170690636

After:
✔ No errors
image
https://github.com/magento/magento-coding-standard/runs/3170628234

@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 9f38b7a into magento:develop Jul 28, 2021
@fredden fredden deleted the vsprintf branch August 21, 2021 16:08
magento-devops-reposync-svc pushed a commit that referenced this pull request Mar 28, 2023
…o-coding-standard-426

[Imported] Fix PHP error with short class names
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