Skip to content

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

Closed
@lykhouzov

Description

@lykhouzov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions