@@ -23,15 +23,15 @@ discard block |
||
| 23 | 23 | public function __construct( |
| 24 | 24 | public readonly ReflectionFunctionAbstract $reflection, |
| 25 | 25 | private array $arguments, |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | $this->modeNamed = $this->isNamedMode(); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function addResolvedValue(mixed &$value, string $key = null): void |
| 31 | 31 | { |
| 32 | - if ($key === null) { |
|
| 32 | + if ($key === null){ |
|
| 33 | 33 | $this->resolvedValues[] = &$value; |
| 34 | - } else { |
|
| 34 | + }else{ |
|
| 35 | 35 | $this->resolvedValues[$key] = &$value; |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | ? $parameter->getName() |
| 43 | 43 | : $parameter->getPosition(); |
| 44 | 44 | |
| 45 | - if (!\array_key_exists($key, $this->arguments)) { |
|
| 45 | + if (!\array_key_exists($key, $this->arguments)){ |
|
| 46 | 46 | return []; |
| 47 | 47 | } |
| 48 | 48 | $_val = &$this->arguments[$key]; |
| 49 | 49 | |
| 50 | - if ($variadic && \is_array($_val)) { |
|
| 50 | + if ($variadic && \is_array($_val)){ |
|
| 51 | 51 | // Save keys is possible |
| 52 | 52 | $positional = true; |
| 53 | 53 | $result = []; |
| 54 | - foreach ($_val as $key => &$item) { |
|
| 55 | - if (!$positional && \is_int($key)) { |
|
| 54 | + foreach ($_val as $key => &$item){ |
|
| 55 | + if (!$positional && \is_int($key)){ |
|
| 56 | 56 | throw new ResolvingException( |
| 57 | 57 | 'Cannot use positional argument after named argument during unpacking named variadic argument.' |
| 58 | 58 | ); |
| 59 | 59 | } |
| 60 | 60 | $positional = $positional && \is_int($key); |
| 61 | - if ($positional) { |
|
| 61 | + if ($positional){ |
|
| 62 | 62 | $result[] = &$item; |
| 63 | - } else { |
|
| 63 | + }else{ |
|
| 64 | 64 | $result[$key] = &$item; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | $nums = 0; |
| 80 | 80 | $strings = 0; |
| 81 | - foreach ($this->arguments as $key => $_) { |
|
| 82 | - if (\is_int($key)) { |
|
| 81 | + foreach ($this->arguments as $key => $_){ |
|
| 82 | + if (\is_int($key)){ |
|
| 83 | 83 | ++$nums; |
| 84 | - } else { |
|
| 84 | + }else{ |
|
| 85 | 85 | ++$strings; |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -29,9 +29,12 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function addResolvedValue(mixed &$value, string $key = null): void |
| 31 | 31 | { |
| 32 | - if ($key === null) { |
|
| 32 | + if ($key === null) |
|
| 33 | + { |
|
| 33 | 34 | $this->resolvedValues[] = &$value; |
| 34 | - } else { |
|
| 35 | + } |
|
| 36 | + else |
|
| 37 | + { |
|
| 35 | 38 | $this->resolvedValues[$key] = &$value; |
| 36 | 39 | } |
| 37 | 40 | } |
@@ -42,25 +45,32 @@ discard block |
||
| 42 | 45 | ? $parameter->getName() |
| 43 | 46 | : $parameter->getPosition(); |
| 44 | 47 | |
| 45 | - if (!\array_key_exists($key, $this->arguments)) { |
|
| 48 | + if (!\array_key_exists($key, $this->arguments)) |
|
| 49 | + { |
|
| 46 | 50 | return []; |
| 47 | 51 | } |
| 48 | 52 | $_val = &$this->arguments[$key]; |
| 49 | 53 | |
| 50 | - if ($variadic && \is_array($_val)) { |
|
| 54 | + if ($variadic && \is_array($_val)) |
|
| 55 | + { |
|
| 51 | 56 | // Save keys is possible |
| 52 | 57 | $positional = true; |
| 53 | 58 | $result = []; |
| 54 | - foreach ($_val as $key => &$item) { |
|
| 55 | - if (!$positional && \is_int($key)) { |
|
| 59 | + foreach ($_val as $key => &$item) |
|
| 60 | + { |
|
| 61 | + if (!$positional && \is_int($key)) |
|
| 62 | + { |
|
| 56 | 63 | throw new ResolvingException( |
| 57 | 64 | 'Cannot use positional argument after named argument during unpacking named variadic argument.' |
| 58 | 65 | ); |
| 59 | 66 | } |
| 60 | 67 | $positional = $positional && \is_int($key); |
| 61 | - if ($positional) { |
|
| 68 | + if ($positional) |
|
| 69 | + { |
|
| 62 | 70 | $result[] = &$item; |
| 63 | - } else { |
|
| 71 | + } |
|
| 72 | + else |
|
| 73 | + { |
|
| 64 | 74 | $result[$key] = &$item; |
| 65 | 75 | } |
| 66 | 76 | } |
@@ -78,10 +88,14 @@ discard block |
||
| 78 | 88 | { |
| 79 | 89 | $nums = 0; |
| 80 | 90 | $strings = 0; |
| 81 | - foreach ($this->arguments as $key => $_) { |
|
| 82 | - if (\is_int($key)) { |
|
| 91 | + foreach ($this->arguments as $key => $_) |
|
| 92 | + { |
|
| 93 | + if (\is_int($key)) |
|
| 94 | + { |
|
| 83 | 95 | ++$nums; |
| 84 | - } else { |
|
| 96 | + } |
|
| 97 | + else |
|
| 98 | + { |
|
| 85 | 99 | ++$strings; |
| 86 | 100 | } |
| 87 | 101 | } |
@@ -35,18 +35,18 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function invoke(mixed $target, array $parameters = []): mixed |
| 37 | 37 | { |
| 38 | - if (\is_array($target) && isset($target[1])) { |
|
| 38 | + if (\is_array($target) && isset($target[1])){ |
|
| 39 | 39 | // In a form of resolver and method |
| 40 | 40 | [$resolver, $method] = $target; |
| 41 | 41 | |
| 42 | 42 | // Resolver instance (i.e. [ClassName::class, 'method']) |
| 43 | - if (\is_string($resolver)) { |
|
| 43 | + if (\is_string($resolver)){ |
|
| 44 | 44 | $resolver = $this->container->get($resolver); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - try { |
|
| 47 | + try{ |
|
| 48 | 48 | $method = new \ReflectionMethod($resolver, $method); |
| 49 | - } catch (\ReflectionException $e) { |
|
| 49 | + }catch (\ReflectionException $e){ |
|
| 50 | 50 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | ); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if (\is_string($target) && \is_callable($target)) { |
|
| 60 | + if (\is_string($target) && \is_callable($target)){ |
|
| 61 | 61 | $target = $target(...); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ($target instanceof \Closure) { |
|
| 65 | - try { |
|
| 64 | + if ($target instanceof \Closure){ |
|
| 65 | + try{ |
|
| 66 | 66 | $reflection = new \ReflectionFunction($target); |
| 67 | - } catch (\ReflectionException $e) { |
|
| 67 | + }catch (\ReflectionException $e){ |
|
| 68 | 68 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -35,18 +35,23 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function invoke(mixed $target, array $parameters = []): mixed |
| 37 | 37 | { |
| 38 | - if (\is_array($target) && isset($target[1])) { |
|
| 38 | + if (\is_array($target) && isset($target[1])) |
|
| 39 | + { |
|
| 39 | 40 | // In a form of resolver and method |
| 40 | 41 | [$resolver, $method] = $target; |
| 41 | 42 | |
| 42 | 43 | // Resolver instance (i.e. [ClassName::class, 'method']) |
| 43 | - if (\is_string($resolver)) { |
|
| 44 | + if (\is_string($resolver)) |
|
| 45 | + { |
|
| 44 | 46 | $resolver = $this->container->get($resolver); |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | - try { |
|
| 49 | + try |
|
| 50 | + { |
|
| 48 | 51 | $method = new \ReflectionMethod($resolver, $method); |
| 49 | - } catch (\ReflectionException $e) { |
|
| 52 | + } |
|
| 53 | + catch (\ReflectionException $e) |
|
| 54 | + { |
|
| 50 | 55 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 51 | 56 | } |
| 52 | 57 | |
@@ -57,14 +62,19 @@ discard block |
||
| 57 | 62 | ); |
| 58 | 63 | } |
| 59 | 64 | |
| 60 | - if (\is_string($target) && \is_callable($target)) { |
|
| 65 | + if (\is_string($target) && \is_callable($target)) |
|
| 66 | + { |
|
| 61 | 67 | $target = $target(...); |
| 62 | 68 | } |
| 63 | 69 | |
| 64 | - if ($target instanceof \Closure) { |
|
| 65 | - try { |
|
| 70 | + if ($target instanceof \Closure) |
|
| 71 | + { |
|
| 72 | + try |
|
| 73 | + { |
|
| 66 | 74 | $reflection = new \ReflectionFunction($target); |
| 67 | - } catch (\ReflectionException $e) { |
|
| 75 | + } |
|
| 76 | + catch (\ReflectionException $e) |
|
| 77 | + { |
|
| 68 | 78 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 69 | 79 | } |
| 70 | 80 | |
@@ -50,7 +50,8 @@ |
||
| 50 | 50 | */ |
| 51 | 51 | public function get(string|Autowire $id, string $context = null): mixed |
| 52 | 52 | { |
| 53 | - if ($id instanceof Autowire) { |
|
| 53 | + if ($id instanceof Autowire) |
|
| 54 | + { |
|
| 54 | 55 | return $id->resolve($this->factory); |
| 55 | 56 | } |
| 56 | 57 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | use DestructorTrait; |
| 18 | 18 | |
| 19 | 19 | private State $state; |
| 20 | - private FactoryInterface|Factory $factory; |
|
| 20 | + private FactoryInterface | Factory $factory; |
|
| 21 | 21 | |
| 22 | 22 | public function __construct(Registry $constructor) |
| 23 | 23 | { |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | * @throws ContainerException |
| 47 | 47 | * @throws \Throwable |
| 48 | 48 | */ |
| 49 | - public function get(string|Autowire $id, string $context = null): mixed |
|
| 49 | + public function get(string | Autowire $id, string $context = null): mixed |
|
| 50 | 50 | { |
| 51 | - if ($id instanceof Autowire) { |
|
| 51 | + if ($id instanceof Autowire){ |
|
| 52 | 52 | return $id->resolve($this->factory); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | public function __construct( |
| 27 | 27 | private readonly string $alias, |
| 28 | 28 | private readonly array $parameters = [] |
| 29 | - ) { |
|
| 29 | + ){ |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public static function __set_state(array $anArray): static |
@@ -41,22 +41,22 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public static function wire(mixed $definition): Autowire |
| 43 | 43 | { |
| 44 | - if ($definition instanceof self) { |
|
| 44 | + if ($definition instanceof self){ |
|
| 45 | 45 | return $definition; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if (\is_string($definition)) { |
|
| 48 | + if (\is_string($definition)){ |
|
| 49 | 49 | return new self($definition); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if (\is_array($definition) && isset($definition['class'])) { |
|
| 52 | + if (\is_array($definition) && isset($definition['class'])){ |
|
| 53 | 53 | return new self( |
| 54 | 54 | $definition['class'], |
| 55 | 55 | $definition['options'] ?? $definition['params'] ?? [] |
| 56 | 56 | ); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if (\is_object($definition)) { |
|
| 59 | + if (\is_object($definition)){ |
|
| 60 | 60 | $autowire = new self($definition::class, []); |
| 61 | 61 | $autowire->target = $definition; |
| 62 | 62 | return $autowire; |
@@ -41,22 +41,26 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public static function wire(mixed $definition): Autowire |
| 43 | 43 | { |
| 44 | - if ($definition instanceof self) { |
|
| 44 | + if ($definition instanceof self) |
|
| 45 | + { |
|
| 45 | 46 | return $definition; |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | - if (\is_string($definition)) { |
|
| 49 | + if (\is_string($definition)) |
|
| 50 | + { |
|
| 49 | 51 | return new self($definition); |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | - if (\is_array($definition) && isset($definition['class'])) { |
|
| 54 | + if (\is_array($definition) && isset($definition['class'])) |
|
| 55 | + { |
|
| 53 | 56 | return new self( |
| 54 | 57 | $definition['class'], |
| 55 | 58 | $definition['options'] ?? $definition['params'] ?? [] |
| 56 | 59 | ); |
| 57 | 60 | } |
| 58 | 61 | |
| 59 | - if (\is_object($definition)) { |
|
| 62 | + if (\is_object($definition)) |
|
| 63 | + { |
|
| 60 | 64 | $autowire = new self($definition::class, []); |
| 61 | 65 | $autowire->target = $definition; |
| 62 | 66 | return $autowire; |
@@ -16,10 +16,10 @@ |
||
| 16 | 16 | public function __construct( |
| 17 | 17 | protected \ReflectionParameter $parameter, |
| 18 | 18 | protected \ReflectionFunctionAbstract $context |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | $name = $context->getName(); |
| 21 | - if ($context instanceof \ReflectionMethod) { |
|
| 22 | - $name = $context->class . '::' . $name; |
|
| 21 | + if ($context instanceof \ReflectionMethod){ |
|
| 22 | + $name = $context->class.'::'.$name; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | parent::__construct(\sprintf("Unable to resolve '%s' argument in '%s'", $parameter->name, $name)); |
@@ -18,7 +18,8 @@ |
||
| 18 | 18 | protected \ReflectionFunctionAbstract $context |
| 19 | 19 | ) { |
| 20 | 20 | $name = $context->getName(); |
| 21 | - if ($context instanceof \ReflectionMethod) { |
|
| 21 | + if ($context instanceof \ReflectionMethod) |
|
| 22 | + { |
|
| 22 | 23 | $name = $context->class . '::' . $name; |
| 23 | 24 | } |
| 24 | 25 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function __construct( |
| 14 | 14 | \ReflectionFunctionAbstract $reflection, |
| 15 | 15 | private readonly string $parameter |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | $pattern = "Unknown named parameter `{$parameter}` `%s` %s."; |
| 18 | 18 | parent::__construct($this->renderFunctionAndParameter($reflection, $pattern)); |
| 19 | 19 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function __construct( |
| 14 | 14 | \ReflectionFunctionAbstract $reflection, |
| 15 | 15 | private readonly string $parameter |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | $pattern = "Unable to resolve required argument `{$parameter}` when resolving `%s` %s."; |
| 18 | 18 | parent::__construct($this->renderFunctionAndParameter($reflection, $pattern)); |
| 19 | 19 | } |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | public function __construct( |
| 14 | 14 | \ReflectionFunctionAbstract $reflection, |
| 15 | 15 | private readonly int $position |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | $pattern = 'Cannot use positional argument after named argument `%s` %s.'; |
| 18 | 18 | parent::__construct($this->renderFunctionAndParameter($reflection, $pattern)); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function getParameter(): string |
| 22 | 22 | { |
| 23 | - return '#' . $this->position; |
|
| 23 | + return '#'.$this->position; |
|
| 24 | 24 | } |
| 25 | 25 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | { |
| 13 | 13 | $message = 'An argument resolved with wrong type: '; |
| 14 | 14 | parent::__construct( |
| 15 | - $message . $error->getMessage(), |
|
| 15 | + $message.$error->getMessage(), |
|
| 16 | 16 | $error->getCode(), |
| 17 | 17 | $error |
| 18 | 18 | ); |