Skip to content

Commit

Permalink
Fixed usage of L11 specific methods"
Browse files Browse the repository at this point in the history
  • Loading branch information
luisdalmolin committed Oct 29, 2024
1 parent d8e021e commit 5b90df2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Commands/GenerateEnumsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/MakeEnumMethodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}

/**
Expand Down
18 changes: 14 additions & 4 deletions src/Generators/AbstractEnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
}

Expand All @@ -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}");
}
Expand All @@ -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();
}
Expand All @@ -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('.');
Expand Down
9 changes: 7 additions & 2 deletions src/Generators/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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') ?? '');
Expand Down

0 comments on commit 5b90df2

Please sign in to comment.