Skip to content

Commit

Permalink
add DTO TypeScript types generation command
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Oct 12, 2023
1 parent 229b01a commit e4797f2
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/data-transfer-objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

'normalise_properties' => true,

'types_generation_file_name' => null,

];
14 changes: 14 additions & 0 deletions src/Attributes/AsType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace OpenSoutheners\LaravelDto\Attributes;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
class AsType
{
public function __construct(public string $typeName)

Check warning on line 10 in src/Attributes/AsType.php

View check run for this annotation

Codecov / codecov/patch

src/Attributes/AsType.php#L10

Added line #L10 was not covered by tests
{
//
}

Check warning on line 13 in src/Attributes/AsType.php

View check run for this annotation

Codecov / codecov/patch

src/Attributes/AsType.php#L13

Added line #L13 was not covered by tests
}
128 changes: 128 additions & 0 deletions src/Commands/DtoTypesGenerateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace OpenSoutheners\LaravelDto\Commands;

use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use OpenSoutheners\LaravelDto\DataTransferObject;
use OpenSoutheners\LaravelDto\TypeGenerator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;

#[AsCommand(name: 'dto:typescript')]
class DtoTypesGenerateCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'dto:typescript';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generates TypeScript types from data transfer objects.';

public function __construct(protected Filesystem $filesystem)

Check warning on line 33 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L33

Added line #L33 was not covered by tests
{
parent::__construct();

Check warning on line 35 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L35

Added line #L35 was not covered by tests
}

/**
* Handle command.
*/
public function handle(): int

Check warning on line 41 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L41

Added line #L41 was not covered by tests
{
if (! $this->confirm('Are you sure you want to generate types from your data transfer objects?', $this->option('force'))) {
return 1;

Check warning on line 44 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L43-L44

Added lines #L43 - L44 were not covered by tests
}

$sourceDirectory = app_path($this->option('source'));

Check warning on line 47 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L47

Added line #L47 was not covered by tests

if (! file_exists($sourceDirectory) || ! is_dir($sourceDirectory)) {
$this->error('Path does not exists');

Check warning on line 50 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L49-L50

Added lines #L49 - L50 were not covered by tests

return 2;

Check warning on line 52 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L52

Added line #L52 was not covered by tests
}

$destinationDirectory = $this->option('output');

Check warning on line 55 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L55

Added line #L55 was not covered by tests

if (
(! file_exists($destinationDirectory) || ! $this->filesystem->isWritable($destinationDirectory))
&& ! $this->filesystem->makeDirectory($destinationDirectory, 493, true)

Check warning on line 59 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L58-L59

Added lines #L58 - L59 were not covered by tests
) {
$this->error('Permissions error, cannot create a directory under the destination path');

Check warning on line 61 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L61

Added line #L61 was not covered by tests

return 3;

Check warning on line 63 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L63

Added line #L63 was not covered by tests
}

$dataTransferObjects = Collection::make((new Finder)->files()->in($sourceDirectory))
->map(fn ($file) => $file->getBasename('.php'))
->sort()
->values()
->all();

Check warning on line 70 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L66-L70

Added lines #L66 - L70 were not covered by tests

$namespace = str_replace(DIRECTORY_SEPARATOR, '\\', Str::replaceFirst(app_path(), 'App', $sourceDirectory));

Check warning on line 72 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L72

Added line #L72 was not covered by tests

$garbageCollection = Collection::make([]);

Check warning on line 74 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L74

Added line #L74 was not covered by tests

foreach ($dataTransferObjects as $dataTransferObject) {
$dataTransferObjectClass = implode('\\', [$namespace, $dataTransferObject]);

Check warning on line 77 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L76-L77

Added lines #L76 - L77 were not covered by tests

if (! class_exists($dataTransferObjectClass) || ! is_a($dataTransferObjectClass, DataTransferObject::class, true)) {
continue;

Check warning on line 80 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L79-L80

Added lines #L79 - L80 were not covered by tests
}

(new TypeGenerator($dataTransferObjectClass, $garbageCollection))->generate();

Check warning on line 83 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L83

Added line #L83 was not covered by tests
}

$filename = $this->option('filename');
$configFilename = config('data-transfer-objects.types_generation_file_name');

Check warning on line 87 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L86-L87

Added lines #L86 - L87 were not covered by tests

if ($filename === 'types.ts' && $configFilename) {
$filename = $configFilename;

Check warning on line 90 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L89-L90

Added lines #L89 - L90 were not covered by tests
}

$destinationFile = implode(DIRECTORY_SEPARATOR, [$destinationDirectory, $filename]);

Check warning on line 93 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L93

Added line #L93 was not covered by tests

if (
$this->filesystem->exists($destinationFile)
&& ! $this->confirm('Are you sure you want to overwrite the output file?', $this->option('force'))

Check warning on line 97 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L96-L97

Added lines #L96 - L97 were not covered by tests
) {
return 0;

Check warning on line 99 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L99

Added line #L99 was not covered by tests
}

if (! $this->filesystem->put($destinationFile, $garbageCollection->join("\n\n"))) {
$this->error('Something happened and types file could not be written');

Check warning on line 103 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L102-L103

Added lines #L102 - L103 were not covered by tests

return 4;

Check warning on line 105 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L105

Added line #L105 was not covered by tests
}

$this->info("Types file successfully generated at \"{$destinationFile}\"");

Check warning on line 108 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L108

Added line #L108 was not covered by tests

return 0;

Check warning on line 110 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L110

Added line #L110 was not covered by tests
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()

Check warning on line 118 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L118

Added line #L118 was not covered by tests
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Force running without asking anything'],
['replace', 'r', InputOption::VALUE_NONE, 'Replace existing types'],
['output', 'o', InputOption::VALUE_OPTIONAL, 'Destination folder where to place generated types', resource_path('types')],
['source', 's', InputOption::VALUE_OPTIONAL, 'Source folder where to look at for data transfer objects (must be relative to app folder)', 'DataTransferObjects'],
['filename', null, InputOption::VALUE_OPTIONAL, 'Destination file name with types generated on it', 'types.ts'],
];

Check warning on line 126 in src/Commands/DtoTypesGenerateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Commands/DtoTypesGenerateCommand.php#L120-L126

Added lines #L120 - L126 were not covered by tests
}
}
3 changes: 2 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use OpenSoutheners\LaravelDto\Commands\DtoMakeCommand;
use OpenSoutheners\LaravelDto\Commands\DtoTypesGenerateCommand;
use OpenSoutheners\LaravelDto\Contracts\ValidatedDataTransferObject;

class ServiceProvider extends BaseServiceProvider
Expand All @@ -17,7 +18,7 @@ class ServiceProvider extends BaseServiceProvider
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([DtoMakeCommand::class]);
$this->commands([DtoMakeCommand::class, DtoTypesGenerateCommand::class]);
}

$this->app->beforeResolving(
Expand Down
163 changes: 163 additions & 0 deletions src/TypeGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

namespace OpenSoutheners\LaravelDto;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use OpenSoutheners\LaravelDto\Attributes\AsType;
use OpenSoutheners\LaravelDto\Attributes\NormaliseProperties;
use ReflectionClass;
use Symfony\Component\PropertyInfo\Type;

class TypeGenerator
{
public const PHP_TO_TYPESCRIPT_VARIANT_TYPES = [
'int' => 'number',
'float' => 'number',
'bool' => 'boolean',
'\stdClass' => 'object',
];

public function __construct(protected string $dataTransferObject, protected Collection $garbageCollection)

Check warning on line 23 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L23

Added line #L23 was not covered by tests
{
//
}

Check warning on line 26 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L26

Added line #L26 was not covered by tests

public function generate(): void

Check warning on line 28 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L28

Added line #L28 was not covered by tests
{
$reflection = new ReflectionClass($this->dataTransferObject);

Check warning on line 30 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L30

Added line #L30 was not covered by tests

$normalisesPropertiesKeys = config('data-transfer-objects.normalise_properties', true);

Check warning on line 32 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L32

Added line #L32 was not covered by tests

if (! empty($reflection->getAttributes(NormaliseProperties::class))) {
$normalisesPropertiesKeys = true;

Check warning on line 35 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L34-L35

Added lines #L34 - L35 were not covered by tests
}

/** @var array<\ReflectionProperty> $properties */
$properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
$propertyInfoExtractor = PropertiesMapper::propertyInfoExtractor();

Check warning on line 40 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L39-L40

Added lines #L39 - L40 were not covered by tests

$exportedType = $this->getExportTypeName($reflection);
$exportAsString = "export type {$exportedType} = {\n";

Check warning on line 43 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L42-L43

Added lines #L42 - L43 were not covered by tests

foreach ($properties as $property) {

Check warning on line 45 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L45

Added line #L45 was not covered by tests
/** @var array<\Symfony\Component\PropertyInfo\Type> $propertyTypes */
$propertyTypes = $propertyInfoExtractor->getTypes($this->dataTransferObject, $property->getName());
$propertyType = reset($propertyTypes);

Check warning on line 48 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L47-L48

Added lines #L47 - L48 were not covered by tests

$propertyTypeClass = $propertyType->getClassName();

Check warning on line 50 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L50

Added line #L50 was not covered by tests

if (is_a($propertyTypeClass, Authenticatable::class, true)) {
continue;

Check warning on line 53 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L52-L53

Added lines #L52 - L53 were not covered by tests
}

$nullMark = $propertyType->isNullable() ? '?' : '';

Check warning on line 56 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L56

Added line #L56 was not covered by tests

$propertyTypeAsString = $this->extractTypeFromPropertyType($propertyType);
$propertyKeyAsString = $property->getName();

Check warning on line 59 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L58-L59

Added lines #L58 - L59 were not covered by tests

if ($normalisesPropertiesKeys) {
$propertyKeyAsString = Str::camel($propertyKeyAsString);
$propertyKeyAsString .= is_subclass_of($propertyTypeClass, Model::class) ? '_id' : '';

Check warning on line 63 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L61-L63

Added lines #L61 - L63 were not covered by tests
}

$exportAsString .= "\t{$propertyKeyAsString}{$nullMark}: {$propertyTypeAsString};\n";

Check warning on line 66 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L66

Added line #L66 was not covered by tests
}

$exportAsString .= "};";

Check warning on line 69 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L69

Added line #L69 was not covered by tests

$this->garbageCollection[$exportedType] = $exportAsString;

Check warning on line 71 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L71

Added line #L71 was not covered by tests
}

protected function getExportTypeName(ReflectionClass $reflection): string

Check warning on line 74 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L74

Added line #L74 was not covered by tests
{
/** @var array<\ReflectionAttribute<\OpenSoutheners\LaravelDto\Attributes\AsType>> $classAttributes */
$classAttributes = $reflection->getAttributes(AsType::class);

Check warning on line 77 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L77

Added line #L77 was not covered by tests

$classAttribute = reset($classAttributes);

Check warning on line 79 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L79

Added line #L79 was not covered by tests

if (! $classAttribute) {
return $reflection->getShortName();

Check warning on line 82 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L81-L82

Added lines #L81 - L82 were not covered by tests
}

return $classAttribute->newInstance()->typeName;

Check warning on line 85 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L85

Added line #L85 was not covered by tests
}

protected function extractTypeFromPropertyType(Type $propertyType): string

Check warning on line 88 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L88

Added line #L88 was not covered by tests
{
$propertyBuiltInType = $propertyType->getBuiltinType();
$propertyTypeString = $propertyType->getClassName() ?? $propertyBuiltInType;

Check warning on line 91 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L90-L91

Added lines #L90 - L91 were not covered by tests

return match (true) {
$propertyType->isCollection() => $this->extractCollectionType($propertyTypeString, $propertyType->getCollectionValueTypes()),
is_a($propertyTypeString, Model::class, true) => $this->extractModelType($propertyTypeString),
is_a($propertyTypeString, \BackedEnum::class, true) => $this->extractEnumType($propertyTypeString),
$propertyBuiltInType === 'object' && $propertyBuiltInType !== $propertyTypeString => $this->extractObjectType($propertyTypeString),
default => $this->builtInTypeToTypeScript($propertyType->getBuiltinType()),
};

Check warning on line 99 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L93-L99

Added lines #L93 - L99 were not covered by tests
}

protected function builtInTypeToTypeScript(string $identifier): string

Check warning on line 102 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L102

Added line #L102 was not covered by tests
{
return static::PHP_TO_TYPESCRIPT_VARIANT_TYPES[$identifier] ?? $identifier;

Check warning on line 104 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L104

Added line #L104 was not covered by tests
}

/**
* Summary of extractObjectType
*/
protected function extractObjectType(string $objectClass): string

Check warning on line 110 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L110

Added line #L110 was not covered by tests
{
(new self($objectClass, $this->garbageCollection))->generate();

Check warning on line 112 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L112

Added line #L112 was not covered by tests

return class_basename($objectClass);

Check warning on line 114 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L114

Added line #L114 was not covered by tests
}

/**
* Summary of extractEnumType
*
* @see https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
*/
protected function extractEnumType(string $enumClass): string

Check warning on line 122 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L122

Added line #L122 was not covered by tests
{
$exportedType = class_basename($enumClass);

Check warning on line 124 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L124

Added line #L124 was not covered by tests

if ($this->garbageCollection->has($exportedType)) {
return $exportedType;

Check warning on line 127 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L126-L127

Added lines #L126 - L127 were not covered by tests
}

$exportsAsString = '';
$exportsAsString .= "export const enum {$exportedType} {\n";

Check warning on line 131 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L130-L131

Added lines #L130 - L131 were not covered by tests

foreach ($enumClass::cases() as $case) {
$caseValueAsString = is_int($case->value) ? $case->value : "\"{$case->value}\"";
$exportsAsString .= "\t{$case->name} = {$caseValueAsString},\n";

Check warning on line 135 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L133-L135

Added lines #L133 - L135 were not covered by tests
}

$exportsAsString .= "};";

Check warning on line 138 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L138

Added line #L138 was not covered by tests

$this->garbageCollection[$exportedType] = $exportsAsString;

Check warning on line 140 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L140

Added line #L140 was not covered by tests

return $exportedType;

Check warning on line 142 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L142

Added line #L142 was not covered by tests
}

/**
* Summary of getCollectionType
*
* @param array<\Symfony\Component\PropertyInfo\Type> $collectedTypes
*/
protected function extractCollectionType(string $collection, array $collectedTypes): string

Check warning on line 150 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L150

Added line #L150 was not covered by tests
{
$collectedType = reset($collectedTypes);

Check warning on line 152 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L152

Added line #L152 was not covered by tests

return $this->extractTypeFromPropertyType($collectedType);

Check warning on line 154 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L154

Added line #L154 was not covered by tests
}

protected function extractModelType(string $modelClass): string

Check warning on line 157 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L157

Added line #L157 was not covered by tests
{
// TODO: Check type from Model's property's attribute or getRouteKeyName as fallback
// TODO: To be able to do the above need to generate types from models
return 'string';

Check warning on line 161 in src/TypeGenerator.php

View check run for this annotation

Codecov / codecov/patch

src/TypeGenerator.php#L161

Added line #L161 was not covered by tests
}
}

0 comments on commit e4797f2

Please sign in to comment.