Skip to content

Commit

Permalink
Merge pull request #363 from dereuromark/phpstan2
Browse files Browse the repository at this point in the history
Upgrade to PHPStan2
  • Loading branch information
dereuromark authored Dec 19, 2024
2 parents 8c1c1cf + d5c687b commit 69bfae7
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 100 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Annotator/CommandAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ protected function getPrimaryModelClass(string $content): ?string {
return null;
}

/** @var string $modelName */
$modelName = $matches[1];

return $modelName;
Expand Down
2 changes: 0 additions & 2 deletions src/Annotator/TemplateAnnotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ protected function parseLoopEntities(string $content): array {

$result = [];

/** @var array<string> $entities */
$entities = $matches[2];
foreach ($entities as $key => $entity) {
if (Inflector::pluralize($entity) !== $matches[1][$key]) {
Expand All @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions src/Command/AnnotateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,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);
}

Expand All @@ -121,8 +119,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;
Expand Down Expand Up @@ -155,8 +151,6 @@ protected function getAnnotator(string $class): AbstractAnnotator {
$class = $tasks[$class];
}

assert($this->args !== null, 'Args not set');

$options = $this->args->getOptions();
$options['plugin'] = $this->plugin;

Expand Down
2 changes: 0 additions & 2 deletions src/Command/GeneratePhpStormMetaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Directive/BaseDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* @see https://blog.jetbrains.com/phpstorm/2019/02/new-phpstorm-meta-php-features/
* @method array toArray()
* @method array<mixed> toArray()
*/
abstract class BaseDirective {

Expand Down
1 change: 0 additions & 1 deletion src/Generator/Task/BehaviorTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Generator/Task/ModelTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Task/TableFinderTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
78 changes: 0 additions & 78 deletions tests/PHPStan/AssociationTableMixinClassReflectionExtension.php

This file was deleted.

0 comments on commit 69bfae7

Please sign in to comment.