Skip to content

Commit

Permalink
Add Hashed Type to Map (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcampbPPU committed May 26, 2023
1 parent e4e7283 commit 17e67af
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 93 deletions.
233 changes: 145 additions & 88 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ parameters:
# Determines the level of checking. 5 is a good starter point 8 is max
level: 5

checkGenericClassInNonGenericObjectType: false

ignoreErrors:
- '#Call to an undefined method ReflectionType::getName\(\)#'

Expand Down
8 changes: 7 additions & 1 deletion src/Actions/BuildModelDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
use ReflectionException;
use Symfony\Component\Finder\SplFileInfo;

/**
* @template TKey
* @template TValue{reflectionModel: \ReflectionClass, name: string, columns: \Illuminate\Support\Collection, nonColumns: \Illuminate\Support\Collection, relations: \Illuminate\Support\Collection, interfaces: \Illuminate\Support\Collection, imports: \Illuminate\Support\Collection}
*/
class BuildModelDetails
{
use ClassBaseName;
Expand All @@ -17,7 +21,7 @@ class BuildModelDetails
/**
* Build the model details.
*
* @return array
* @return array<TKey, TValue>|null
*
* @throws ReflectionException
*/
Expand Down Expand Up @@ -84,6 +88,8 @@ public function __invoke(SplFileInfo $modelFile, bool $resolveAbstract = false):
}

/**
* @return array<TKey, TValue>|null
*
* @throws NestedCommandException
*/
private function getModelDetails(SplFileInfo $modelFile, bool $resolveAbstract): ?array
Expand Down
6 changes: 6 additions & 0 deletions src/Actions/GenerateCliOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class GenerateCliOutput

protected string $indent = '';

/**
* @var array<int, ReflectionClass>
*/
protected array $enumReflectors = [];

/**
* @var array<int, array<string, mixed>>
*/
protected array $imports = [];

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Actions/GenerateJsonOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
use FumeApp\ModelTyper\Traits\ClassBaseName;
use FumeApp\ModelTyper\Traits\ModelRefClass;
use Illuminate\Support\Collection;
use ReflectionClass;
use Symfony\Component\Finder\SplFileInfo;

class GenerateJsonOutput
{
/**
* @var array<string, array<string, mixed>>
*/
protected array $output = [];

/**
* @var array<int, ReflectionClass>
*/
protected array $enumReflectors = [];

use ClassBaseName;
Expand Down
2 changes: 2 additions & 0 deletions src/Actions/GetModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class GetModels
/**
* Return collection of models.
*
* @param array<string>|null $includedModels
* @param array<string>|null $excludedModels
* @return Collection<int, SplFileInfo>
*/
public function __invoke(?string $model = null, ?array $includedModels = null, ?array $excludedModels = null): Collection
Expand Down
2 changes: 2 additions & 0 deletions src/Actions/RunModelShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function __construct(Application $app = null)
*
* @see https://github.com/laravel/framework/blob/9.x/src/Illuminate/Foundation/Console/ShowModelCommand.php
*
* @return array<string, mixed>
*
* @throws NestedCommandException
*/
public function __invoke(string $model, bool $resolveAbstract = false): array
Expand Down
3 changes: 2 additions & 1 deletion src/Actions/WriteColumnAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class WriteColumnAttribute
/**
* Get model columns and attributes to the output.
*
* @param array $attribute <{name: string, type: string, increments: bool, nullable: bool, default: mixed, unique: bool, fillable: bool, hidden: bool, appended: mixed, cast: string}>
* @param array{name: string, type: string, increments: bool, nullable: bool, default: mixed, unique: bool, fillable: bool, hidden?: bool, appended: mixed, cast?: string|null, forceType?: bool} $attribute
* @return array{array{name: string, type: string}, ReflectionClass|null}|array{string, ReflectionClass|null}|array{null, null}
*/
public function __invoke(ReflectionClass $reflectionModel, array $attribute, string $indent = '', bool $jsonOutput = false, bool $noHidden = false, bool $timestampsDate = false, bool $optionalNullables = false): array
{
Expand Down
2 changes: 2 additions & 0 deletions src/Actions/WriteEnumConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class WriteEnumConst
{
/**
* Write the enum const to the output.
*
* @return array{type: string, name: string}|string
*/
public function __invoke(ReflectionClass $reflection, string $indent = '', bool $jsonOutput = false): array|string
{
Expand Down
3 changes: 2 additions & 1 deletion src/Actions/WriteRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class WriteRelationship
/**
* Write the relationship to the output.
*
* @param array $relation <{name: string, type: string, related:string}>
* @param array{name: string, type: string, related:string} $relation
* @return array{type: string, name: string}|string
*/
public function __invoke(array $relation, string $indent = '', bool $jsonOutput = false, bool $optionalRelation = false, bool $plurals = false): array|string
{
Expand Down
4 changes: 4 additions & 0 deletions src/Constants/TypescriptMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class TypescriptMappings
{
/**
* @var array<string, string>
*/
public static array $mappings = [
'bigint' => 'number',
'int' => 'number',
Expand All @@ -20,5 +23,6 @@ class TypescriptMappings
'array' => 'string[]',
'point' => 'Point',
'guid' => 'string',
'hashed' => 'string',
];
}
4 changes: 3 additions & 1 deletion src/Overrides/ErrorEmittingConsoleComponentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public function __construct(Factory $factory, bool $throwExceptions = false)

/**
* Reroute calls to underlying instance unless intercepted by override.
*
* @param array<mixed> $arguments
*/
public function __call($name, $arguments)
public function __call(string $name, array $arguments): mixed
{
if ($name === 'error') {
return $this->emitError(...$arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/ModelRefClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait ModelRefClass
/**
* Get the reflection interface.
*
* @param array $info - The model details from the model:show command.
* @param array<string, mixed> $info
*/
public function getRefInterface(array $info): ReflectionClass
{
Expand Down
6 changes: 6 additions & 0 deletions src/TypescriptInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

class TypescriptInterface
{
/**
* @param array<string, mixed> $columns
* @param array<string, mixed> $mutators
* @param array<string, mixed> $relations
* @param array<string, mixed> $interfaces
*/
public function __construct(
public string $name,
public array $columns,
Expand Down

0 comments on commit 17e67af

Please sign in to comment.