From 67e22d86c8c63daad9a54bb6993e7977877866fe Mon Sep 17 00:00:00 2001 From: Robert Boes <2871897+RobertBoes@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:12:13 +0100 Subject: [PATCH 1/3] feat: introduce pint --- .gitattributes | 2 +- .../workflows/{php-cs-fixer.yml => pint.yml} | 10 ++--- .gitignore | 3 -- .php_cs.dist.php | 40 ------------------- README.md | 2 +- composer.json | 1 + pint.json | 3 ++ 7 files changed, 11 insertions(+), 50 deletions(-) rename .github/workflows/{php-cs-fixer.yml => pint.yml} (53%) delete mode 100644 .php_cs.dist.php create mode 100644 pint.json diff --git a/.gitattributes b/.gitattributes index 886475c..26bc1a9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,7 +8,7 @@ /phpunit.xml.dist export-ignore /tests export-ignore /.editorconfig export-ignore -/.php_cs.dist export-ignore +/pint.json export-ignore /psalm.xml export-ignore /psalm.xml.dist export-ignore /testbench.yaml export-ignore diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/pint.yml similarity index 53% rename from .github/workflows/php-cs-fixer.yml rename to .github/workflows/pint.yml index f55d1fa..6039de6 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/pint.yml @@ -12,12 +12,12 @@ jobs: with: ref: ${{ github.head_ref }} - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga + - name: Run Laravel Pint + uses: aglipanci/laravel-pint-action@2.4 with: - args: --config=.php_cs.dist.php --allow-risky=yes + verboseMode: true - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: Fix styling + commit_message: "style: PHP Linting (Pint)" diff --git a/.gitignore b/.gitignore index 5e3be30..2ef32f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .idea -.php_cs -.php_cs.cache .phpunit.result.cache .phpunit.cache build @@ -12,5 +10,4 @@ phpstan.neon testbench.yaml vendor node_modules -.php-cs-fixer.cache yarn-error.log diff --git a/.php_cs.dist.php b/.php_cs.dist.php deleted file mode 100644 index 8d8a790..0000000 --- a/.php_cs.dist.php +++ /dev/null @@ -1,40 +0,0 @@ -in([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->name('*.php') - ->notName('*.blade.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true); - -return (new PhpCsFixer\Config()) - ->setRules([ - '@PSR12' => true, - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => ['sort_algorithm' => 'alpha'], - 'no_unused_imports' => true, - 'not_operator_with_successor_space' => true, - 'trailing_comma_in_multiline' => true, - 'phpdoc_scalar' => true, - 'unary_operator_spaces' => true, - 'binary_operator_spaces' => true, - 'blank_line_before_statement' => [ - 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], - ], - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_var_without_name' => true, - 'class_attributes_separation' => [ - 'elements' => [ - 'method' => 'one', - ], - ], - 'method_argument_space' => [ - 'on_multiline' => 'ensure_fully_multiline', - 'keep_multiple_spaces_after_comma' => true, - ], - 'single_trait_insert_per_statement' => true, - ]) - ->setFinder($finder); diff --git a/README.md b/README.md index db4c8c6..a890280 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/robertboes/inertia-breadcrumbs.svg?style=flat-square)](https://packagist.org/packages/robertboes/inertia-breadcrumbs) [![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/robertboes/inertia-breadcrumbs?style=flat-square)](https://packagist.org/packages/robertboes/inertia-breadcrumbs) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/RobertBoes/inertia-breadcrumbs/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/robertboes/inertia-breadcrumbs/actions?query=workflow%3Arun-tests+branch%3Amain) -[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/RobertBoes/inertia-breadcrumbs/php-cs-fixer.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/RobertBoes/inertia-breadcrumbs/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain++) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/RobertBoes/inertia-breadcrumbs/pint.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/RobertBoes/inertia-breadcrumbs/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain++) [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/RobertBoes/inertia-breadcrumbs?label=latest%20version&style=flat-square)](https://github.com/RobertBoes/inertia-breadcrumbs/releases/latest) [![Total Downloads](https://img.shields.io/packagist/dt/robertboes/inertia-breadcrumbs.svg?style=flat-square)](https://packagist.org/packages/robertboes/inertia-breadcrumbs) [![GitHub](https://img.shields.io/github/license/RobertBoes/inertia-breadcrumbs?style=flat-square)](https://github.com/RobertBoes/inertia-breadcrumbs/blob/main/LICENSE.md) diff --git a/composer.json b/composer.json index 57fd288..57977ca 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "composer/composer": "^2.1", "diglactic/laravel-breadcrumbs": "^8.0", "glhd/gretel": "^1.7", + "laravel/pint": "^1.14", "nunomaduro/collision": "^7.0", "nunomaduro/larastan": "^2.0", "orchestra/testbench": "^8.0", diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..93061b6 --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "laravel" +} From a4bdd6d56a03e0eb5e7d50ef095d81c8f4d63bb9 Mon Sep 17 00:00:00 2001 From: RobertBoes Date: Wed, 13 Mar 2024 16:24:12 +0000 Subject: [PATCH 2/3] style: PHP Linting (Pint) --- config/inertia-breadcrumbs.php | 2 +- src/BreadcrumbCollection.php | 4 +--- src/Collectors/DiglacticBreadcrumbsCollector.php | 2 +- src/Exceptions/PackageNotInstalledException.php | 2 +- tests/DiglacticCollectorTest.php | 6 ++++-- tests/GretelCollectorTest.php | 4 +++- tests/Helpers/RequestBuilder.php | 9 +++++---- tests/MiddlewareTest.php | 8 +++++++- tests/SerializationTest.php | 2 +- tests/TabunaCollectorTest.php | 4 +++- 10 files changed, 27 insertions(+), 16 deletions(-) diff --git a/config/inertia-breadcrumbs.php b/config/inertia-breadcrumbs.php index b3b8fbb..e6ec888 100644 --- a/config/inertia-breadcrumbs.php +++ b/config/inertia-breadcrumbs.php @@ -3,8 +3,8 @@ use RobertBoes\InertiaBreadcrumbs\Classifier\AppendAllBreadcrumbs; use RobertBoes\InertiaBreadcrumbs\Classifier\IgnoreSingleBreadcrumbs; use RobertBoes\InertiaBreadcrumbs\Collectors\DiglacticBreadcrumbsCollector; -use RobertBoes\InertiaBreadcrumbs\Collectors\TabunaBreadcrumbsCollector; use RobertBoes\InertiaBreadcrumbs\Collectors\GretelBreadcrumbsCollector; +use RobertBoes\InertiaBreadcrumbs\Collectors\TabunaBreadcrumbsCollector; return [ 'middleware' => [ diff --git a/src/BreadcrumbCollection.php b/src/BreadcrumbCollection.php index 3172550..0e912c6 100644 --- a/src/BreadcrumbCollection.php +++ b/src/BreadcrumbCollection.php @@ -13,9 +13,7 @@ class BreadcrumbCollection implements Arrayable public Collection $items; /** - * - * @param array|Collection $items - * @param null|Closure(mixed): Breadcrumb $initializer + * @param null|Closure(mixed): Breadcrumb $initializer * @return void */ public function __construct(array|Collection $items, ?Closure $initializer = null) diff --git a/src/Collectors/DiglacticBreadcrumbsCollector.php b/src/Collectors/DiglacticBreadcrumbsCollector.php index 063dc9f..c032435 100644 --- a/src/Collectors/DiglacticBreadcrumbsCollector.php +++ b/src/Collectors/DiglacticBreadcrumbsCollector.php @@ -38,7 +38,7 @@ private function getBreadcrumbs(Request $request): Collection try { return Breadcrumbs::generate($route->getName(), ...array_values($route->parameters())); - } catch (InvalidBreadcrumbException | UnnamedRouteException) { + } catch (InvalidBreadcrumbException|UnnamedRouteException) { return collect(); } } diff --git a/src/Exceptions/PackageNotInstalledException.php b/src/Exceptions/PackageNotInstalledException.php index cdf06e1..577f6a9 100644 --- a/src/Exceptions/PackageNotInstalledException.php +++ b/src/Exceptions/PackageNotInstalledException.php @@ -8,6 +8,6 @@ class PackageNotInstalledException extends Exception { public function __construct(string $packageIdentifier) { - parent::__construct(sprintf("%s is not installed", $packageIdentifier)); + parent::__construct(sprintf('%s is not installed', $packageIdentifier)); } } diff --git a/tests/DiglacticCollectorTest.php b/tests/DiglacticCollectorTest.php index 3ca6913..74b9adb 100644 --- a/tests/DiglacticCollectorTest.php +++ b/tests/DiglacticCollectorTest.php @@ -35,7 +35,7 @@ public function usesCustomMiddlewareGroup($app) } /** - * @param \Illuminate\Routing\Router $router + * @param \Illuminate\Routing\Router $router */ public function defineRoutes($router) { @@ -86,7 +86,6 @@ public function it_throws_an_exception_when_package_is_not_installed() /** * @test - * */ public function it_collects_diglactic_breadcrumbs() { @@ -136,6 +135,7 @@ public function it_can_use_a_reserved_keyword() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_resolves_a_single_route_parameter() @@ -182,6 +182,7 @@ public function it_returns_empty_collection_for_404_page() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_ignores_the_query_string_by_default_when_determining_current_route() @@ -208,6 +209,7 @@ public function it_ignores_the_query_string_by_default_when_determining_current_ /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_does_not_ignore_query_parameters_when_configured_to_do_so_when_determining_current_route() diff --git a/tests/GretelCollectorTest.php b/tests/GretelCollectorTest.php index b9d888c..f4ba362 100644 --- a/tests/GretelCollectorTest.php +++ b/tests/GretelCollectorTest.php @@ -32,7 +32,7 @@ protected function getPackageProviders($app) } /** - * @param \Illuminate\Routing\Router $router + * @param \Illuminate\Routing\Router $router */ public function defineRoutes($router) { @@ -111,6 +111,7 @@ public function it_returns_empty_collection_for_404_page() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_ignores_the_query_string_by_default_when_determining_current_route() @@ -134,6 +135,7 @@ public function it_ignores_the_query_string_by_default_when_determining_current_ /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_does_not_ignore_query_parameters_when_configured_to_do_so_when_determining_current_route() diff --git a/tests/Helpers/RequestBuilder.php b/tests/Helpers/RequestBuilder.php index abb7c48..aec76c7 100644 --- a/tests/Helpers/RequestBuilder.php +++ b/tests/Helpers/RequestBuilder.php @@ -14,11 +14,12 @@ class RequestBuilder * @example RequestBuilder::create('post.show', ['postId' => 1], PostShowRequest::class); * @example RequestBuilder::create('post.index'); * - * @param string $routeName Name of the route. - * @param array $parameters Array of route or input parameters. - * @param string $class Request class. - * @throws \Exception If the route name doesn't exist. + * @param string $routeName Name of the route. + * @param array $parameters Array of route or input parameters. + * @param string $class Request class. * @return Request + * + * @throws \Exception If the route name doesn't exist. */ public static function create(string $routeName, array $parameters = [], string $class = Request::class) { diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php index bb52a22..1971ea2 100644 --- a/tests/MiddlewareTest.php +++ b/tests/MiddlewareTest.php @@ -27,7 +27,7 @@ public function hasMiddlewareDisabled($app) } /** - * @param \Illuminate\Routing\Router $router + * @param \Illuminate\Routing\Router $router */ public function defineRoutes($router) { @@ -53,6 +53,7 @@ public function it_adds_middleware_to_web_group() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_adds_middleware_to_custom_group() @@ -69,6 +70,7 @@ public function it_adds_middleware_to_custom_group() /** * @test + * * @define-env hasMiddlewareDisabled */ public function it_only_adds_middleware_when_enabled_in_config() @@ -78,6 +80,7 @@ public function it_only_adds_middleware_when_enabled_in_config() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_adds_breadcrumbs_for_current_route() @@ -104,6 +107,7 @@ public function it_adds_breadcrumbs_for_current_route() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_adds_diglactic_breadcrumbs_with_additional_data() @@ -131,6 +135,7 @@ public function it_adds_diglactic_breadcrumbs_with_additional_data() /** * @test + * * @define-env usesCustomMiddlewareGroup * @define-env usesCustomSharedKey */ @@ -159,6 +164,7 @@ public function it_does_change_key_of_breadcrumb() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_does_not_add_breadcrumbs_when_route_has_no_breadcrumbs() diff --git a/tests/SerializationTest.php b/tests/SerializationTest.php index a5caa20..67416a4 100644 --- a/tests/SerializationTest.php +++ b/tests/SerializationTest.php @@ -13,7 +13,7 @@ class SerializationTest extends TestCase { /** - * @param \Illuminate\Routing\Router $router + * @param \Illuminate\Routing\Router $router */ public function defineRoutes($router): void { diff --git a/tests/TabunaCollectorTest.php b/tests/TabunaCollectorTest.php index 4f45e56..c1afaea 100644 --- a/tests/TabunaCollectorTest.php +++ b/tests/TabunaCollectorTest.php @@ -27,7 +27,7 @@ protected function collector(): string } /** - * @param \Illuminate\Routing\Router $router + * @param \Illuminate\Routing\Router $router */ public function defineRoutes($router) { @@ -138,6 +138,7 @@ public function it_returns_empty_collection_for_404_page() /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_ignores_the_query_string_by_default_when_determining_current_route() @@ -166,6 +167,7 @@ public function it_ignores_the_query_string_by_default_when_determining_current_ /** * @test + * * @define-env usesCustomMiddlewareGroup */ public function it_does_not_ignore_query_parameters_when_configured_to_do_so_when_determining_current_route() From 985940cdd0d3c628b00345df4cc7e852b8212f49 Mon Sep 17 00:00:00 2001 From: Robert Boes <2871897+RobertBoes@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:25:36 +0100 Subject: [PATCH 3/3] fix: update pint workflow job name --- .github/workflows/pint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 6039de6..1acaf1b 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -3,7 +3,7 @@ name: Check & fix styling on: [push] jobs: - php-cs-fixer: + pint: runs-on: ubuntu-latest steps: