Skip to content

Commit

Permalink
fixed larastan
Browse files Browse the repository at this point in the history
  • Loading branch information
Luukdewaaier committed Mar 12, 2024
1 parent 4ac8de1 commit d5b7ce6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
"phpunit/phpunit": "^10.0",
"orchestra/testbench": "^8.0|^9.0",
"friendsofphp/php-cs-fixer": "^3.0",
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.4"
},
"minimum-stability": "dev",
"prefer-stable": true,
"replace": {
},
"extra": {
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Commands/GenerateTypesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ public function handle(): void
$this->modelDir = $this->option('modelDir') ?? config('laravel-model-ts-type.model_dir');
$this->namespace = $this->option('namespace') ?? config('laravel-model-ts-type.namespace');
$this->outputDir = $this->option('outputDir') ?? config('laravel-model-ts-type.output_dir');
$this->useKebabCase = !($this->option('noKebabCase') ?? config('laravel-model-ts-type.no_kebab_case'));
$this->useKebabCase = !($this->option('noKebabCase') ?: config('laravel-model-ts-type.no_kebab_case'));
$this->indentation = $this->formatIndentation();
// @phpstan-ignore-next-line
$this->model = $this->option('model') ?? null;

$this->getModels($this->modelDir);
Expand All @@ -149,6 +148,7 @@ public function handle(): void
}

if ($reflectionClass->isEnum()) {
/** @phpstan-ignore-next-line */
$enumFormatter = new EnumFormatter($fullyQualifiedName);
$tsContent = $enumFormatter->format();

Expand Down
2 changes: 1 addition & 1 deletion src/Facades/FormatNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Facades\Facade;

/**
* @method string get(string $path)
* @method static string get(string $path)
*/
class FormatNamespace extends Facade
{
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function unify_path(string $path): string

if (!function_exists('extractEnumName')) {
/**
* @param class-string $fullyQualifiedName
* @param class-string<UnitEnum> $fullyQualifiedName
* @throws ReflectionException
* @return string
*/
Expand All @@ -29,7 +29,7 @@ function extractEnumName(string $fullyQualifiedName): string

if (!function_exists('extractEnumShortName')) {
/**
* @param class-string $fullyQualifiedName
* @param class-string<UnitEnum> $fullyQualifiedName
* @throws ReflectionException
* @return string
*/
Expand Down
1 change: 1 addition & 0 deletions src/Support/Generators/AttributePropertyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private function getPropertyType(ReflectionMethod $method): string
if($returnType instanceof ReflectionUnionType) {
return collect($returnType->getTypes())
->map(function($returnType) {
/** @phpstan-ignore-next-line */
return $this->formatPhpReturnType($returnType->getName()) ;
})
->join(' | ') . ($returnType->allowsNull() ? ' | null' : '');
Expand Down
8 changes: 6 additions & 2 deletions src/Support/TypescriptFormatters/EnumFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace Scrumble\TypeGenerator\Support\TypescriptFormatters;

use UnitEnum;
use ReflectionEnum;
use ReflectionException;
use ReflectionEnumPureCase;
use ReflectionEnumBackedCase;

class EnumFormatter
{
/**
* @var class-string
* @var class-string<UnitEnum>
*/
private string $fullyQualifiedName;

Expand All @@ -20,7 +23,7 @@ class EnumFormatter
private ReflectionEnum $reflectionEnum;

/**
* @param class-string $fullyQualifiedName
* @param class-string<UnitEnum> $fullyQualifiedName
* @throws ReflectionException
*/
public function __construct(string $fullyQualifiedName)
Expand Down Expand Up @@ -58,6 +61,7 @@ private function getValues(): string
$cases = $this->reflectionEnum->getCases();

$values = array_map(function ($case) {
/** @phpstan-ignore-next-line */
$value = $case->getValue()->value;

if (is_string($value)) {
Expand Down

0 comments on commit d5b7ce6

Please sign in to comment.