@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function to($value) |
| 40 | 40 | { |
| 41 | - if(isset($this->bindings[$this->activeKey])) { |
|
| 41 | + if (isset($this->bindings[$this->activeKey])) { |
|
| 42 | 42 | $this->bindings[$this->activeKey]['binding'] = $value; |
| 43 | 43 | } else { |
| 44 | 44 | $this->bindings[$this->activeKey] = ['binding' => $value, 'calls' => [], 'properties' => []]; |
@@ -63,13 +63,13 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | private function setArrayBinding($binding) |
| 65 | 65 | { |
| 66 | - if(isset($binding[0])) { |
|
| 66 | + if (isset($binding[0])) { |
|
| 67 | 67 | $this->to($binding[0]); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if(isset($binding['calls'])){ |
|
| 71 | - foreach($binding['calls'] as $call => $parameters) { |
|
| 72 | - if(is_numeric($call)) { |
|
| 70 | + if (isset($binding['calls'])) { |
|
| 71 | + foreach ($binding['calls'] as $call => $parameters) { |
|
| 72 | + if (is_numeric($call)) { |
|
| 73 | 73 | $call = $parameters; |
| 74 | 74 | $parameters = []; |
| 75 | 75 | } |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | $this->bindings[$this->activeKey]['calls'] = []; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(isset($binding['sets'])){ |
|
| 83 | - foreach($binding['sets'] as $property => $parameters) { |
|
| 84 | - if(is_numeric($property)) { |
|
| 82 | + if (isset($binding['sets'])) { |
|
| 83 | + foreach ($binding['sets'] as $property => $parameters) { |
|
| 84 | + if (is_numeric($property)) { |
|
| 85 | 85 | $property = $parameters; |
| 86 | 86 | $parameters = []; |
| 87 | 87 | } |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | public function merge($bindings) |
| 98 | 98 | { |
| 99 | - foreach($bindings as $key => $binding) { |
|
| 99 | + foreach ($bindings as $key => $binding) { |
|
| 100 | 100 | $this->activeKey = $key; |
| 101 | - if(is_array($binding)) { |
|
| 101 | + if (is_array($binding)) { |
|
| 102 | 102 | $this->setArrayBinding($binding); |
| 103 | 103 | } else { |
| 104 | 104 | $this->bindings[$key] = ['binding' => $binding, 'calls' => [], 'properties' => []]; |
@@ -20,6 +20,9 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | private $activeKey; |
| 22 | 22 | |
| 23 | + /** |
|
| 24 | + * @param string $activeKey |
|
| 25 | + */ |
|
| 23 | 26 | public function setActiveKey($activeKey) |
| 24 | 27 | { |
| 25 | 28 | $this->activeKey = $activeKey; |
@@ -46,11 +49,17 @@ discard block |
||
| 46 | 49 | return $this; |
| 47 | 50 | } |
| 48 | 51 | |
| 52 | + /** |
|
| 53 | + * @param string $key |
|
| 54 | + */ |
|
| 49 | 55 | public function get($key) |
| 50 | 56 | { |
| 51 | 57 | return $this->bindings[$key]; |
| 52 | 58 | } |
| 53 | 59 | |
| 60 | + /** |
|
| 61 | + * @param string $key |
|
| 62 | + */ |
|
| 54 | 63 | public function has($key) |
| 55 | 64 | { |
| 56 | 65 | return isset($this->bindings[$key]); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $instance = $this->getInstance($resolvedClass['binding'], $constructorArguments); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - foreach($resolvedClass['calls'] ?? [] as $calls) { |
|
| 103 | + foreach ($resolvedClass['calls'] ?? [] as $calls) { |
|
| 104 | 104 | $method = new \ReflectionMethod($instance, $calls[0]); |
| 105 | 105 | $method->invokeArgs($instance, $this->getMethodArguments($method, $calls[1])); |
| 106 | 106 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | private function resolveArgument($argument, $class) |
| 132 | 132 | { |
| 133 | - if($class && is_string($argument)) { |
|
| 133 | + if ($class && is_string($argument)) { |
|
| 134 | 134 | return $this->resolve($argument); |
| 135 | 135 | } |
| 136 | 136 | return $argument; |
@@ -153,8 +153,7 @@ discard block |
||
| 153 | 153 | if (isset($methodArguments[$parameter->getName()])) { |
| 154 | 154 | $argumentValues[] = $this->resolveArgument($methodArguments[$parameter->getName()], $className); |
| 155 | 155 | } else { |
| 156 | - $argumentValues[] = $className ? $this->resolve($className) : |
|
| 157 | - ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null); |
|
| 156 | + $argumentValues[] = $className ? $this->resolve($className) : ($parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null); |
|
| 158 | 157 | } |
| 159 | 158 | } |
| 160 | 159 | return $argumentValues; |