Skip to content

Commit

Permalink
Rolling code back to old config style for Larastan and L10
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonferens committed Nov 5, 2024
1 parent 1f703b2 commit 818d375
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Commands/GenerateEnumsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
14 changes: 12 additions & 2 deletions src/Generators/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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') ?? '');
Expand Down

0 comments on commit 818d375

Please sign in to comment.