diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 98e911a..b9dd379 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -8,14 +8,14 @@ # PHP CS Fixer can be run by using the composer script `composer format` $finder = Finder::create() - ->in(__DIR__) - ->name('*.php') - ->notName('*.blade.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true) - ->exclude('public') - ->exclude('node_modules') - ->exclude('build') - ->append(['.php-cs-fixer.php']); + ->in(__DIR__) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true) + ->exclude('public') + ->exclude('node_modules') + ->exclude('build') + ->append(['.php-cs-fixer.php']); return Config::create($finder); diff --git a/composer.json b/composer.json index 70f0b77..3528b51 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ }, "require-dev": { "10up/wp_mock": "^0.4.2", - "friendsofphp/php-cs-fixer": "^3.64", "larastan/larastan": "^2.9", "orchestra/testbench": "^8.27", "pestphp/pest": "^2.36", diff --git a/composer.lock b/composer.lock index d174754..e2cde94 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0c5dbeef1a8bacc5801ccfb35a31ff46", + "content-hash": "83278427e5ce0eeccfa9dbbaf2a13f18", "packages": [ { "name": "brick/math", @@ -731,16 +731,16 @@ }, { "name": "laravel/framework", - "version": "v10.48.23", + "version": "v10.48.24", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "625269ca4881d2b50eded2045cb930960a181d98" + "reference": "2add73f71b88fc45ee1d4f3421f22366247f6155" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/625269ca4881d2b50eded2045cb930960a181d98", - "reference": "625269ca4881d2b50eded2045cb930960a181d98", + "url": "https://api.github.com/repos/laravel/framework/zipball/2add73f71b88fc45ee1d4f3421f22366247f6155", + "reference": "2add73f71b88fc45ee1d4f3421f22366247f6155", "shasum": "" }, "require": { @@ -934,7 +934,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-11-12T15:39:10+00:00" + "time": "2024-11-20T15:57:07+00:00" }, { "name": "laravel/prompts", @@ -996,16 +996,16 @@ }, { "name": "laravel/serializable-closure", - "version": "v1.3.6", + "version": "v1.3.7", "source": { "type": "git", "url": "https://github.com/laravel/serializable-closure.git", - "reference": "f865a58ea3a0107c336b7045104c75243fa59d96" + "reference": "4f48ade902b94323ca3be7646db16209ec76be3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/f865a58ea3a0107c336b7045104c75243fa59d96", - "reference": "f865a58ea3a0107c336b7045104c75243fa59d96", + "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/4f48ade902b94323ca3be7646db16209ec76be3d", + "reference": "4f48ade902b94323ca3be7646db16209ec76be3d", "shasum": "" }, "require": { @@ -1053,7 +1053,7 @@ "issues": "https://github.com/laravel/serializable-closure/issues", "source": "https://github.com/laravel/serializable-closure" }, - "time": "2024-11-11T17:06:04+00:00" + "time": "2024-11-14T18:34:49+00:00" }, { "name": "league/commonmark", @@ -1791,32 +1791,32 @@ }, { "name": "nunomaduro/termwind", - "version": "v1.16.0", + "version": "v1.17.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/termwind.git", - "reference": "dcf1ec3dfa36137b7ce41d43866644a7ab8fc257" + "reference": "5369ef84d8142c1d87e4ec278711d4ece3cbf301" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/dcf1ec3dfa36137b7ce41d43866644a7ab8fc257", - "reference": "dcf1ec3dfa36137b7ce41d43866644a7ab8fc257", + "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/5369ef84d8142c1d87e4ec278711d4ece3cbf301", + "reference": "5369ef84d8142c1d87e4ec278711d4ece3cbf301", "shasum": "" }, "require": { "ext-mbstring": "*", "php": "^8.1", - "symfony/console": "^6.4.12" + "symfony/console": "^6.4.15" }, "require-dev": { - "illuminate/console": "^10.48.22", - "illuminate/support": "^10.48.22", - "laravel/pint": "^1.18.1", - "pestphp/pest": "^2", + "illuminate/console": "^10.48.24", + "illuminate/support": "^10.48.24", + "laravel/pint": "^1.18.2", + "pestphp/pest": "^2.36.0", "pestphp/pest-plugin-mock": "2.0.0", - "phpstan/phpstan": "^1.12.6", + "phpstan/phpstan": "^1.12.11", "phpstan/phpstan-strict-rules": "^1.6.1", - "symfony/var-dumper": "^6.4.11", + "symfony/var-dumper": "^6.4.15", "thecodingmachine/phpstan-strict-rules": "^1.0.0" }, "type": "library", @@ -1856,7 +1856,7 @@ ], "support": { "issues": "https://github.com/nunomaduro/termwind/issues", - "source": "https://github.com/nunomaduro/termwind/tree/v1.16.0" + "source": "https://github.com/nunomaduro/termwind/tree/v1.17.0" }, "funding": [ { @@ -1872,7 +1872,7 @@ "type": "github" } ], - "time": "2024-10-15T15:27:12+00:00" + "time": "2024-11-21T10:36:35+00:00" }, { "name": "phpoption/phpoption", @@ -4739,16 +4739,16 @@ }, { "name": "voku/portable-ascii", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/voku/portable-ascii.git", - "reference": "b56450eed252f6801410d810c8e1727224ae0743" + "reference": "b1d923f88091c6bf09699efcd7c8a1b1bfd7351d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/voku/portable-ascii/zipball/b56450eed252f6801410d810c8e1727224ae0743", - "reference": "b56450eed252f6801410d810c8e1727224ae0743", + "url": "https://api.github.com/repos/voku/portable-ascii/zipball/b1d923f88091c6bf09699efcd7c8a1b1bfd7351d", + "reference": "b1d923f88091c6bf09699efcd7c8a1b1bfd7351d", "shasum": "" }, "require": { @@ -4773,7 +4773,7 @@ "authors": [ { "name": "Lars Moelleken", - "homepage": "http://www.moelleken.org/" + "homepage": "https://www.moelleken.org/" } ], "description": "Portable ASCII library - performance optimized (ascii) string functions for php.", @@ -4785,7 +4785,7 @@ ], "support": { "issues": "https://github.com/voku/portable-ascii/issues", - "source": "https://github.com/voku/portable-ascii/tree/2.0.1" + "source": "https://github.com/voku/portable-ascii/tree/2.0.3" }, "funding": [ { @@ -4809,7 +4809,7 @@ "type": "tidelift" } ], - "time": "2022-03-08T17:03:00+00:00" + "time": "2024-11-21T01:49:47+00:00" }, { "name": "webmozart/assert", @@ -5488,16 +5488,16 @@ }, { "name": "fakerphp/faker", - "version": "v1.24.0", + "version": "v1.24.1", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "a136842a532bac9ecd8a1c723852b09915d7db50" + "reference": "e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/a136842a532bac9ecd8a1c723852b09915d7db50", - "reference": "a136842a532bac9ecd8a1c723852b09915d7db50", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5", + "reference": "e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5", "shasum": "" }, "require": { @@ -5545,9 +5545,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.24.0" + "source": "https://github.com/FakerPHP/Faker/tree/v1.24.1" }, - "time": "2024-11-07T15:11:20+00:00" + "time": "2024-11-21T13:46:39+00:00" }, { "name": "fidry/cpu-core-counter", diff --git a/config/skeleton-package.php b/config/skeleton-package.php index a65488f..da27760 100644 --- a/config/skeleton-package.php +++ b/config/skeleton-package.php @@ -4,22 +4,22 @@ return [ - /* - |-------------------------------------------------------------------------- - | Example Package - |-------------------------------------------------------------------------- - | - | Configuration files provide a great way to customize your package. - | - | In most cases, you should provide sane defaults and publishing the config - | should be optional. - | - | Here, we'll define a few inspirational quotes for use in our component - | and console command. - | - */ + /* + |-------------------------------------------------------------------------- + | Example Package + |-------------------------------------------------------------------------- + | + | Configuration files provide a great way to customize your package. + | + | In most cases, you should provide sane defaults and publishing the config + | should be optional. + | + | Here, we'll define a few inspirational quotes for use in our component + | and console command. + | + */ - 'quotes' => [ - 'For every Sage there is an Acorn.', - ], + 'quotes' => [ + 'For every Sage there is an Acorn.', + ], ]; diff --git a/configure.php b/configure.php index 4f242bf..451eace 100644 --- a/configure.php +++ b/configure.php @@ -5,94 +5,94 @@ function ask(string $question, string $default = ''): string { - $answer = readline($question.($default ? " ({$default})" : null).': '); + $answer = readline($question.($default ? " ({$default})" : null).': '); - if (! $answer) { - return $default; - } + if (! $answer) { + return $default; + } - return $answer; + return $answer; } function confirm(string $question, bool $default = false): bool { - $answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')'); + $answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')'); - if (! $answer) { - return $default; - } + if (! $answer) { + return $default; + } - return strtolower($answer) === 'y'; + return strtolower($answer) === 'y'; } function writeln(string $line): void { - echo $line.PHP_EOL; + echo $line.PHP_EOL; } function run(string $command): string { - return trim((string) shell_exec($command)); + return trim((string) shell_exec($command)); } function str_after(string $subject, string $search): string { - $pos = strrpos($subject, $search); + $pos = strrpos($subject, $search); - if (false === $pos) { - return $subject; - } + if (false === $pos) { + return $subject; + } - return substr($subject, $pos + strlen($search)); + return substr($subject, $pos + strlen($search)); } function slugify(string $subject): string { - return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-')); + return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-')); } function title_case(string $subject): string { - return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject))); + return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject))); } function replace_in_file(string $file, array $replacements): void { - $contents = file_get_contents($file); - - file_put_contents( - $file, - str_replace( - array_keys($replacements), - array_values($replacements), - $contents - ) - ); + $contents = file_get_contents($file); + + file_put_contents( + $file, + str_replace( + array_keys($replacements), + array_values($replacements), + $contents + ) + ); } function determineSeparator(string $path): string { - return str_replace('/', DIRECTORY_SEPARATOR, $path); + return str_replace('/', DIRECTORY_SEPARATOR, $path); } function replaceForWindows(): array { - return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":package :class Example SkeletonPackage"')); + return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":package :class Example SkeletonPackage"')); } function replaceForAllOtherOSes(): array { - return explode(PHP_EOL, run('grep -E -r -l -i ":class|:package|Example|SkeletonPackage" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__))); + return explode(PHP_EOL, run('grep -E -r -l -i ":class|:package|Example|SkeletonPackage" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__))); } function remove_readme_paragraphs(string $file): void { - $contents = file_get_contents($file); + $contents = file_get_contents($file); - file_put_contents( - $file, - preg_replace('/.*/s', '', $contents) ?: $contents - ); + file_put_contents( + $file, + preg_replace('/.*/s', '', $contents) ?: $contents + ); } $currentDirectory = getcwd(); @@ -118,33 +118,33 @@ function remove_readme_paragraphs(string $file): void writeln('This script will replace the above values in all relevant files in the project directory.'); if (! confirm('Modify files?', true)) { - exit(1); + exit(1); } $files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes()); foreach ($files as $file) { - replace_in_file($file, [ - ':package_name' => $packageName, - 'skeleton-package' => $packageSlug, - 'Example' => $className, - 'SkeletonPackage' => $nameSpace, - 'example' => $classSlug, - ':package_description' => $description, - ]); - - match (true) { - str_contains($file, determineSeparator('src/Example.php')) => rename($file, determineSeparator('./src/'.$className.'.php')), - str_contains($file, determineSeparator('src/SkeletonPackageServiceProvider.php')) => rename($file, determineSeparator('./src/'.$nameSpace.'ServiceProvider.php')), - str_contains($file, determineSeparator('src/Console/ExampleCommand.php')) => rename($file, determineSeparator('./src/Console/'.$className.'Command.php')), - str_contains($file, determineSeparator('src/Facades/Example.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')), - str_contains($file, determineSeparator('resources/views/example.blade.php')) => rename($file, determineSeparator('./resources/views/'.$classSlug.'.blade.php')), - str_contains($file, determineSeparator('tests/ExampleTest.php')) => rename($file, determineSeparator('./tests/'.$className.'Test.php')), - str_contains($file, determineSeparator('tests/Console/ExampleCommandTest.php')) => rename($file, determineSeparator('./tests/Console/'.$className.'CommandTest.php')), - str_contains($file, determineSeparator('tests/Facades/ExampleTest.php')) => rename($file, determineSeparator('./tests/Facades/'.$className.'Test.php')), - str_contains($file, 'README.md') => remove_readme_paragraphs($file), - default => [], - }; + replace_in_file($file, [ + ':package_name' => $packageName, + 'skeleton-package' => $packageSlug, + 'Example' => $className, + 'SkeletonPackage' => $nameSpace, + 'example' => $classSlug, + ':package_description' => $description, + ]); + + match (true) { + str_contains($file, determineSeparator('src/Example.php')) => rename($file, determineSeparator('./src/'.$className.'.php')), + str_contains($file, determineSeparator('src/SkeletonPackageServiceProvider.php')) => rename($file, determineSeparator('./src/'.$nameSpace.'ServiceProvider.php')), + str_contains($file, determineSeparator('src/Console/ExampleCommand.php')) => rename($file, determineSeparator('./src/Console/'.$className.'Command.php')), + str_contains($file, determineSeparator('src/Facades/Example.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')), + str_contains($file, determineSeparator('resources/views/example.blade.php')) => rename($file, determineSeparator('./resources/views/'.$classSlug.'.blade.php')), + str_contains($file, determineSeparator('tests/ExampleTest.php')) => rename($file, determineSeparator('./tests/'.$className.'Test.php')), + str_contains($file, determineSeparator('tests/Console/ExampleCommandTest.php')) => rename($file, determineSeparator('./tests/Console/'.$className.'CommandTest.php')), + str_contains($file, determineSeparator('tests/Facades/ExampleTest.php')) => rename($file, determineSeparator('./tests/Facades/'.$className.'Test.php')), + str_contains($file, 'README.md') => remove_readme_paragraphs($file), + default => [], + }; } rename(determineSeparator('./config/skeleton-package.php'), determineSeparator('./config/'.$packageSlug.'.php')); diff --git a/src/Console/ExampleCommand.php b/src/Console/ExampleCommand.php index d4556d6..54cddd8 100644 --- a/src/Console/ExampleCommand.php +++ b/src/Console/ExampleCommand.php @@ -9,27 +9,27 @@ class ExampleCommand extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'example'; + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'example'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'My custom Acorn command.'; + /** + * The console command description. + * + * @var string + */ + protected $description = 'My custom Acorn command.'; - /** - * Execute the console command. - */ - public function handle(): void - { - $this->info( - Example::getQuote() - ); - } + /** + * Execute the console command. + */ + public function handle(): void + { + $this->info( + Example::getQuote() + ); + } } diff --git a/src/Example.php b/src/Example.php index 9b00c8f..4bec4f3 100644 --- a/src/Example.php +++ b/src/Example.php @@ -10,38 +10,38 @@ class Example { - /** - * Create a new Example instance. - */ - public function __construct(protected Application $app) - { - } - - /** - * Retrieve a random inspirational quote. - */ - public function getQuote(): string - { - $quotes = config('skeleton-package.quotes'); - - Assert::isArray($quotes); - - $quote = Arr::random( - $quotes - ); - - Assert::string($quote); - - return $quote; - } - - /** - * Retrieve a post content. - */ - public function getPostContent(int $postId): string - { - $post = \get_post($postId); - - return $post ? $post->post_content : 'Post not found'; - } + /** + * Create a new Example instance. + */ + public function __construct(protected Application $app) + { + } + + /** + * Retrieve a random inspirational quote. + */ + public function getQuote(): string + { + $quotes = config('skeleton-package.quotes'); + + Assert::isArray($quotes); + + $quote = Arr::random( + $quotes + ); + + Assert::string($quote); + + return $quote; + } + + /** + * Retrieve a post content. + */ + public function getPostContent(int $postId): string + { + $post = \get_post($postId); + + return $post ? $post->post_content : 'Post not found'; + } } diff --git a/src/Facades/Example.php b/src/Facades/Example.php index a518d17..d99897b 100644 --- a/src/Facades/Example.php +++ b/src/Facades/Example.php @@ -12,11 +12,11 @@ */ class Example extends Facade { - /** - * Get the registered name of the component. - */ - protected static function getFacadeAccessor(): string - { - return 'Example'; - } + /** + * Get the registered name of the component. + */ + protected static function getFacadeAccessor(): string + { + return 'Example'; + } } diff --git a/src/SkeletonPackageServiceProvider.php b/src/SkeletonPackageServiceProvider.php index 98f8d04..ceebe45 100644 --- a/src/SkeletonPackageServiceProvider.php +++ b/src/SkeletonPackageServiceProvider.php @@ -10,22 +10,22 @@ class SkeletonPackageServiceProvider extends PackageServiceProvider { - public function configurePackage(Package $package): void - { - $package - ->name('skeleton-package') - ->hasConfigFile() - ->hasViews() - ->hasCommand(ExampleCommand::class); - } + public function configurePackage(Package $package): void + { + $package + ->name('skeleton-package') + ->hasConfigFile() + ->hasViews() + ->hasCommand(ExampleCommand::class); + } - public function packageRegistered(): void - { - $this->app->singleton('Example', fn () => new Example($this->app)); - } + public function packageRegistered(): void + { + $this->app->singleton('Example', fn () => new Example($this->app)); + } - public function packageBooted(): void - { - $this->app->make('Example'); - } + public function packageBooted(): void + { + $this->app->make('Example'); + } } diff --git a/tests/Console/ExampleCommandTest.php b/tests/Console/ExampleCommandTest.php index 141dbdb..a5bd064 100644 --- a/tests/Console/ExampleCommandTest.php +++ b/tests/Console/ExampleCommandTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); it('can retrieve a random inspirational quote', function () { - $this->artisan('example') - ->expectsOutput('For every Sage there is an Acorn.') - ->assertExitCode(0); + $this->artisan('example') + ->expectsOutput('For every Sage there is an Acorn.') + ->assertExitCode(0); }); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index a524031..0e02ea9 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -3,22 +3,22 @@ declare(strict_types=1); it('can retrieve a random inspirational quote', function () { - $quote = app()->make('Example')->getQuote(); + $quote = app()->make('Example')->getQuote(); - expect($quote)->tobe('For every Sage there is an Acorn.'); + expect($quote)->tobe('For every Sage there is an Acorn.'); }); it('can retrieve post content', function () { - $postId = 123; - $post = new stdClass(); - $post->post_content = 'Hello World!'; + $postId = 123; + $post = new stdClass(); + $post->post_content = 'Hello World!'; - WP_Mock::userFunction('get_post') - ->once() - ->with(123) - ->andReturn($post); + WP_Mock::userFunction('get_post') + ->once() + ->with(123) + ->andReturn($post); - $postContent = app()->make('Example')->getPostContent($postId); + $postContent = app()->make('Example')->getPostContent($postId); - expect($postContent)->tobe('Hello World!'); + expect($postContent)->tobe('Hello World!'); }); diff --git a/tests/Facades/ExampleTest.php b/tests/Facades/ExampleTest.php index b490ec1..5f7a602 100644 --- a/tests/Facades/ExampleTest.php +++ b/tests/Facades/ExampleTest.php @@ -5,7 +5,7 @@ use Yard\SkeletonPackage\Facades\Example; it('can retrieve a random inspirational quote', function () { - $quote = Example::getQuote(); + $quote = Example::getQuote(); - expect($quote)->tobe('For every Sage there is an Acorn.'); + expect($quote)->tobe('For every Sage there is an Acorn.'); }); diff --git a/tests/TestCase.php b/tests/TestCase.php index 1f487fe..612ef40 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,31 +8,31 @@ class TestCase extends Orchestra { - protected function setUp(): void - { - parent::setUp(); - - \WP_Mock::setUp(); - } - - protected function tearDown(): void - { - parent::tearDown(); - - \WP_Mock::tearDown(); - } - - /** - * Get package providers. - * - * @param \Illuminate\Foundation\Application $app - * - * @return array> - */ - protected function getPackageProviders($app) - { - return [ - 'Yard\SkeletonPackage\SkeletonPackageServiceProvider', - ]; - } + protected function setUp(): void + { + parent::setUp(); + + \WP_Mock::setUp(); + } + + protected function tearDown(): void + { + parent::tearDown(); + + \WP_Mock::tearDown(); + } + + /** + * Get package providers. + * + * @param \Illuminate\Foundation\Application $app + * + * @return array> + */ + protected function getPackageProviders($app) + { + return [ + 'Yard\SkeletonPackage\SkeletonPackageServiceProvider', + ]; + } }