cakephp-codesniffer
cakephp-codesniffer copied to clipboard
Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined property
trafficstars
Ran phpcbf --colors -p src/ tests/ on my CakePHP 5 project:
Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined property: PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode::$type in /srv/app/vendor/cakephp/cakephp-codesniffer/CakePHP/Sniffs/Commenting/TypeHintSniff.php on line 104 in /srv/app/vendor/squizlabs/php_codesniffer/src/Runner.php:623
Stack trace:
#0 /srv/app/vendor/cakephp/cakephp-codesniffer/CakePHP/Sniffs/Commenting/TypeHintSniff.php(104): PHP_CodeSniffer\Runner->handleErrors(2, 'Undefined prope...', '/srv/app/vendor...', 104)
#1 /srv/app/vendor/squizlabs/php_codesniffer/src/Files/File.php(519): CakePHP\Sniffs\Commenting\TypeHintSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 103)
#2 /srv/app/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 /srv/app/vendor/squizlabs/php_codesniffer/src/Fixer.php(175): PHP_CodeSniffer\Files\LocalFile->process()
#4 /srv/app/vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 /srv/app/vendor/squizlabs/php_codesniffer/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport(Array, Object(PHP_CodeSniffer\Files\LocalFile), false, 190)
#6 /srv/app/vendor/squizlabs/php_codesniffer/src/Runner.php(706): PHP_CodeSniffer\Reporter->cacheFileReport(Object(PHP_CodeSniffer\Files\LocalFile))
#7 /srv/app/vendor/squizlabs/php_codesniffer/src/Runner.php(453): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#8 /srv/app/vendor/squizlabs/php_codesniffer/src/Runner.php(215): PHP_CodeSniffer\Runner->run()
#9 /srv/app/vendor/squizlabs/php_codesniffer/bin/phpcbf(14): PHP_CodeSniffer\Runner->runPHPCBF()
#10 /srv/app/vendor/bin/phpcbf(119): include('/srv/app/vendor...')
#11 {main}
thrown in /srv/app/vendor/squizlabs/php_codesniffer/src/Runner.php on line 623
After running in verbose mode I identified it was having issues with this class:
<?php
declare(strict_types=1);
namespace App\Model\Behavior;
use App\Exception\InvalidSearchValueException;
use App\Model\Filter\FilterValidationInterface;
use ArrayObject;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use Cake\ORM\Query;
/**
* Runs validations of friendsofcake/search when this behavior is applied on the Table class.
*/
class FilterRequestValidatorBehavior extends Behavior
{
/**
* Runs validations on FilterCollections implementing FilterValidationInterface
*
* @param EventInterface $event
* @param Query $query
* @param ArrayObject $options
* @param $primary
* @return void
*/
public function beforeFind(EventInterface $event, Query $query, ArrayObject $options, $primary): void
{
$searchParams = $options['search'] ?? null;
if (!$this->table()->hasBehavior('Search') || !is_array($searchParams)) {
return;
}
/** @var \Search\Model\Behavior\SearchBehavior $searchBehavior */
$searchBehavior = $this->table()->getBehavior('Search');
$filterCollection = $searchBehavior->searchManager()->getFilters();
if (!$filterCollection instanceof FilterValidationInterface) {
return;
}
$result = $filterCollection->getValidator()->validate($searchParams);
if (!empty($result)) {
$field = key($result);
$error = reset($result);
$type = key($error);
$msg = $error[$type];
throw new InvalidSearchValueException("Search parameter value for `$field` is invalid. $msg");
}
}
}
Removing the comments above beforeFind seems to have resolved?
Versions:
/srv/app $ composer show -i | grep sniff
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
cakephp/cakephp-codesniffer 5.1.1 CakePHP CodeSniffer Standards
dealerdirect/phpcodesniffer-composer-installer v1.0.0 PHP_CodeSniffer Standards Composer Installer Plugin
slevomat/coding-standard 8.15.0 Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.
squizlabs/php_codesniffer 3.9.1 PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
@param $primary is missing the type
But it would still be nice if the sniffer wouldn't fail that hard in this case.
Afaik this is fixed in https://github.com/php-collective/code-sniffer/blob/661c6bb2ce1c52233df5f74d489a8b0f5e9738da/PhpCollective/Sniffs/Commenting/TypeHintSniff.php#L120-L122 and could be pulled in.