diff --git a/src/Commands/GenerateEnumsCommand.php b/src/Commands/GenerateEnumsCommand.php index cf2c3ce..3fcbe98 100644 --- a/src/Commands/GenerateEnumsCommand.php +++ b/src/Commands/GenerateEnumsCommand.php @@ -47,7 +47,10 @@ public function handle(): int */ protected function enums(): Collection { - return DiscoverEnums::within(app_path((string) config('paragon.enums.paths.php'))) + /** @var string */ + $phpPath = config('paragon.enums.paths.php'); + + return DiscoverEnums::within(app_path($phpPath)) ->reject(function ($enum) { if (! enum_exists($enum)) { return true; diff --git a/src/Commands/MakeEnumMethodCommand.php b/src/Commands/MakeEnumMethodCommand.php index d8a8819..3673197 100644 --- a/src/Commands/MakeEnumMethodCommand.php +++ b/src/Commands/MakeEnumMethodCommand.php @@ -92,9 +92,11 @@ protected function buildClass($name): string */ protected function getPath($name): string { + /** @var string */ + $methods = config('paragon.enums.paths.methods'); $extension = $this->option('javascript') ? 'js' : 'ts'; - return resource_path(config()->string('paragon.enums.paths.methods')) . "/{$this->name()}.{$extension}"; + return resource_path($methods) . "/{$this->name()}.{$extension}"; } /** diff --git a/src/Generators/AbstractEnumGenerator.php b/src/Generators/AbstractEnumGenerator.php index 6241dc1..9169558 100644 --- a/src/Generators/AbstractEnumGenerator.php +++ b/src/Generators/AbstractEnumGenerator.php @@ -17,8 +17,11 @@ class AbstractEnumGenerator public function __construct(protected EnumBuilder $builder) { + /** @var string */ + $generatedPath = config('paragon.enums.paths.generated'); + $this->files = Storage::createLocalDriver([ - 'root' => resource_path(config()->string('paragon.enums.paths.generated')), + 'root' => resource_path($generatedPath), ]); } @@ -34,9 +37,11 @@ protected function contents(): string { $imports = $this->imports(); $suffix = $imports->count() ? PHP_EOL : ''; + /** @var string */ + $abstractClass = config('paragon.enums.abstract-class'); return str((string) file_get_contents($this->builder->abstractStubPath())) - ->replace('{{ Abstract }}', config()->string('paragon.enums.abstract-class')) + ->replace('{{ Abstract }}', $abstractClass) ->replace('{{ Imports }}', "{$imports->join('')}{$suffix}") ->replace('{{ Methods }}', "{$this->methods($imports->keys())}{$suffix}"); } @@ -48,10 +53,13 @@ protected function contents(): string */ protected function imports(): Collection { + /** @var string */ + $methodsPath = config('paragon.enums.paths.methods'); + try { $files = Finder::create() ->files() - ->in(resource_path(config()->string('paragon.enums.paths.methods'))); + ->in(resource_path($methodsPath)); } catch (DirectoryNotFoundException) { return collect(); } @@ -62,10 +70,12 @@ protected function imports(): Collection return $fileCollection ->mapWithKeys(function (SplFileInfo $file): array { $filesystem = new FileUtility(); + /** @var string */ + $generatedPath = config('paragon.enums.paths.generated'); $relativeFilePath = $filesystem->makePathRelative( $file->getPath(), - resource_path(config()->string('paragon.enums.paths.generated')) + resource_path($generatedPath) ); $name = (string) str($file->getFileName())->before('.'); diff --git a/src/Generators/EnumGenerator.php b/src/Generators/EnumGenerator.php index 8b08527..f47dc82 100644 --- a/src/Generators/EnumGenerator.php +++ b/src/Generators/EnumGenerator.php @@ -29,8 +29,11 @@ class EnumGenerator */ public function __construct(protected string $enum, protected EnumBuilder $builder) { + /** @var string */ + $generatedPath = config('paragon.enums.paths.generated'); + $this->files = Storage::createLocalDriver([ - 'root' => resource_path(config()->string('paragon.enums.paths.generated')), + 'root' => resource_path($generatedPath), ]); $this->cache = Storage::createLocalDriver([ @@ -63,11 +66,13 @@ public function __invoke(): bool protected function contents(): string { $code = $this->prepareEnumCode(); + /** @var string */ + $abstractClass = config('paragon.enums.abstract-class'); return str(file_get_contents($this->builder->stubPath()) ?: null) ->replace('{{ Path }}', $this->relativePath()) ->replace('{{ Enum }}', class_basename($this->enum)) - ->replace('{{ Abstract }}', config()->string('paragon.enums.abstract-class')) + ->replace('{{ Abstract }}', $abstractClass) ->replace('{{ TypeDefinition }}', $code->get('type') ?? '') ->replace('{{ Cases }}', $code->get('cases') ?? '') ->replace('{{ Getters }}', $code->get('getters') ?? '');