refactor(di): enhance InitializerDependencyAnalyzer with fallback namespace resolution and improved return type handling

- Add fallback logic to resolve classes in the same namespace from file contents.
- Simplify `getInitializerInvokeReturnType` by reducing redundancy in return type validation.
- Extend support for detecting and resolving full class names from method return statements.
- Introduce named parameter pattern matching for return type extraction.
This commit is contained in:
2025-11-03 22:08:49 +01:00
parent d0c36b9245
commit 703d9b04fe
4 changed files with 112 additions and 86 deletions

View File

@@ -150,83 +150,3 @@ final readonly class CompiledComponentMetadata
);
}
}
/**
* Component Property Metadata
*/
final readonly class ComponentPropertyMetadata
{
public function __construct(
public string $name,
public string $type,
public bool $isPublic,
public bool $isReadonly,
public mixed $defaultValue = null,
public bool $hasDefaultValue = false
) {
}
public function toArray(): array
{
return [
'name' => $this->name,
'type' => $this->type,
'is_public' => $this->isPublic,
'is_readonly' => $this->isReadonly,
'default_value' => $this->defaultValue,
'has_default_value' => $this->hasDefaultValue,
];
}
public static function fromArray(array $data): self
{
return new self(
name: $data['name'],
type: $data['type'],
isPublic: $data['is_public'],
isReadonly: $data['is_readonly'],
defaultValue: $data['default_value'] ?? null,
hasDefaultValue: $data['has_default_value'] ?? false
);
}
}
/**
* Component Action Metadata
*/
final readonly class ComponentActionMetadata
{
/**
* @param string $name Action name
* @param array<string, string> $parameters Parameter name => type
* @param string|null $returnType Return type
* @param bool $isPublic Is public method
*/
public function __construct(
public string $name,
public array $parameters,
public ?string $returnType = null,
public bool $isPublic = true
) {
}
public function toArray(): array
{
return [
'name' => $this->name,
'parameters' => $this->parameters,
'return_type' => $this->returnType,
'is_public' => $this->isPublic,
];
}
public static function fromArray(array $data): self
{
return new self(
name: $data['name'],
parameters: $data['parameters'],
returnType: $data['return_type'] ?? null,
isPublic: $data['is_public'] ?? true
);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Framework\LiveComponents\Performance;
/**
* Component Action Metadata
*/
final readonly class ComponentActionMetadata
{
/**
* @param string $name Action name
* @param array<string, string> $parameters Parameter name => type
* @param string|null $returnType Return type
* @param bool $isPublic Is public method
*/
public function __construct(
public string $name,
public array $parameters,
public ?string $returnType = null,
public bool $isPublic = true
) {}
public function toArray(): array
{
return [
'name' => $this->name,
'parameters' => $this->parameters,
'return_type' => $this->returnType,
'is_public' => $this->isPublic,
];
}
public static function fromArray(array $data): self
{
return new self(
name : $data['name'],
parameters: $data['parameters'],
returnType: $data['return_type'] ?? null,
isPublic : $data['is_public'] ?? true
);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Framework\LiveComponents\Performance;
/**
* Component Property Metadata
*/
final readonly class ComponentPropertyMetadata
{
public function __construct(
public string $name,
public string $type,
public bool $isPublic,
public bool $isReadonly,
public mixed $defaultValue = null,
public bool $hasDefaultValue = false
) {}
public function toArray(): array
{
return [
'name' => $this->name,
'type' => $this->type,
'is_public' => $this->isPublic,
'is_readonly' => $this->isReadonly,
'default_value' => $this->defaultValue,
'has_default_value' => $this->hasDefaultValue,
];
}
public static function fromArray(array $data): self
{
return new self(
name : $data['name'],
type : $data['type'],
isPublic : $data['is_public'],
isReadonly : $data['is_readonly'],
defaultValue : $data['default_value'] ?? null,
hasDefaultValue: $data['has_default_value'] ?? false
);
}
}