Skip to content

Commit

Permalink
cs and static analise fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mastir committed Sep 9, 2024
1 parent 6615a0f commit 5c89b51
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
19 changes: 16 additions & 3 deletions src/InterfaceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

namespace CuyZ\Valinor;

/**
* @api
*/
interface InterfaceResolver
{
public function resolve(string $interface, ?array $props) : ?string;
/**
* @param array<string,mixed>|null $props
* @return class-string|null
*/
public function resolve(string $interface, ?array $props): ?string;

public function getResolverProps(string $interface) : array;
/**
* @return string[]
*/
public function getResolverProps(string $interface): array;

public function transform(object $input, callable $next) : array;
/**
* @return array<string|int,mixed>
*/
public function transform(object $input, callable $next): array;
}
1 change: 0 additions & 1 deletion src/Library/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ final class Settings
/** @var array<class-string, null> */
public array $transformerAttributes = [];

/** @var InterfaceResolver|null */
public ?InterfaceResolver $interfaceResolver = null;

public function __construct()
Expand Down
24 changes: 13 additions & 11 deletions src/Mapper/Tree/Builder/InterfaceNodeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
private ObjectImplementations $implementations,
private ClassDefinitionRepository $classDefinitionRepository,
private FunctionsContainer $constructors,
private InterfaceResolver $interfaceResolver,
private ?InterfaceResolver $interfaceResolver,
) {}

public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode
Expand All @@ -55,17 +55,19 @@ public function build(Shell $shell, RootNodeBuilder $rootBuilder): TreeNode

if (! $this->implementations->has($className)) {
if ($type instanceof InterfaceType || $this->classDefinitionRepository->for($type)->isAbstract) {
if ($this->interfaceResolver){
if ($this->interfaceResolver) {
$value = $shell->value();
$resolver_props = [];
foreach($this->interfaceResolver->getResolverProps($className) as $prop){
$resolver_props[$prop] = $value[$prop];
unset($value[$prop]);
}
$resolvedClassName = $this->interfaceResolver->resolve($className, $resolver_props);
if ($resolvedClassName !== null) {
$shell = $shell->withType(new NativeClassType($resolvedClassName))->withValue($value);
return $this->delegate->build($shell, $rootBuilder);
if (is_array($value)) {
$resolver_props = [];
foreach($this->interfaceResolver->getResolverProps($className) as $prop) {
$resolver_props[$prop] = $value[$prop];
unset($value[$prop]);
}
$resolvedClassName = $this->interfaceResolver->resolve($className, $resolver_props);
if ($resolvedClassName !== null) {
$shell = $shell->withType(new NativeClassType($resolvedClassName))->withValue($value);
return $this->delegate->build($shell, $rootBuilder);
}
}
}
throw new CannotResolveObjectType($className);
Expand Down
5 changes: 0 additions & 5 deletions src/MapperBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace CuyZ\Valinor;

use CuyZ\Valinor\InterfaceResolver;
use CuyZ\Valinor\Library\Container;
use CuyZ\Valinor\Library\Settings;
use CuyZ\Valinor\Mapper\ArgumentsMapper;
Expand Down Expand Up @@ -531,10 +530,6 @@ public function registerTransformer(callable|string $transformer, int $priority
return $clone;
}

/**
* @param string $factoryClass
* @return void
*/
public function withInterfaceResolver(InterfaceResolver $resolver): self
{

Expand Down

0 comments on commit 5c89b51

Please sign in to comment.