From ba95d18ef55c91295250ae8b7bfa73d8fb866b9b Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Mon, 10 Aug 2020 10:22:48 +0200 Subject: [PATCH] [PHPCS] Extend to check/fix all source code and turn GHA into auto-commit fixer (#1003) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * phpcs: enable also for config, resources and tests * composer fix-style * vendor/bin/phpunit -d --update-snapshots * gha: instead of checking the style, fix and auto-commit it 💪 --- .github/workflows/run-tests.yml | 18 ++++-- composer.json | 4 +- config/ide-helper.php | 2 +- resources/views/helper.php | 63 +++++++++---------- resources/views/meta.php | 16 ++--- .../ModelsCommand/AbstractModelsCommand.php | 4 +- .../CustomCollection/Models/Simple.php | 4 +- .../ModelsCommand/CustomCollection/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../CustomDate/Models/CustomDate.php | 4 +- .../Console/ModelsCommand/CustomDate/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../GenerateBasicPhpdoc/Models/Post.php | 4 +- .../GenerateBasicPhpdoc/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../GenerateBasicPhpdocCamel/Models/Post.php | 4 +- .../GenerateBasicPhpdocCamel/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../GenerateBasicPhpdocFinal/Models/Post.php | 4 +- .../GenerateBasicPhpdocFinal/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../GeneratePhpdocWithFqn/Models/Post.php | 4 +- .../GeneratePhpdocWithFqn/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../Builders/EMaterialQueryBuilder.php | 4 +- .../Models/Post.php | 4 +- .../Test.php | 4 +- .../ModelsCommand/Getter/Models/Simple.php | 4 +- tests/Console/ModelsCommand/Getter/Test.php | 4 +- .../Getter/__snapshots__/Test__test__1.php | 4 +- .../ModelsCommand/Ignored/Models/Ignored.php | 4 +- .../Ignored/Models/NotIgnored.php | 4 +- tests/Console/ModelsCommand/Ignored/Test.php | 4 +- .../Ignored/__snapshots__/Test__test__1.php | 4 +- .../ModelsCommand/Interfaces/Models/User.php | 4 +- .../Console/ModelsCommand/Interfaces/Test.php | 4 +- .../Casts/CastedProperty.php | 2 +- .../Casts/CustomCasterWithDocblockReturn.php | 2 +- ...ustomCasterWithNullablePrimitiveReturn.php | 2 +- ...ustomCasterWithPrimitiveDocblockReturn.php | 2 +- .../Casts/CustomCasterWithPrimitiveReturn.php | 2 +- .../Casts/CustomCasterWithReturnType.php | 2 +- .../Casts/CustomCasterWithoutReturnType.php | 2 +- .../LaravelCustomCasts/Models/CustomCast.php | 4 +- .../ModelsCommand/LaravelCustomCasts/Test.php | 6 +- ..._parses_casted_properties_correctly__1.php | 4 +- .../ModelsCommand/MagicWhere/Models/Post.php | 4 +- .../Console/ModelsCommand/MagicWhere/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../PHPStormNoInspection/Models/Simple.php | 4 +- .../PHPStormNoInspection/Test.php | 5 +- .../Test__testNoinspectionNotPresent__1.php | 4 +- .../Test__testNoinspectionPresent__1.php | 4 +- .../RelationCountProperties/Models/Post.php | 4 +- .../RelationCountProperties/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../ModelsCommand/Relations/Models/Simple.php | 4 +- .../ModelsOtherNamespace/AnotherModel.php | 4 +- .../Console/ModelsCommand/Relations/Test.php | 4 +- .../Relations/__snapshots__/Test__test__1.php | 4 +- .../ResetAndSmartReset/Models/Simple.php | 4 +- .../ModelsCommand/ResetAndSmartReset/Test.php | 4 +- .../__snapshots__/Test__testNoReset__1.php | 4 +- .../__snapshots__/Test__testReset__1.php | 4 +- .../__snapshots__/Test__testSmartReset__1.php | 4 +- .../SoftDeletes/Models/Simple.php | 4 +- .../ModelsCommand/SoftDeletes/Test.php | 4 +- .../__snapshots__/Test__test__1.php | 4 +- .../migrations/____custom_casts_table.php | 4 +- .../migrations/____custom_dates_table.php | 4 +- .../migrations/____posts_table.php | 4 +- .../migrations/____simple_table.php | 4 +- tests/MethodTest.php | 4 +- tests/TestCase.php | 4 +- 74 files changed, 249 insertions(+), 119 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index dc753dc..5209c60 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -39,8 +39,8 @@ jobs: - name: Execute Unit Tests run: composer test - check-style: - name: Check Code Style + fix-style: + name: Fix Code Style timeout-minutes: 15 runs-on: ubuntu-latest env: @@ -55,10 +55,20 @@ jobs: with: php-version: 7.4 coverage: none - + tools: composer:v2 + - name: Install dependencies run: | composer remove phpro/grumphp vimeo/psalm --no-update --dev composer update --prefer-dist --no-suggest --no-progress - - run: composer check-style + - run: composer fix-style + continue-on-error: true + + # Revert modifications so they don't get commited 💥 + - run: git checkout -- composer.json + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: composer fix-style + commit_author: laravel-ide-helper diff --git a/composer.json b/composer.json index 57ad7dd..9787c2c 100644 --- a/composer.json +++ b/composer.json @@ -64,8 +64,8 @@ }, "scripts": { "analyze": "psalm", - "check-style": "phpcs -p --standard=PSR12 src/", - "fix-style": "phpcbf -p --standard=PSR12 src/", + "check-style": "phpcs -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'", + "fix-style": "phpcbf -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'", "test": "phpunit", "test-regenerate": "phpunit -d --update-snapshots" } diff --git a/config/ide-helper.php b/config/ide-helper.php index bec4fc9..c0b252a 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -99,7 +99,7 @@ return array( 'include_helpers' => false, 'helper_files' => array( - base_path().'/vendor/laravel/framework/src/Illuminate/Support/helpers.php', + base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php', ), /* diff --git a/resources/views/helper.php b/resources/views/helper.php index 40dfecc..d4d2fb8 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -20,66 +20,63 @@ * @see https://github.com/barryvdh/laravel-ide-helper */ - $aliases): ?> - + $aliases) : ?> + namespace { - - - getDocComment(' ')) ?> - getClassType() ?> getExtendsClass() ?> { - getMethods() as $method): ?> - - getDocComment(' ')) ?> + + getDocComment(' ')) ?> + getClassType() ?> getExtendsClass() ?> { + getMethods() as $method) : ?> + getDocComment(' ')) ?> public static function getName() ?>(getParamsWithDefault() ?>) - {getDeclaringClass() !== $method->getRoot()): ?> - + {getDeclaringClass() !== $method->getRoot()) : ?> //Method inherited from getDeclaringClass() ?> - + - isInstanceCall()):?> + isInstanceCall()) :?> /** @var getRoot()?> $instance */ - shouldReturn() ? 'return ': '' ?>getRootMethodCall() ?>; + shouldReturn() ? 'return ' : '' ?>getRootMethodCall() ?>; } } - + } - $aliases): ?> + $aliases) : ?> namespace { - - - getClassType() ?> getShortName() ?> extends getExtends() ?> {getExtendsNamespace() == '\Illuminate\Database\Eloquent'): ?> - getMethods() as $method): ?> - getDocComment(' ')) ?> + + getClassType() ?> getShortName() ?> extends getExtends() ?> {getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?> + getMethods() as $method) : ?> + getDocComment(' ')) ?> public static function getName() ?>(getParamsWithDefault() ?>) - {getDeclaringClass() !== $method->getRoot()): ?> - + {getDeclaringClass() !== $method->getRoot()) : ?> //Method inherited from getDeclaringClass() ?> - + - isInstanceCall()):?> + isInstanceCall()) :?> /** @var getRoot()?> $instance */ - shouldReturn() ? 'return ': '' ?>getRootMethodCall() ?>; + shouldReturn() ? 'return ' : '' ?>getRootMethodCall() ?>; } - -} - + + } + } - + namespace { - + } - + namespace Illuminate\Support { /** * Methods commonly used in migrations @@ -106,7 +103,7 @@ namespace Illuminate\Support { } - + namespace getNamespaceName()?> { /** * @method \Illuminate\Database\Eloquent\Collection|getShortName()?>[]|getShortName()?> create($attributes = []) diff --git a/resources/views/meta.php b/resources/views/meta.php index bcac7d6..51d87da 100644 --- a/resources/views/meta.php +++ b/resources/views/meta.php @@ -10,22 +10,22 @@ namespace PHPSTORM_META { * @author Barry vd. Heuvel * @see https://github.com/barryvdh/laravel-ide-helper */ - + override(, map([ '' => '@', - $class): ?> + $class) : ?> '' => \::class, - + ])); - - override(\factory(0), map([ + + override(\factory(0), map([ '' => '@FactoryBuilder', - + 'getName() ?>' => \getName() ?>FactoryBuilder::class, - - ])); + + ])); override(\Illuminate\Support\Arr::add(0), type(0)); diff --git a/tests/Console/ModelsCommand/AbstractModelsCommand.php b/tests/Console/ModelsCommand/AbstractModelsCommand.php index 4ea52ef..d2fce45 100644 --- a/tests/Console/ModelsCommand/AbstractModelsCommand.php +++ b/tests/Console/ModelsCommand/AbstractModelsCommand.php @@ -1,4 +1,6 @@ -shouldReceive('get') - ->andReturn(file_get_contents(__DIR__.'/Models/CustomCast.php')) + ->andReturn(file_get_contents(__DIR__ . '/Models/CustomCast.php')) ->once(); $mockFilesystem ->shouldReceive('put') diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php index ec49d7b..a431f81 100644 --- a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php @@ -1,4 +1,6 @@ -assertSame($output, $method->getDocComment('')); $this->assertSame('setName', $method->getName()); - $this->assertSame('\\'.ExampleClass::class, $method->getDeclaringClass()); + $this->assertSame('\\' . ExampleClass::class, $method->getDeclaringClass()); $this->assertSame('$last, $first, ...$middle', $method->getParams(true)); $this->assertSame(['$last', '$first', '...$middle'], $method->getParams(false)); $this->assertSame('$last, $first = \'Barry\', ...$middle', $method->getParamsWithDefault(true)); @@ -68,7 +68,7 @@ class ExampleTest extends TestCase */'; $this->assertSame($output, $method->getDocComment('')); $this->assertSame('with', $method->getName()); - $this->assertSame('\\'.Builder::class, $method->getDeclaringClass()); + $this->assertSame('\\' . Builder::class, $method->getDeclaringClass()); $this->assertSame('$relations', $method->getParams(true)); $this->assertSame(['$relations'], $method->getParams(false)); $this->assertSame('$relations', $method->getParamsWithDefault(true)); diff --git a/tests/TestCase.php b/tests/TestCase.php index 0c7f82a..05f2caf 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,4 +1,6 @@ -