From 818d3758e645c88790f7b3af32260b6b2fbb3212 Mon Sep 17 00:00:00 2001 From: Brandon Ferens Date: Tue, 5 Nov 2024 10:28:11 -0800 Subject: [PATCH] Rolling code back to old config style for Larastan and L10 --- src/Commands/GenerateEnumsCommand.php | 7 ++++++- src/Generators/EnumGenerator.php | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Commands/GenerateEnumsCommand.php b/src/Commands/GenerateEnumsCommand.php index 2ca3b21..1e5043e 100644 --- a/src/Commands/GenerateEnumsCommand.php +++ b/src/Commands/GenerateEnumsCommand.php @@ -48,7 +48,12 @@ public function handle(): int */ protected function enums(): Collection { - return DiscoverEnums::within(app_path(config()->string('paragon.enums.paths.php'))) + /** + * @var string $path + */ + $path = config('paragon.enums.paths.php'); + + return DiscoverEnums::within(app_path($path)) ->reject(function (ReflectionEnum $enum) { $paths = Arr::map( Arr::wrap(config('paragon.enums.paths.ignore')), diff --git a/src/Generators/EnumGenerator.php b/src/Generators/EnumGenerator.php index 1ccdb21..54167a9 100644 --- a/src/Generators/EnumGenerator.php +++ b/src/Generators/EnumGenerator.php @@ -27,8 +27,13 @@ class EnumGenerator */ public function __construct(protected ReflectionEnum $enum, protected EnumBuilder $builder) { + /** + * @var string $path + */ + $path = config('paragon.enums.paths.generated'); + static::$files = Storage::createLocalDriver([ - 'root' => resource_path(config()->string('paragon.enums.paths.generated')), + 'root' => resource_path($path), ]); static::$cache = Storage::createLocalDriver([ @@ -56,10 +61,15 @@ protected function contents(): string { $code = $this->prepareEnumCode(); + /** + * @var string $abstractName + */ + $abstractName = config('paragon.enums.abstract-class'); + return str(file_get_contents($this->builder->stubPath()) ?: null) ->replace('{{ Path }}', $this->relativePath()) ->replace('{{ Enum }}', $this->enum->getShortName()) - ->replace('{{ Abstract }}', config()->string('paragon.enums.abstract-class')) + ->replace('{{ Abstract }}', $abstractName) ->replace('{{ TypeDefinition }}', $code->get('type') ?? '') ->replace('{{ Cases }}', $code->get('cases') ?? '') ->replace('{{ Getters }}', $code->get('getters') ?? '');