From 2e769032fe07d658ab6129e82b0845f060d59924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Ba=C5=A1i=C4=87?= Date: Wed, 24 Mar 2021 14:22:26 +0100 Subject: [PATCH] Adds php-cs-fixer. Formats code. --- .gitignore | 3 ++- .php_cs.dist | 19 +++++++++++++++++++ README.md | 16 ++++++++++++++++ composer.json | 3 ++- src/Ekko.php | 16 ++++++++-------- src/Frameworks/Laravel/Ekko.php | 4 ++-- src/Frameworks/Laravel/Helpers.php | 6 +++--- src/Frameworks/Laravel/ServiceProvider.php | 20 ++++---------------- src/Frameworks/Laravel/config.php | 2 +- src/Helpers.php | 2 +- src/Url/GenericUrlProvider.php | 2 +- src/Url/LaravelUrlProvider.php | 2 +- tests/EkkoTest.php | 6 +++--- tests/LaravelTest.php | 4 ++-- 14 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 .php_cs.dist diff --git a/.gitignore b/.gitignore index 5a22558..e5cf541 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor composer.lock -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.php_cs.cache \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..a8a9206 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,19 @@ +in(__DIR__) + ->exclude(['.github','vendor']) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR1' => true, + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], + 'no_unused_imports' => true, + ]) + ->setFinder($finder); \ No newline at end of file diff --git a/README.md b/README.md index 153beb8..b2beaeb 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,22 @@ The same as `Ekko::isActive`. This method encloses the input with wildcard `*`. The same as `Ekko::isActiveMatch`, but accepts only the array of strings. **Backward compatibility.** Use `Ekko::isActive` and pass it the same array. +## Development + +```bash +# Install dependencies +composer install + +# Run tests +vendor/bin/phpunit + +# Run Psalm +vendor/bin/psalm + +# Format code (php-cs-fixer) +vendor/bin/php-cs-fixer +``` + ## Credits Many thanks to: diff --git a/composer.json b/composer.json index 728151e..cc00993 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "mockery/mockery": "^1.4", "illuminate/support": "^8.0", "illuminate/routing": "^8.0", - "vimeo/psalm": "^4.6" + "vimeo/psalm": "^4.6", + "friendsofphp/php-cs-fixer": "^2.18" }, "extra": { "laravel": { diff --git a/src/Ekko.php b/src/Ekko.php index ca6bce1..6620c82 100644 --- a/src/Ekko.php +++ b/src/Ekko.php @@ -2,8 +2,8 @@ namespace Laravelista\Ekko; -use Laravelista\Ekko\Url\UrlProviderInterface; use Laravelista\Ekko\Url\GenericUrlProvider; +use Laravelista\Ekko\Url\UrlProviderInterface; /** * This is the main (core) class of Ekko. @@ -13,11 +13,6 @@ */ class Ekko { - public function __construct() - { - $this->url = new GenericUrlProvider; - } - /** * This value gets returned if the * given output equals null. @@ -33,6 +28,11 @@ public function __construct() */ protected UrlProviderInterface $url; + public function __construct() + { + $this->url = new GenericUrlProvider(); + } + /** * This static method uses `require_once` to * include global helper functions. By default @@ -40,7 +40,7 @@ public function __construct() * * @return void */ - static public function enableGlobalHelpers() + public static function enableGlobalHelpers() { require_once(__DIR__.'/Helpers.php'); } @@ -118,7 +118,7 @@ public function getCurrentUrl(): string */ protected function inArray(array $input, string $methodName): bool { - foreach($input as $url) { + foreach ($input as $url) { if ($this->$methodName($url, true)) { return true; } diff --git a/src/Frameworks/Laravel/Ekko.php b/src/Frameworks/Laravel/Ekko.php index d2ebf70..1a1061f 100644 --- a/src/Frameworks/Laravel/Ekko.php +++ b/src/Frameworks/Laravel/Ekko.php @@ -11,7 +11,7 @@ class Ekko extends \Laravelista\Ekko\Ekko */ public function __construct(protected Router $router) { - parent::__construct(); + parent::__construct(); } /** @@ -23,7 +23,7 @@ public function __construct(protected Router $router) * * @return void */ - static public function enableGlobalHelpers() + public static function enableGlobalHelpers() { require_once(__DIR__.'/Helpers.php'); } diff --git a/src/Frameworks/Laravel/Helpers.php b/src/Frameworks/Laravel/Helpers.php index 2a4224d..c57fe78 100644 --- a/src/Frameworks/Laravel/Helpers.php +++ b/src/Frameworks/Laravel/Helpers.php @@ -1,7 +1,7 @@ isActive($input, $output); } -} \ No newline at end of file +} diff --git a/src/Frameworks/Laravel/ServiceProvider.php b/src/Frameworks/Laravel/ServiceProvider.php index b2735cf..ef9d4b8 100644 --- a/src/Frameworks/Laravel/ServiceProvider.php +++ b/src/Frameworks/Laravel/ServiceProvider.php @@ -3,25 +3,12 @@ namespace Laravelista\Ekko\Frameworks\Laravel; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\Facades\Config; use Laravelista\Ekko\Url\LaravelUrlProvider; -// use Illuminate\Contracts\Support\DeferrableProvider; -class ServiceProvider extends \Illuminate\Support\ServiceProvider /* implements DeferrableProvider */ +class ServiceProvider extends \Illuminate\Support\ServiceProvider implements DeferrableProvider { - /** - * Indicates if loading of the provider is deferred. - * - * Laravel 5.8 - * The defer boolean property on the service provider which is/was used to - * indicate if a provider is deferred has been deprecated in Laravel 5.8. - * In order to mark the service provider as deferred it should implement - * the Illuminate\Contracts\Support\DeferrableProvider contract. - * - * @var bool - */ - protected $defer = true; - /** * Register services. * @@ -30,7 +17,8 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider /* implements public function register() { $this->mergeConfigFrom( - __DIR__.'/config.php', 'ekko' + __DIR__.'/config.php', + 'ekko' ); $this->app->singleton(Ekko::class, function (Application $app) { diff --git a/src/Frameworks/Laravel/config.php b/src/Frameworks/Laravel/config.php index e9641ed..0f38817 100644 --- a/src/Frameworks/Laravel/config.php +++ b/src/Frameworks/Laravel/config.php @@ -7,4 +7,4 @@ * is defined when user called. */ 'default_output' => 'active', -]; \ No newline at end of file +]; diff --git a/src/Helpers.php b/src/Helpers.php index 240022b..ab0c02b 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -10,6 +10,6 @@ */ function is_active(array|string $input, $output = null) { - return (new Ekko)->isActive($input, $output); + return (new Ekko())->isActive($input, $output); } } diff --git a/src/Url/GenericUrlProvider.php b/src/Url/GenericUrlProvider.php index e28ca36..2b6f960 100644 --- a/src/Url/GenericUrlProvider.php +++ b/src/Url/GenericUrlProvider.php @@ -19,4 +19,4 @@ public function current(): string // without query parameters // return strtok($_SERVER['REQUEST_URI'], '?'); } -} \ No newline at end of file +} diff --git a/src/Url/LaravelUrlProvider.php b/src/Url/LaravelUrlProvider.php index d301f72..6acb73e 100644 --- a/src/Url/LaravelUrlProvider.php +++ b/src/Url/LaravelUrlProvider.php @@ -25,4 +25,4 @@ public function current(): string { return $this->request->getRequestUri(); } -} \ No newline at end of file +} diff --git a/tests/EkkoTest.php b/tests/EkkoTest.php index 9210dd6..9cdcf71 100644 --- a/tests/EkkoTest.php +++ b/tests/EkkoTest.php @@ -1,8 +1,8 @@ ekko = new Ekko; + $this->ekko = new Ekko(); } public function isActiveDataProvider() @@ -115,4 +115,4 @@ public function urlProvider() { $this->assertInstanceOf(GenericUrlProvider::class, $this->ekko->getUrlProvider()); } -} \ No newline at end of file +} diff --git a/tests/LaravelTest.php b/tests/LaravelTest.php index 69be203..ae72be6 100644 --- a/tests/LaravelTest.php +++ b/tests/LaravelTest.php @@ -1,9 +1,9 @@