From f9aea3e3dc9fb1bc8c2a364315b85b2438bc6647 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 18 Feb 2024 22:52:05 +0100 Subject: [PATCH] tv bump 4 (#3) * fix lat test * apply cs * separate --- .github/FUNDING.yml | 3 ++ .github/workflows/code_analysis.yml | 51 ++++++++++++------- ecs.php | 23 +-------- src/CakePHP/PortedInflector.php | 14 ++--- .../ModelMethodExtension.php | 2 +- .../ClassComponentPropertyExtension.php | 4 +- .../ShellClassPropertyExtension.php | 1 - src/ModelBehaviorMethodExtractor.php | 4 +- src/Reflection/ClassReflectionFinder.php | 2 +- .../Fixture/existing_component_component.php | 2 +- .../Fixture/existing_controller_component.php | 2 +- ...oller_component_from_parent_controller.php | 2 +- ...mponent_with_same_method_name_as_model.php | 2 +- .../Fixture/invalid_component_property.php | 2 +- .../ClassModelPropertyExtensionsTest.php | 4 +- .../Fixture/core_model_behavior.php | 2 +- .../Fixture/custom_model_behavior.php | 10 ---- .../Fixture/existing_controller_model.php | 2 +- .../Fixture/existing_model_model.php | 2 +- .../Fixture/invalid_controller_property.php | 2 +- .../Fixture/invalid_model_property.php | 2 +- .../Fixture/existing_shell_model.php | 2 +- .../Fixture/existing_shell_task.php | 2 +- .../Fixture/invalid_shell_property.php | 2 +- .../ShellClassPropertyExtensionTest.php | 4 +- tests/Source/Model/Behavior/BasicBehavior.php | 1 + tests/Source/Model/SameAsModel.php | 1 + 27 files changed, 71 insertions(+), 79 deletions(-) create mode 100644 .github/FUNDING.yml delete mode 100644 tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/custom_model_behavior.php diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..f797866 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms +github: tomasvotruba +custom: https://www.paypal.me/rectorphp diff --git a/.github/workflows/code_analysis.yml b/.github/workflows/code_analysis.yml index 0a28f8b..d34fa7c 100644 --- a/.github/workflows/code_analysis.yml +++ b/.github/workflows/code_analysis.yml @@ -1,29 +1,46 @@ name: Code Analysis on: - push: null pull_request: null + push: + branches: + - main jobs: - build: + code_analysis: + strategy: + fail-fast: false + matrix: + actions: + - + name: 'Composer Validate' + run: composer validate --ansi + + - + name: 'PHPStan' + run: composer phpstan --ansi + + - + name: 'Coding Standard' + run: composer fix-cs --ansi + + - + name: 'Tests' + run: vendor/bin/phpunit + + name: ${{ matrix.actions.name }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 + # see https://github.com/shivammathur/setup-php + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + coverage: none - - name: Validate composer - run: composer validate + # composer install cache - https://github.com/ramsey/composer-install + - uses: "ramsey/composer-install@v2" - - name: Install dependencies - run: composer install - - - name: Run static type analysis - run: vendor/bin/phpstan - - - name: Run test suite - run: vendor/bin/phpunit + - run: ${{ matrix.actions.run }} diff --git a/ecs.php b/ecs.php index 62958f6..081fb12 100644 --- a/ecs.php +++ b/ecs.php @@ -2,27 +2,8 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() - ->withPaths([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - - // add a single rule - ->withRules([ - NoUnusedImportsFixer::class, - ]) - - // add sets - group of rules - // ->withPreparedSets( - // arrays: true, - // namespaces: true, - // spaces: true, - // docblocks: true, - // comments: true, - // ) - - ; + ->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) + ->withPreparedSets(psr12: true); diff --git a/src/CakePHP/PortedInflector.php b/src/CakePHP/PortedInflector.php index 17be922..90d0bdb 100644 --- a/src/CakePHP/PortedInflector.php +++ b/src/CakePHP/PortedInflector.php @@ -229,13 +229,13 @@ public static function pluralize($word) if (!isset(static::$_plural['cacheUninflected']) || !isset(static::$_plural['cacheIrregular'])) { static::$_plural['cacheUninflected'] = '(?:' . implode( - '|', - static::$_plural['merged']['uninflected'] - ) . ')'; + '|', + static::$_plural['merged']['uninflected'] + ) . ')'; static::$_plural['cacheIrregular'] = '(?:' . implode( - '|', - array_keys(static::$_plural['merged']['irregular']) - ) . ')'; + '|', + array_keys(static::$_plural['merged']['irregular']) + ) . ')'; } if (preg_match('/(.*?(?:\\b|_))(' . static::$_plural['cacheIrregular'] . ')$/i', $word, $regs)) { @@ -272,6 +272,6 @@ public static function pluralize($word) private static function underscore($camelCasedWord) { $underscoredWord = preg_replace('/(?<=\\w)([A-Z])/', '_\\1', (string) $camelCasedWord); - return mb_strtolower($underscoredWord); + return mb_strtolower($underscoredWord); } } diff --git a/src/ClassMethodExtension/ModelMethodExtension.php b/src/ClassMethodExtension/ModelMethodExtension.php index 727bf5b..c2d833e 100644 --- a/src/ClassMethodExtension/ModelMethodExtension.php +++ b/src/ClassMethodExtension/ModelMethodExtension.php @@ -70,7 +70,7 @@ static function ( return $methodReflection->getName() === $methodName; } ); - if (! $methodReflections) { + if (!$methodReflections) { throw new Exception('Method not found'); } return reset($methodReflections); diff --git a/src/ClassPropertyExtension/ClassComponentPropertyExtension.php b/src/ClassPropertyExtension/ClassComponentPropertyExtension.php index 216b59e..18f6471 100644 --- a/src/ClassPropertyExtension/ClassComponentPropertyExtension.php +++ b/src/ClassPropertyExtension/ClassComponentPropertyExtension.php @@ -80,7 +80,7 @@ private function getDefinedComponentsAsList(ClassReflection $classReflection): a $definedComponents = []; foreach (array_merge([$classReflection], $classReflection->getParents()) as $class) { - if (! $class->hasProperty('components')) { + if (!$class->hasProperty('components')) { continue; } @@ -89,7 +89,7 @@ private function getDefinedComponentsAsList(ClassReflection $classReflection): a ->getDefaultValueExpression(); if (!$defaultValue instanceof Array_) { - continue; + continue; } foreach ($defaultValue->items as $item) { diff --git a/src/ClassPropertyExtension/ShellClassPropertyExtension.php b/src/ClassPropertyExtension/ShellClassPropertyExtension.php index c371689..d567292 100644 --- a/src/ClassPropertyExtension/ShellClassPropertyExtension.php +++ b/src/ClassPropertyExtension/ShellClassPropertyExtension.php @@ -4,7 +4,6 @@ namespace PHPStanCakePHP2\ClassPropertyExtension; - /** * Adds {@link Model}s as properties to {@link Shell}s. * diff --git a/src/ModelBehaviorMethodExtractor.php b/src/ModelBehaviorMethodExtractor.php index 4e6bbc7..70cc1cb 100644 --- a/src/ModelBehaviorMethodExtractor.php +++ b/src/ModelBehaviorMethodExtractor.php @@ -69,7 +69,7 @@ private function filterBehaviorMethods( ExtendedMethodReflection $methodReflection ): bool { return $methodReflection->isPublic() - && ! $methodReflection->isStatic() + && !$methodReflection->isStatic() && array_filter( $methodReflection->getVariants(), [$this, 'filterBehaviorMethodVariants'] @@ -87,7 +87,7 @@ private function filterBehaviorMethodVariants( /** @var ParameterReflection|null $firstParameter */ $firstParameter = array_shift($parameters); - if (! $firstParameter) { + if (!$firstParameter) { return false; } diff --git a/src/Reflection/ClassReflectionFinder.php b/src/Reflection/ClassReflectionFinder.php index 3c321aa..fa873b2 100644 --- a/src/Reflection/ClassReflectionFinder.php +++ b/src/Reflection/ClassReflectionFinder.php @@ -61,7 +61,7 @@ private function getClassNamesFromPaths( $classPaths = []; foreach ($paths as $path) { $filePaths = glob($path); - if (! is_array($filePaths)) { + if (!is_array($filePaths)) { throw new Exception(sprintf('glob(%s) caused an error', $path)); } $classPaths = array_merge($classPaths, $filePaths); diff --git a/tests/ClassPropertyExtension/ClassComponentPropertyExtension/Fixture/existing_component_component.php b/tests/ClassPropertyExtension/ClassComponentPropertyExtension/Fixture/existing_component_component.php index c5a317d..2c6ff4f 100644 --- a/tests/ClassPropertyExtension/ClassComponentPropertyExtension/Fixture/existing_component_component.php +++ b/tests/ClassPropertyExtension/ClassComponentPropertyExtension/Fixture/existing_component_component.php @@ -1,6 +1,6 @@ assertFileAsserts($assertType, $file, ...$args); } - public static function dataFileAsserts(): \Iterator + public static function dataFileAsserts(): Iterator { yield from self::gatherAssertTypes(__DIR__ . '/Fixture/core_model_behavior.php'); - yield from self::gatherAssertTypes(__DIR__ . '/Fixture/custom_model_behavior.php'); yield from self::gatherAssertTypes(__DIR__ . '/Fixture/invalid_model_property.php'); yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_model_model.php'); diff --git a/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/core_model_behavior.php b/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/core_model_behavior.php index 38e5f44..a17e30b 100644 --- a/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/core_model_behavior.php +++ b/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/core_model_behavior.php @@ -1,6 +1,6 @@ behaviorMethod('a string!'); - -assertType('string', $result); diff --git a/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/existing_controller_model.php b/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/existing_controller_model.php index 58af979..fcb052c 100644 --- a/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/existing_controller_model.php +++ b/tests/ClassPropertyExtension/ClassModelsPropertyExtension/Fixture/existing_controller_model.php @@ -1,6 +1,6 @@