@@ -5,8 +5,8 @@ |
||
| 5 | 5 | /** Is thrown when no dependency exists or can be created for the supplied name. */ |
| 6 | 6 | class UnresolvableDependency extends DiException |
| 7 | 7 | { |
| 8 | - /** @param string $name Name of the dependency. */ |
|
| 9 | - public function __construct(string $name) { |
|
| 10 | - parent::__construct(['name' => $name]); |
|
| 11 | - } |
|
| 8 | + /** @param string $name Name of the dependency. */ |
|
| 9 | + public function __construct(string $name) { |
|
| 10 | + parent::__construct(['name' => $name]); |
|
| 11 | + } |
|
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |
@@ -12,8 +12,9 @@ |
||
| 12 | 12 | * @return mixed|null Resolved value or null. |
| 13 | 13 | */ |
| 14 | 14 | protected function resolveByType(\ReflectionParameter $param) { |
| 15 | - if ($param->hasType() === false || $param->getType()->isBuiltin()) |
|
| 16 | - return null; |
|
| 15 | + if ($param->hasType() === false || $param->getType()->isBuiltin()) { |
|
| 16 | + return null; |
|
| 17 | + } |
|
| 17 | 18 | |
| 18 | 19 | $name = $param->getClass()->getName(); |
| 19 | 20 | return $this->fromClass($name) |
@@ -48,12 +48,14 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function get(string $name) { |
| 50 | 50 | $value = $this->read($name); |
| 51 | - if ($value !== null) |
|
| 52 | - return $value; |
|
| 51 | + if ($value !== null) { |
|
| 52 | + return $value; |
|
| 53 | + } |
|
| 53 | 54 | |
| 54 | 55 | $bean = $this->create($name); |
| 55 | - if ($bean === null) |
|
| 56 | - throw new UnresolvableDependency($name); |
|
| 56 | + if ($bean === null) { |
|
| 57 | + throw new UnresolvableDependency($name); |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | return $this->store($bean); |
| 59 | 61 | } |
@@ -79,16 +81,19 @@ discard block |
||
| 79 | 81 | */ |
| 80 | 82 | public function resolve(\ReflectionParameter $param) { |
| 81 | 83 | $value = $this->resolveStoredByName($param); |
| 82 | - if ($value !== null) |
|
| 83 | - return $value; |
|
| 84 | + if ($value !== null) { |
|
| 85 | + return $value; |
|
| 86 | + } |
|
| 84 | 87 | |
| 85 | 88 | $bean = $this->resolveMethodByName($param) ?? $this->resolveByType($param); |
| 86 | - if ($bean !== null) |
|
| 87 | - return $this->store($bean); |
|
| 89 | + if ($bean !== null) { |
|
| 90 | + return $this->store($bean); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | $value = $this->resolveByDefault($param); |
| 90 | - if ($value !== null) |
|
| 91 | - return $value; |
|
| 94 | + if ($value !== null) { |
|
| 95 | + return $value; |
|
| 96 | + } |
|
| 92 | 97 | |
| 93 | 98 | throw new UnresolvableParameter($param->getName()); |
| 94 | 99 | } |
@@ -22,15 +22,18 @@ |
||
| 22 | 22 | * @throws NotTheRequestedInterface If the created instance is not a $name |
| 23 | 23 | */ |
| 24 | 24 | protected function fromInterfaceAlias(string $name) { |
| 25 | - if (interface_exists($name, true) === false) |
|
| 26 | - return null; |
|
| 25 | + if (interface_exists($name, true) === false) { |
|
| 26 | + return null; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | $bean = $this->fromClass($this->fromConst($this->interfaceToAlias($name))); |
| 29 | - if ($bean === null) |
|
| 30 | - return null; |
|
| 30 | + if ($bean === null) { |
|
| 31 | + return null; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | - if (is_subclass_of($bean->value, $name) === false) |
|
| 33 | - throw new NotTheRequestedInterface(get_class($bean->value), $name); |
|
| 34 | + if (is_subclass_of($bean->value, $name) === false) { |
|
| 35 | + throw new NotTheRequestedInterface(get_class($bean->value), $name); |
|
| 36 | + } |
|
| 34 | 37 | |
| 35 | 38 | $bean->addAlias($name); |
| 36 | 39 | return $bean; |
@@ -22,15 +22,18 @@ |
||
| 22 | 22 | * @throws NotTheRequestedInterface if the created instance is not a $name |
| 23 | 23 | */ |
| 24 | 24 | protected function fromInterfaceMethod(string $name) { |
| 25 | - if (interface_exists($name, true) === false) |
|
| 26 | - return null; |
|
| 25 | + if (interface_exists($name, true) === false) { |
|
| 26 | + return null; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | $bean = $this->fromMethod($this->interfaceToFactory($name)); |
| 29 | - if ($bean === null) |
|
| 30 | - return null; |
|
| 30 | + if ($bean === null) { |
|
| 31 | + return null; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | - if (is_subclass_of($bean->value, $name) === false) |
|
| 33 | - throw new NotTheRequestedInterface(get_class($bean->value), $name); |
|
| 34 | + if (is_subclass_of($bean->value, $name) === false) { |
|
| 35 | + throw new NotTheRequestedInterface(get_class($bean->value), $name); |
|
| 36 | + } |
|
| 34 | 37 | |
| 35 | 38 | $bean->addAlias($name); |
| 36 | 39 | return $bean; |
@@ -13,11 +13,13 @@ |
||
| 13 | 13 | * @return Bean|null New $name instance or null if no such class |
| 14 | 14 | */ |
| 15 | 15 | protected function fromClass(string $name) { |
| 16 | - if (class_exists($name, true) === false) |
|
| 17 | - return null; |
|
| 16 | + if (class_exists($name, true) === false) { |
|
| 17 | + return null; |
|
| 18 | + } |
|
| 18 | 19 | |
| 19 | - if (method_exists($name, '__construct') === false) |
|
| 20 | - return new Bean($name, new $name); |
|
| 20 | + if (method_exists($name, '__construct') === false) { |
|
| 21 | + return new Bean($name, new $name); |
|
| 22 | + } |
|
| 21 | 23 | |
| 22 | 24 | $method = new \ReflectionMethod($name, '__construct'); |
| 23 | 25 | return new Bean($name, new $name(...$this->autowire($method))); |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | * @return Bean|null Wrapped factory method result or null if no such factory |
| 15 | 15 | */ |
| 16 | 16 | protected function fromMethod(string $name) { |
| 17 | - if (method_exists($this->config, $name) === false) |
|
| 18 | - return null; |
|
| 17 | + if (method_exists($this->config, $name) === false) { |
|
| 18 | + return null; |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | 21 | $method = $this->configReflClass->getMethod($name); |
| 21 | 22 | $value = $this->config->$name(...$this->autowire($method)); |
@@ -14,18 +14,20 @@ |
||
| 14 | 14 | * @throws ClassNotInjectable If $name is not an Injectable |
| 15 | 15 | */ |
| 16 | 16 | protected function fromClass(string $name) { |
| 17 | - if (class_exists($name, true) === false) |
|
| 18 | - return null; |
|
| 17 | + if (class_exists($name, true) === false) { |
|
| 18 | + return null; |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | - if (method_exists($name, '__construct') === false) |
|
| 21 | - $value = new $name; |
|
| 22 | - else { |
|
| 21 | + if (method_exists($name, '__construct') === false) { |
|
| 22 | + $value = new $name; |
|
| 23 | + } else { |
|
| 23 | 24 | $method = new \ReflectionMethod($name, '__construct'); |
| 24 | 25 | $value = new $name(...$this->autowire($method)); |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | - if ($value instanceof Injectable) |
|
| 28 | - return new Bean($name, $value); |
|
| 28 | + if ($value instanceof Injectable) { |
|
| 29 | + return new Bean($name, $value); |
|
| 30 | + } |
|
| 29 | 31 | |
| 30 | 32 | throw new ClassNotInjectable($name); |
| 31 | 33 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | |
| 33 | 33 | /** @return string default exception message */ |
| 34 | 34 | public function buildMessage(array $vars) { |
| 35 | - $message = $this->getId() . ':'; |
|
| 35 | + $message = $this->getId().':'; |
|
| 36 | 36 | foreach ($vars as $key => $value) |
| 37 | 37 | $message .= " $key = $value;"; |
| 38 | 38 | |
@@ -33,8 +33,9 @@ |
||
| 33 | 33 | /** @return string default exception message */ |
| 34 | 34 | public function buildMessage(array $vars) { |
| 35 | 35 | $message = $this->getId() . ':'; |
| 36 | - foreach ($vars as $key => $value) |
|
| 37 | - $message .= " $key = $value;"; |
|
| 36 | + foreach ($vars as $key => $value) { |
|
| 37 | + $message .= " $key = $value;"; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | return $message; |
| 40 | 41 | } |