Skip to content

Commit

Permalink
Laravel Pint, cleanup, and composer requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonferens committed Sep 25, 2024
1 parent fddfb18 commit 422c4b7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 31 deletions.
16 changes: 15 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@
}
],
"require": {
"php": "^8.1"
"php": "^8.1",
"illuminate/filesystem": ">=10.0",
"illuminate/support": ">=10.0"
},
"require-dev": {
"laravel/framework": ">=10.0",
"laravel/pint": "^1.18"
},
"autoload": {
"psr-4": {
"Kirschbaum\\Paragon\\": "src/"
}
},
"scripts": {
"pint": [
"./vendor/bin/pint"
],
"pint-check": [
"./vendor/bin/pint --test"
]
},
"config": {
"sort-packages": true
},
Expand Down
44 changes: 44 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"preset": "laravel",
"rules": {
"blank_line_before_statement": {
"statements": [
"break",
"case",
"continue",
"declare",
"default",
"do",
"exit",
"for",
"foreach",
"if",
"include",
"include_once",
"require",
"require_once",
"return",
"switch",
"throw",
"try",
"while",
"yield"
]
},
"class_definition": {
"multi_line_extends_each_single_line": true,
"single_item_single_line": true,
"single_line": false
},
"concat_space": {
"spacing": "one"
},
"explicit_string_variable": true,
"method_chaining_indentation": true,
"new_with_braces": true,
"nullable_type_declaration_for_default_null_value": true,
"ordered_traits": true,
"phpdoc_separation": true,
"single_line_empty_body": true
}
}
6 changes: 2 additions & 4 deletions src/Commands/GenerateEnumsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ class GenerateEnumsCommand extends Command
public function handle(): int
{
$generatedEnums = $this->enums()
->map(function ($enum) {
return EnumGenerator::generate($enum);
})
->map(fn ($enum) => app(EnumGenerator::class, ['enum' => $enum])())
->filter();

$this->components->info("{$generatedEnums->count()} enums have been (re)generated.");

AbstractEnumGenerator::generate();
app(AbstractEnumGenerator::class)();

$this->components->info('Abstract enum class has been (re)generated.');

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/MakeEnumMethodCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle(): int
{
parent::handle();

AbstractEnumGenerator::generate();
app(AbstractEnumGenerator::class)();

$this->components
->info("Abstract enum class has been rebuilt to include new [{$this->argument('name')}] method.");
Expand Down Expand Up @@ -79,6 +79,6 @@ protected function buildClass($name): string
*/
protected function getPath($name): string
{
return resource_path(config('paragon.enums.paths.methods')) . DIRECTORY_SEPARATOR . $this->argument('name') . '.ts';
return resource_path(config('paragon.enums.paths.methods')) . "/{$this->argument('name')}.ts";
}
}
5 changes: 0 additions & 5 deletions src/Generators/AbstractEnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public function __invoke(): void
$this->files->put($this->path(), $this->contents());
}

public static function generate()
{
return (new self())();
}

/**
* Inject all prepared data into the stub.
*/
Expand Down
23 changes: 4 additions & 19 deletions src/Generators/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ public function __invoke(): bool
return true;
}

/**
* Initiate enum file generation.
*
* @throws ReflectionException
*/
public static function generate(string $enum): bool
{
return (new self($enum))();
}

/**
* Typescript enum file contents.
*/
Expand Down Expand Up @@ -122,9 +112,7 @@ protected function relativePath(): string
protected function buildTypeDefinition(): string
{
return $this->methods()
->map(function ($method) {
return PHP_EOL . " {$method->getName()}();";
})
->map(fn ($method) => PHP_EOL . " {$method->getName()}();")
->sortDesc()
->when(
$this->reflector->isBacked(),
Expand Down Expand Up @@ -163,9 +151,8 @@ protected function buildCases(Collection $cases): string
->map(function ($case) {
$value = $this->caseValueProperty($case);

$methodValues = $this->methods()->map(function (ReflectionMethod $method) use ($case) {
return $this->caseMethods($method, $case);
});
$methodValues = $this->methods()
->map(fn (ReflectionMethod $method) => $this->caseMethods($method, $case));

return $this->assembleCaseObject($case, $value, $methodValues);
})
Expand Down Expand Up @@ -229,9 +216,7 @@ protected function assembleCaseObject($case, string $value, Collection $methodVa
protected function buildGetters(Collection $cases): string
{
return $cases
->map(function ($case) {
return $this->assembleCaseGetter($case);
})
->map(fn ($case) => $this->assembleCaseGetter($case))
->join(PHP_EOL . PHP_EOL);
}

Expand Down

0 comments on commit 422c4b7

Please sign in to comment.