From 2c4fe61112bd864aec80b7f5a358ce1674509350 Mon Sep 17 00:00:00 2001 From: SMorteza Ebadi <47121888+smortexa@users.noreply.github.com> Date: Fri, 19 Aug 2022 05:59:29 +0430 Subject: [PATCH] Add rule loader (#13) --- src/RuleLoader.php | 32 ++++++++++++++++++++++++++++++++ src/phparkitect.php | 16 ++-------------- tests/Feature/RuleLoaderTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 src/RuleLoader.php create mode 100644 tests/Feature/RuleLoaderTest.php diff --git a/src/RuleLoader.php b/src/RuleLoader.php new file mode 100644 index 0000000..6fcab2c --- /dev/null +++ b/src/RuleLoader.php @@ -0,0 +1,32 @@ +make('config')['arkitect']; + + return Arr::flatten($package_config['rules']); + } + + public static function all(): array + { + return array_merge(static::package(), static::user()); + } +} diff --git a/src/phparkitect.php b/src/phparkitect.php index 6ae716e..a31084a 100644 --- a/src/phparkitect.php +++ b/src/phparkitect.php @@ -3,22 +3,10 @@ declare(strict_types=1); use Arkitect\CLI\Config; -use Illuminate\Support\Arr; -use Mortexa\LaravelArkitect\CreateApplication; +use Mortexa\LaravelArkitect\RuleLoader; return static function (Config $config): void { - $app = CreateApplication::app(); - - $package_config = $app->make('config')['arkitect']; - - $rules = []; - - $rules = array_merge($rules, Arr::flatten($package_config['rules'])); - - foreach (glob($app->basePath('tests/Architecture/*.php')) as $file) { - $class = basename($file, '.php'); - $rules[] = 'Tests\\Architecture\\'.$class; - } + $rules = RuleLoader::all(); foreach ($rules as $rule) { if ($rule::directoryExists()) { diff --git a/tests/Feature/RuleLoaderTest.php b/tests/Feature/RuleLoaderTest.php new file mode 100644 index 0000000..9227fe7 --- /dev/null +++ b/tests/Feature/RuleLoaderTest.php @@ -0,0 +1,26 @@ +