diff --git a/composer.json b/composer.json index 738599a7..9b7824b0 100644 --- a/composer.json +++ b/composer.json @@ -78,7 +78,7 @@ "lowest": "validate-prefer-lowest", "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json", "stan": "phpstan analyse", - "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^1.0.0 && mv composer.backup composer.json", + "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^2.0.0 && mv composer.backup composer.json", "stan-tests": "phpstan analyse -c tests/phpstan.neon", "test": "phpunit", "test-coverage": "phpunit --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml" diff --git a/phpstan.neon b/phpstan.neon index efb6acd8..4f82cbc9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,13 +1,9 @@ -services: - - - class: IdeHelper\PHPStan\AssociationTableMixinClassReflectionExtension - tags: - - phpstan.broker.methodsClassReflectionExtension - - phpstan.broker.propertiesClassReflectionExtension parameters: level: 8 paths: - src/ + + treatPhpDocTypesAsCertain: false bootstrapFiles: - tests/bootstrap.php - tests/shim.php diff --git a/src/Annotator/CommandAnnotator.php b/src/Annotator/CommandAnnotator.php index 5b29f74b..d4c72263 100644 --- a/src/Annotator/CommandAnnotator.php +++ b/src/Annotator/CommandAnnotator.php @@ -45,7 +45,6 @@ protected function getPrimaryModelClass(string $content): ?string { return null; } - /** @var string $modelName */ $modelName = $matches[1]; return $modelName; diff --git a/src/Annotator/TemplateAnnotator.php b/src/Annotator/TemplateAnnotator.php index 5400615e..2e4fa3b7 100644 --- a/src/Annotator/TemplateAnnotator.php +++ b/src/Annotator/TemplateAnnotator.php @@ -337,7 +337,6 @@ protected function parseLoopEntities(string $content): array { $result = []; - /** @var array $entities */ $entities = $matches[2]; foreach ($entities as $key => $entity) { if (Inflector::pluralize($entity) !== $matches[1][$key]) { @@ -355,7 +354,6 @@ protected function parseLoopEntities(string $content): array { $annotation = GenericString::generate('\\' . $className); if (Configure::read('IdeHelper.templateCollectionObject') !== false) { $collectionClass = CollectionClass::name('\\' . CollectionInterface::class); - /** @var string|bool|null $collectionType */ $collectionType = Configure::read('IdeHelper.templateCollectionObject'); if (Configure::read('IdeHelper.objectAsGenerics') === true && $collectionType !== 'iterable') { $annotation .= '|' . GenericString::generate('\\' . $className, $collectionClass); diff --git a/src/Command/AnnotateCommand.php b/src/Command/AnnotateCommand.php index 825079cd..3731746a 100644 --- a/src/Command/AnnotateCommand.php +++ b/src/Command/AnnotateCommand.php @@ -129,8 +129,6 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption * @return \IdeHelper\Console\Io */ protected function _io(): Io { - assert($this->io !== null, 'IO not set'); - return new Io($this->io); } @@ -140,8 +138,6 @@ protected function _io(): Io { * @return bool */ protected function _shouldSkip(string $fileName): bool { - assert($this->args !== null, 'Args not set'); - $filter = (string)$this->args->getOption('filter'); if (!$filter) { return false; @@ -175,8 +171,6 @@ protected function getAnnotator(string $class): AbstractAnnotator { } if (!isset($this->_instantiatedAnnotators[$class])) { - assert($this->args !== null, 'Args not set'); - $this->_instantiatedAnnotators[$class] = new $class($this->_io(), $this->args->getOptions()); } diff --git a/src/Command/GeneratePhpStormMetaCommand.php b/src/Command/GeneratePhpStormMetaCommand.php index 352c79db..32f56b95 100644 --- a/src/Command/GeneratePhpStormMetaCommand.php +++ b/src/Command/GeneratePhpStormMetaCommand.php @@ -124,8 +124,6 @@ protected function ensureDir(): void { * @return \IdeHelper\Console\Io */ protected function io(): Io { - assert($this->io !== null, 'IO not set'); - return new Io($this->io); } diff --git a/src/Generator/Directive/BaseDirective.php b/src/Generator/Directive/BaseDirective.php index 5123ce57..91617e50 100644 --- a/src/Generator/Directive/BaseDirective.php +++ b/src/Generator/Directive/BaseDirective.php @@ -7,7 +7,7 @@ /** * @see https://blog.jetbrains.com/phpstorm/2019/02/new-phpstorm-meta-php-features/ - * @method array toArray() + * @method array toArray() */ abstract class BaseDirective { diff --git a/src/Generator/Task/BehaviorTask.php b/src/Generator/Task/BehaviorTask.php index 41693b9f..a3cc184d 100644 --- a/src/Generator/Task/BehaviorTask.php +++ b/src/Generator/Task/BehaviorTask.php @@ -100,7 +100,6 @@ protected function addBehaviors(array $behaviors, string $folder, ?string $plugi if (!$matches) { continue; } - /** @var string $name */ $name = $matches[1]; if ($plugin) { $name = $plugin . '.' . $name; diff --git a/src/Generator/Task/ModelTask.php b/src/Generator/Task/ModelTask.php index 4d4fba38..2d6e1e79 100644 --- a/src/Generator/Task/ModelTask.php +++ b/src/Generator/Task/ModelTask.php @@ -105,7 +105,6 @@ protected function addModels(array $models, $folder, $plugin = null) { if (!$matches) { continue; } - /** @var string $model */ $model = $matches[1]; if ($plugin) { $model = $plugin . '.' . $model; diff --git a/src/Generator/Task/TableFinderTask.php b/src/Generator/Task/TableFinderTask.php index 292148c1..f7a0e2aa 100644 --- a/src/Generator/Task/TableFinderTask.php +++ b/src/Generator/Task/TableFinderTask.php @@ -113,7 +113,7 @@ protected function getCustomFinders(): array { $modelObject = TableRegistry::getTableLocator()->get($model); $behaviors = $modelObject->behaviors(); - /** @var array<\Cake\ORM\Behavior> $iterator */ + /** @var iterable<\Cake\ORM\Behavior> $iterator */ $iterator = $behaviors->getIterator(); foreach ($iterator as $behavior) { $behaviorClass = get_class($behavior); diff --git a/tests/PHPStan/AssociationTableMixinClassReflectionExtension.php b/tests/PHPStan/AssociationTableMixinClassReflectionExtension.php deleted file mode 100644 index e1c8bc64..00000000 --- a/tests/PHPStan/AssociationTableMixinClassReflectionExtension.php +++ /dev/null @@ -1,78 +0,0 @@ -broker = $broker; - } - - /** - * @return \PHPStan\Reflection\ClassReflection - */ - protected function getTableReflection(): ClassReflection { - return $this->broker->getClass(Table::class); - } - - /** - * @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection - * @param string $methodName Method name - * @return bool - */ - public function hasMethod(ClassReflection $classReflection, string $methodName): bool { - if (!$classReflection->isSubclassOf(Association::class)) { - return false; - } - - return $this->getTableReflection()->hasMethod($methodName); - } - - /** - * @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection - * @param string $methodName Method name - * @return \PHPStan\Reflection\MethodReflection - */ - public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection { - return $this->getTableReflection()->getMethod($methodName); - } - - /** - * @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection - * @param string $propertyName Method name - * @return bool - */ - public function hasProperty(ClassReflection $classReflection, string $propertyName): bool { - if (!$classReflection->isSubclassOf(Association::class)) { - return false; - } - - return $this->getTableReflection()->hasProperty($propertyName); - } - - /** - * @param \PHPStan\Reflection\ClassReflection $classReflection Class reflection - * @param string $propertyName Method name - * @return \PHPStan\Reflection\PropertyReflection - */ - public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection { - return $this->getTableReflection()->getProperty($propertyName); - } - -}