diff --git a/.github/workflows/pint-lint.yml b/.github/workflows/pint-lint.yml new file mode 100644 index 00000000..87a91b0e --- /dev/null +++ b/.github/workflows/pint-lint.yml @@ -0,0 +1,20 @@ +name: Lint PHP code style issues + +on: + pull_request: + paths: + - '**.php' + +jobs: + lint-php-code-styling: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Check PHP code style issues + uses: aglipanci/laravel-pint-action@1.0.0 + with: + testMode: true + verboseMode: true diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 02396b6b..00000000 --- a/.styleci.yml +++ /dev/null @@ -1,2 +0,0 @@ -preset: laravel -risky: false diff --git a/composer.json b/composer.json index 9824dd63..c75e089e 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ }, "require-dev": { "doctrine/dbal": "^3.3", + "laravel/pint": "^1.0", "orchestra/testbench": "^7.0 || ^8.0", "phpunit/phpunit": "^9.4" }, diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index 05ee2010..8dc6f8fd 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -75,11 +75,11 @@ public function metaExists() { return Blink::once('eloquent-asset-meta-exists-'.$this->id(), function () { return app('statamic.eloquent.assets.model')::query() - ->where([ - 'container' => $this->containerHandle(), - 'folder' => $this->folder(), - 'basename' => $this->basename(), - ])->count() > 0; + ->where([ + 'container' => $this->containerHandle(), + 'folder' => $this->folder(), + 'basename' => $this->basename(), + ])->count() > 0; }); } diff --git a/src/Assets/AssetContainerRepository.php b/src/Assets/AssetContainerRepository.php index 4cb22648..5b90cb57 100644 --- a/src/Assets/AssetContainerRepository.php +++ b/src/Assets/AssetContainerRepository.php @@ -36,7 +36,7 @@ public function findByHandle(string $handle): ?AssetContainerContract }); } - public function make(string $handle = null): AssetContainerContract + public function make(?string $handle = null): AssetContainerContract { return app(AssetContainerContract::class)->handle($handle); } diff --git a/src/Database/BaseMigration.php b/src/Database/BaseMigration.php index d2f2b6cd..b7473050 100644 --- a/src/Database/BaseMigration.php +++ b/src/Database/BaseMigration.php @@ -22,9 +22,6 @@ public function getConnection() /** * Prefixes table if defined. - * - * @param string $table - * @return string */ protected function prefix(string $table): string { diff --git a/src/Entries/EntryRepository.php b/src/Entries/EntryRepository.php index 2d1c5203..15e8ebeb 100644 --- a/src/Entries/EntryRepository.php +++ b/src/Entries/EntryRepository.php @@ -13,7 +13,7 @@ public static function bindings(): array { return [ EntryContract::class => app('statamic.eloquent.entries.entry'), - QueryBuilder::class => EntryQueryBuilder::class, + QueryBuilder::class => EntryQueryBuilder::class, ]; } @@ -33,7 +33,7 @@ public function find($id): ?EntryContract return $this->substitutionsById[$item->id()] ?? $item; } - public function findByUri(string $uri, string $site = null): ?EntryContract + public function findByUri(string $uri, ?string $site = null): ?EntryContract { $blinkKey = 'eloquent-entry-'.md5(urlencode($uri)).($site ? '-'.$site : ''); $item = Blink::once($blinkKey, function () use ($uri, $site) { diff --git a/src/Globals/GlobalVariablesRepository.php b/src/Globals/GlobalVariablesRepository.php index cdb2ac6c..e85da3fd 100644 --- a/src/Globals/GlobalVariablesRepository.php +++ b/src/Globals/GlobalVariablesRepository.php @@ -13,9 +13,9 @@ public function all(): VariablesCollection { return VariablesCollection::make( VariablesModel::all() - ->each(function ($model) { - return app(Variables::class)::fromModel($model); - }) + ->each(function ($model) { + return app(Variables::class)::fromModel($model); + }) ); } diff --git a/src/Taxonomies/TaxonomyRepository.php b/src/Taxonomies/TaxonomyRepository.php index 6fd373f5..89a41702 100644 --- a/src/Taxonomies/TaxonomyRepository.php +++ b/src/Taxonomies/TaxonomyRepository.php @@ -46,7 +46,7 @@ public function findByHandle($handle): ?TaxonomyContract return $taxonomyModel ? app(TaxonomyContract::class)->fromModel($taxonomyModel) : null; } - public function findByUri(string $uri, string $site = null): ?Taxonomy + public function findByUri(string $uri, ?string $site = null): ?Taxonomy { $collection = Facades\Collection::all() ->first(function ($collection) use ($uri, $site) { diff --git a/src/Taxonomies/TermRepository.php b/src/Taxonomies/TermRepository.php index ccd3557c..5f62decd 100644 --- a/src/Taxonomies/TermRepository.php +++ b/src/Taxonomies/TermRepository.php @@ -40,7 +40,7 @@ public function find($id): ?TermContract return $term; } - public function findByUri(string $uri, string $site = null): ?TermContract + public function findByUri(string $uri, ?string $site = null): ?TermContract { $site = $site ?? $this->stache->sites()->first(); diff --git a/tests/ConsoleKernel.php b/tests/ConsoleKernel.php index 17129e26..ddd12f2d 100644 --- a/tests/ConsoleKernel.php +++ b/tests/ConsoleKernel.php @@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) diff --git a/tests/Data/Entries/EntryQueryBuilderTest.php b/tests/Data/Entries/EntryQueryBuilderTest.php index 609c5e67..dddc326a 100644 --- a/tests/Data/Entries/EntryQueryBuilderTest.php +++ b/tests/Data/Entries/EntryQueryBuilderTest.php @@ -721,7 +721,7 @@ public function entries_can_be_retrieved_on_join_table_conditions() foreach (range(4, 6) as $index) { EntryFactory::id($index)->slug($locations[$index]['slug'])->collection('locations') - ->data(['title' => $locations[$index]['title']])->create(); + ->data(['title' => $locations[$index]['title']])->create(); } $query = Entry::query() diff --git a/tests/Repositories/TaxonomyRepositoryTest.php b/tests/Repositories/TaxonomyRepositoryTest.php index 8e31702b..734e8cd7 100644 --- a/tests/Repositories/TaxonomyRepositoryTest.php +++ b/tests/Repositories/TaxonomyRepositoryTest.php @@ -36,36 +36,36 @@ public function setUp(): void } /** @test */ -// public function it_gets_all_taxonomies() -// { -// $taxonomies = $this->repo->all(); -// -// $this->assertInstanceOf(IlluminateCollection::class, $taxonomies); -// $this->assertCount(2, $taxonomies); -// $this->assertEveryItemIsInstanceOf(Taxonomy::class, $taxonomies); -// -// $ordered = $taxonomies->sortBy->handle()->values(); -// $this->assertEquals(['categories', 'tags'], $ordered->map->handle()->all()); -// $this->assertEquals(['Categories', 'Tags'], $ordered->map->title()->all()); -// } -// -// /** @test */ -// public function it_gets_a_taxonomy_by_handle() -// { -// tap($this->repo->findByHandle('categories'), function ($taxonomy) { -// $this->assertInstanceOf(Taxonomy::class, $taxonomy); -// $this->assertEquals('categories', $taxonomy->handle()); -// $this->assertEquals('Categories', $taxonomy->title()); -// }); -// -// tap($this->repo->findByHandle('tags'), function ($taxonomy) { -// $this->assertInstanceOf(Taxonomy::class, $taxonomy); -// $this->assertEquals('tags', $taxonomy->handle()); -// $this->assertEquals('Tags', $taxonomy->title()); -// }); -// -// $this->assertNull($this->repo->findByHandle('unknown')); -// } + // public function it_gets_all_taxonomies() + // { + // $taxonomies = $this->repo->all(); + // + // $this->assertInstanceOf(IlluminateCollection::class, $taxonomies); + // $this->assertCount(2, $taxonomies); + // $this->assertEveryItemIsInstanceOf(Taxonomy::class, $taxonomies); + // + // $ordered = $taxonomies->sortBy->handle()->values(); + // $this->assertEquals(['categories', 'tags'], $ordered->map->handle()->all()); + // $this->assertEquals(['Categories', 'Tags'], $ordered->map->title()->all()); + // } + // + // /** @test */ + // public function it_gets_a_taxonomy_by_handle() + // { + // tap($this->repo->findByHandle('categories'), function ($taxonomy) { + // $this->assertInstanceOf(Taxonomy::class, $taxonomy); + // $this->assertEquals('categories', $taxonomy->handle()); + // $this->assertEquals('Categories', $taxonomy->title()); + // }); + // + // tap($this->repo->findByHandle('tags'), function ($taxonomy) { + // $this->assertInstanceOf(Taxonomy::class, $taxonomy); + // $this->assertEquals('tags', $taxonomy->handle()); + // $this->assertEquals('Tags', $taxonomy->title()); + // }); + // + // $this->assertNull($this->repo->findByHandle('unknown')); + // } /** @test */ public function it_gets_a_taxonomy_by_uri() @@ -90,15 +90,15 @@ public function it_gets_a_taxonomy_by_uri_with_collection() } /** @test */ -// public function it_saves_a_taxonomy_to_the_stache_and_to_a_file() -// { -// $taxonomy = TaxonomyAPI::make('new'); -// $taxonomy->cascade(['foo' => 'bar']); -// $this->assertNull($this->repo->findByHandle('new')); -// -// $this->repo->save($taxonomy); -// -// $this->assertNotNull($item = $this->repo->findByHandle('new')); -// $this->assertEquals(['foo' => 'bar'], $item->cascade()->all()); -// } + // public function it_saves_a_taxonomy_to_the_stache_and_to_a_file() + // { + // $taxonomy = TaxonomyAPI::make('new'); + // $taxonomy->cascade(['foo' => 'bar']); + // $this->assertNull($this->repo->findByHandle('new')); + // + // $this->repo->save($taxonomy); + // + // $this->assertNotNull($item = $this->repo->findByHandle('new')); + // $this->assertEquals(['foo' => 'bar'], $item->cascade()->all()); + // } } diff --git a/tests/TestCase.php b/tests/TestCase.php index b957f5fa..076107f7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -75,7 +75,7 @@ protected function resolveApplicationConfiguration($app) ]; foreach ($configs as $config) { - $app['config']->set("statamic.$config", require(__DIR__."/../config/{$config}.php")); + $app['config']->set("statamic.$config", require (__DIR__."/../config/{$config}.php")); } } @@ -84,7 +84,7 @@ protected function getEnvironmentSetUp($app) // We changed the default sites setup but the tests assume defaults like the following. $app['config']->set('statamic.sites', [ 'default' => 'en', - 'sites' => [ + 'sites' => [ 'en' => ['name' => 'English', 'locale' => 'en_US', 'url' => 'http://localhost/'], ], ]); @@ -92,7 +92,7 @@ protected function getEnvironmentSetUp($app) $app['config']->set('statamic.stache.watcher', false); $app['config']->set('statamic.users.repository', 'file'); $app['config']->set('statamic.stache.stores.users', [ - 'class' => \Statamic\Stache\Stores\UsersStore::class, + 'class' => \Statamic\Stache\Stores\UsersStore::class, 'directory' => __DIR__.'/__fixtures__/users', ]); @@ -100,7 +100,7 @@ protected function getEnvironmentSetUp($app) $app['config']->set('cache.stores.outpost', [ 'driver' => 'file', - 'path' => storage_path('framework/cache/outpost-data'), + 'path' => storage_path('framework/cache/outpost-data'), ]); } @@ -152,7 +152,7 @@ public static function assertArraySubset($subset, $array, bool $checkForObjectId } // This method is unavailable on earlier versions of Laravel. - public function partialMock($abstract, \Closure $mock = null) + public function partialMock($abstract, ?\Closure $mock = null) { $mock = \Mockery::mock(...array_filter(func_get_args()))->makePartial(); $this->app->instance($abstract, $mock);