From 35364af57a8a1d4a0110a46bad83d00cdaf07a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Heidk=C3=A4mper?= Date: Sun, 28 Apr 2024 18:23:25 +0200 Subject: [PATCH] update testbench, use laravel pint --- .php-cs-fixer.php | 43 ---------------------- composer.json | 10 ++--- pint.json | 8 ++++ src/Breakpoints/Parser/BootstrapParser.php | 4 +- src/Breakpoints/Parser/PicoParser.php | 2 +- src/Breakpoints/Parser/TailwindParser.php | 8 ++-- src/Controllers/ToolbarController.php | 8 ++-- tests/TestCase.php | 19 +--------- 8 files changed, 25 insertions(+), 77 deletions(-) delete mode 100644 .php-cs-fixer.php create mode 100644 pint.json diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 0901286..0000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,43 +0,0 @@ -in([ - __DIR__ . '/config', - __DIR__ . '/routes', - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->name('*.php') - ->notName('*.blade.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true); - -return (new PhpCsFixer\Config) - ->setRules([ - '@PSR2' => 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, - 'logical_operators' => 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, - ], - ]) - ->setFinder($finder); - \ No newline at end of file diff --git a/composer.json b/composer.json index dd6bb6d..055413e 100644 --- a/composer.json +++ b/composer.json @@ -8,9 +8,9 @@ "mck89/peast": "^1.16" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.54", - "orchestra/testbench": "^8.21", - "pestphp/pest": "^2.33" + "orchestra/testbench": "^9.0", + "pestphp/pest": "^2.34", + "laravel/pint": "^1.15" }, "autoload": { "psr-4": { @@ -23,8 +23,8 @@ } }, "scripts": { - "phpcs": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --dry-run --verbose --diff", - "phpcs:fix": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes", + "phpcs": "vendor/bin/pint -v --test", + "phpcs:fix": "vendor/bin/pint", "test": "vendor/bin/pest" }, "extra": { diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..ae7601d --- /dev/null +++ b/pint.json @@ -0,0 +1,8 @@ +{ + "preset": "laravel", + "rules": { + "concat_space": { + "spacing": "one" + } + } +} diff --git a/src/Breakpoints/Parser/BootstrapParser.php b/src/Breakpoints/Parser/BootstrapParser.php index b52def6..23adc1f 100644 --- a/src/Breakpoints/Parser/BootstrapParser.php +++ b/src/Breakpoints/Parser/BootstrapParser.php @@ -13,14 +13,14 @@ class BootstrapParser 'xxl' => 'min-width: 1400px', ]; - protected array|null $screens = null; + protected ?array $screens = null; public function __construct( protected array $files, ) { } - public function parse(): array|null + public function parse(): ?array { if (! $this->guessWetherBootstrapIsUsed()) { return null; diff --git a/src/Breakpoints/Parser/PicoParser.php b/src/Breakpoints/Parser/PicoParser.php index f1eb2bc..0f1d172 100644 --- a/src/Breakpoints/Parser/PicoParser.php +++ b/src/Breakpoints/Parser/PicoParser.php @@ -12,7 +12,7 @@ class PicoParser 'xl' => 'min-width: 1200px', ]; - public function parse(): array|null + public function parse(): ?array { if (! $this->guessWetherPicoIsUsed()) { return null; diff --git a/src/Breakpoints/Parser/TailwindParser.php b/src/Breakpoints/Parser/TailwindParser.php index ce64756..e22efb6 100644 --- a/src/Breakpoints/Parser/TailwindParser.php +++ b/src/Breakpoints/Parser/TailwindParser.php @@ -17,14 +17,14 @@ class TailwindParser '2xl' => 'min-width: 1536px', ]; - protected array|null $screens = null; + protected ?array $screens = null; public function __construct( protected array $files, ) { } - public function parse(): array|null + public function parse(): ?array { if (! $this->guessWetherTailwindIsUsed()) { return null; @@ -97,12 +97,12 @@ private function parseConfigFile($filename): void $this->sortByMinWidth(); } - private function getRawKeyName($key): string|null + private function getRawKeyName($key): ?string { return $key instanceof StringLiteral ? $key?->getValue() : $key?->getRawName(); } - private function getBreakpointMedia($media): string|null + private function getBreakpointMedia($media): ?string { if ($media instanceof StringLiteral) { $value = $media->getValue(); diff --git a/src/Controllers/ToolbarController.php b/src/Controllers/ToolbarController.php index 144a200..3a2bda2 100644 --- a/src/Controllers/ToolbarController.php +++ b/src/Controllers/ToolbarController.php @@ -59,7 +59,7 @@ protected function trimSiteFromPath(string $path, string $site): string return Str::ensureLeft($path, '/'); } - protected function getBreakpoints(): array|null + protected function getBreakpoints(): ?array { if (! config('statamic.toolbar.components.breakpoint', true)) { return null; @@ -68,7 +68,7 @@ protected function getBreakpoints(): array|null return (new Breakpoints())->toArray(); } - protected function getSite(): string|null + protected function getSite(): ?string { if (! config('statamic.toolbar.components.site', true)) { return null; @@ -77,7 +77,7 @@ protected function getSite(): string|null return $this->entry?->site()->handle; } - protected function getTemplate(): string|null + protected function getTemplate(): ?string { if (! config('statamic.toolbar.components.template', true)) { return null; @@ -92,7 +92,7 @@ protected function getTemplate(): string|null return $route->parameters()['view'] ?? null; } - protected function getCpLink(): string|null + protected function getCpLink(): ?string { if (! config('statamic.toolbar.components.cp_link', true) || ! auth()->check()) { return null; diff --git a/tests/TestCase.php b/tests/TestCase.php index 0307b32..bf53ba7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,34 +20,17 @@ protected function getPackageProviders($app): array { return [ \Statamic\Providers\StatamicServiceProvider::class, - \Wilderborn\Partyline\ServiceProvider::class, \Heidkaemper\Toolbar\ServiceProvider::class, ]; } - protected function getPackageAliases($app) - { - return [ - 'Statamic' => Statamic::class, - ]; - } - protected function resolveApplicationConfiguration($app) { parent::resolveApplicationConfiguration($app); - $configs = [ - 'assets', 'cp', 'forms', 'routes', 'static_caching', - 'sites', 'stache', 'system', 'users', - ]; - - foreach ($configs as $config) { - $app['config']->set("statamic.{$config}", require(__DIR__ . "/../vendor/statamic/cms/config/{$config}.php")); - } - $app['config']->set('statamic.users.repository', 'file'); - $app['config']->set("statamic.toolbar", require(__DIR__ . '/../config/toolbar.php')); + $app['config']->set('statamic.toolbar', require (__DIR__ . '/../config/toolbar.php')); } protected function setUpTestEntry(): void