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

strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in Magento2/Sniffs/Less/ClassNamingSniff.php:69 #425

Closed
lykhouzov opened this issue Oct 14, 2022 · 1 comment · Fixed by #426
Labels
bug Something isn't working Progress: done

Comments

@lykhouzov
Copy link

Preconditions

Example of less file

.legal-store-information{
  color: #aaa!important;
  padding: 13px;
  text-align: center;
  font-family: Arial, sans-serif;
  font-size: 0.8em;
  display: block;

  .a{
    color: #aaa!important;

    &:hover {
      color: #fff!important;
    }
    &:visited {
      color: #aaa!important;
    }
  }
}

Steps to reproduce

  1. run vendor/bin/phpcs -d memory_limit=2G --standard=Magento2 --report-\\Micheh\\PhpCodeSniffer\\Report\\Gitlab=report-phpcs.json --basepath=/var/www/html app/design/frontend/Phoenix/

Expected result

Normal report

Actual result

Fatal Error.

PHP Fatal error:  Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php:69
Stack trace:
#0 /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php(69): strpos()
#1 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Less\ClassNamingSniff->process()
#2 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(628): PHP_CodeSniffer\Files\LocalFile->process()
#4 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile()
#5 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
#6 /var/www/html/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#7 {main}
  thrown in /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php on line 69

As you can see from less file, a class name is shorter than the expected offset 2.
A possible solution is to check the string length before checking the underscore in the className, or check if the found position is bigger than 2

@lykhouzov lykhouzov added the bug Something isn't working label Oct 14, 2022
@m2-assistant
Copy link

m2-assistant bot commented Oct 14, 2022

Hi @lykhouzov. 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


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
Development

Successfully merging a pull request may close this issue.

1 participant