@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | $reflection = new \ReflectionClass($object); |
| 25 | 25 | |
| 26 | - if ($reflection->implementsInterface(QueueableInterface::class)) { |
|
| 26 | + if ($reflection->implementsInterface(QueueableInterface::class)){ |
|
| 27 | 27 | return true; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | $reflection = new \ReflectionClass($object); |
| 39 | 39 | |
| 40 | 40 | $attribute = $this->reader->firstClassMetadata($reflection, Queueable::class); |
| 41 | - if ($attribute !== null) { |
|
| 41 | + if ($attribute !== null){ |
|
| 42 | 42 | return $attribute->queue; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if (\is_object($object) && $reflection->hasMethod('getQueue')) { |
|
| 45 | + if (\is_object($object) && $reflection->hasMethod('getQueue')){ |
|
| 46 | 46 | return $reflection->getMethod('getQueue')->invoke($object); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -23,7 +23,8 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | $reflection = new \ReflectionClass($object); |
| 25 | 25 | |
| 26 | - if ($reflection->implementsInterface(QueueableInterface::class)) { |
|
| 26 | + if ($reflection->implementsInterface(QueueableInterface::class)) |
|
| 27 | + { |
|
| 27 | 28 | return true; |
| 28 | 29 | } |
| 29 | 30 | |
@@ -38,11 +39,13 @@ discard block |
||
| 38 | 39 | $reflection = new \ReflectionClass($object); |
| 39 | 40 | |
| 40 | 41 | $attribute = $this->reader->firstClassMetadata($reflection, Queueable::class); |
| 41 | - if ($attribute !== null) { |
|
| 42 | + if ($attribute !== null) |
|
| 43 | + { |
|
| 42 | 44 | return $attribute->queue; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - if (\is_object($object) && $reflection->hasMethod('getQueue')) { |
|
| 47 | + if (\is_object($object) && $reflection->hasMethod('getQueue')) |
|
| 48 | + { |
|
| 46 | 49 | return $reflection->getMethod('getQueue')->invoke($object); |
| 47 | 50 | } |
| 48 | 51 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function getSecured(): mixed |
| 72 | 72 | { |
| 73 | - if ($this->getProperty('secured', true) === '*') { |
|
| 73 | + if ($this->getProperty('secured', true) === '*'){ |
|
| 74 | 74 | return $this->getProperty('secured', true); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | public function declaredMethods(): array |
| 106 | 106 | { |
| 107 | 107 | $methods = []; |
| 108 | - foreach ($this->getMethods() as $method) { |
|
| 109 | - if ($method->getDeclaringClass()->getName() != $this->getName()) { |
|
| 108 | + foreach ($this->getMethods() as $method){ |
|
| 109 | + if ($method->getDeclaringClass()->getName() != $this->getName()){ |
|
| 110 | 110 | continue; |
| 111 | 111 | } |
| 112 | 112 | |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | self::MUTATOR_ACCESSOR => [], |
| 137 | 137 | ]; |
| 138 | 138 | |
| 139 | - foreach ((array)$this->getProperty('getters', true) as $field => $filter) { |
|
| 139 | + foreach ((array)$this->getProperty('getters', true) as $field => $filter){ |
|
| 140 | 140 | $mutators[self::MUTATOR_GETTER][$field] = $filter; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - foreach ((array)$this->getProperty('setters', true) as $field => $filter) { |
|
| 143 | + foreach ((array)$this->getProperty('setters', true) as $field => $filter){ |
|
| 144 | 144 | $mutators[self::MUTATOR_SETTER][$field] = $filter; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - foreach ((array)$this->getProperty('accessors', true) as $field => $filter) { |
|
| 147 | + foreach ((array)$this->getProperty('accessors', true) as $field => $filter){ |
|
| 148 | 148 | $mutators[self::MUTATOR_ACCESSOR][$field] = $filter; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function getProperty(string $property, bool $merge = false): mixed |
| 162 | 162 | { |
| 163 | - if (isset($this->propertyCache[$property])) { |
|
| 163 | + if (isset($this->propertyCache[$property])){ |
|
| 164 | 164 | //Property merging and trait events are pretty slow |
| 165 | 165 | return $this->propertyCache[$property]; |
| 166 | 166 | } |
@@ -168,27 +168,27 @@ discard block |
||
| 168 | 168 | $properties = $this->reflection->getDefaultProperties(); |
| 169 | 169 | $constants = $this->reflection->getConstants(); |
| 170 | 170 | |
| 171 | - if (isset($properties[$property])) { |
|
| 171 | + if (isset($properties[$property])){ |
|
| 172 | 172 | //Read from default value |
| 173 | 173 | $value = $properties[$property]; |
| 174 | - } elseif (isset($constants[\strtoupper($property)])) { |
|
| 174 | + } elseif (isset($constants[\strtoupper($property)])){ |
|
| 175 | 175 | //Read from a constant |
| 176 | 176 | $value = $constants[\strtoupper($property)]; |
| 177 | - } else { |
|
| 177 | + }else{ |
|
| 178 | 178 | return null; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | //Merge with parent value requested |
| 182 | - if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())) { |
|
| 182 | + if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())){ |
|
| 183 | 183 | $parentValue = $parent->getProperty($property, $merge); |
| 184 | 184 | |
| 185 | - if (\is_array($parentValue)) { |
|
| 185 | + if (\is_array($parentValue)){ |
|
| 186 | 186 | //Class values prior to parent values |
| 187 | 187 | $value = \array_merge($parentValue, $value); |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (!$this->reflection->isSubclassOf(SchematicEntity::class)) { |
|
| 191 | + if (!$this->reflection->isSubclassOf(SchematicEntity::class)){ |
|
| 192 | 192 | return $value; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | { |
| 204 | 204 | $parentClass = $this->reflection->getParentClass(); |
| 205 | 205 | |
| 206 | - if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) { |
|
| 206 | + if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS){ |
|
| 207 | 207 | $parent = clone $this; |
| 208 | 208 | $parent->reflection = $this->getParentClass(); |
| 209 | 209 | |
@@ -70,7 +70,8 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function getSecured(): mixed |
| 72 | 72 | { |
| 73 | - if ($this->getProperty('secured', true) === '*') { |
|
| 73 | + if ($this->getProperty('secured', true) === '*') |
|
| 74 | + { |
|
| 74 | 75 | return $this->getProperty('secured', true); |
| 75 | 76 | } |
| 76 | 77 | |
@@ -105,8 +106,10 @@ discard block |
||
| 105 | 106 | public function declaredMethods(): array |
| 106 | 107 | { |
| 107 | 108 | $methods = []; |
| 108 | - foreach ($this->getMethods() as $method) { |
|
| 109 | - if ($method->getDeclaringClass()->getName() != $this->getName()) { |
|
| 109 | + foreach ($this->getMethods() as $method) |
|
| 110 | + { |
|
| 111 | + if ($method->getDeclaringClass()->getName() != $this->getName()) |
|
| 112 | + { |
|
| 110 | 113 | continue; |
| 111 | 114 | } |
| 112 | 115 | |
@@ -136,15 +139,18 @@ discard block |
||
| 136 | 139 | self::MUTATOR_ACCESSOR => [], |
| 137 | 140 | ]; |
| 138 | 141 | |
| 139 | - foreach ((array)$this->getProperty('getters', true) as $field => $filter) { |
|
| 142 | + foreach ((array)$this->getProperty('getters', true) as $field => $filter) |
|
| 143 | + { |
|
| 140 | 144 | $mutators[self::MUTATOR_GETTER][$field] = $filter; |
| 141 | 145 | } |
| 142 | 146 | |
| 143 | - foreach ((array)$this->getProperty('setters', true) as $field => $filter) { |
|
| 147 | + foreach ((array)$this->getProperty('setters', true) as $field => $filter) |
|
| 148 | + { |
|
| 144 | 149 | $mutators[self::MUTATOR_SETTER][$field] = $filter; |
| 145 | 150 | } |
| 146 | 151 | |
| 147 | - foreach ((array)$this->getProperty('accessors', true) as $field => $filter) { |
|
| 152 | + foreach ((array)$this->getProperty('accessors', true) as $field => $filter) |
|
| 153 | + { |
|
| 148 | 154 | $mutators[self::MUTATOR_ACCESSOR][$field] = $filter; |
| 149 | 155 | } |
| 150 | 156 | |
@@ -160,7 +166,8 @@ discard block |
||
| 160 | 166 | */ |
| 161 | 167 | public function getProperty(string $property, bool $merge = false): mixed |
| 162 | 168 | { |
| 163 | - if (isset($this->propertyCache[$property])) { |
|
| 169 | + if (isset($this->propertyCache[$property])) |
|
| 170 | + { |
|
| 164 | 171 | //Property merging and trait events are pretty slow |
| 165 | 172 | return $this->propertyCache[$property]; |
| 166 | 173 | } |
@@ -168,27 +175,35 @@ discard block |
||
| 168 | 175 | $properties = $this->reflection->getDefaultProperties(); |
| 169 | 176 | $constants = $this->reflection->getConstants(); |
| 170 | 177 | |
| 171 | - if (isset($properties[$property])) { |
|
| 178 | + if (isset($properties[$property])) |
|
| 179 | + { |
|
| 172 | 180 | //Read from default value |
| 173 | 181 | $value = $properties[$property]; |
| 174 | - } elseif (isset($constants[\strtoupper($property)])) { |
|
| 182 | + } |
|
| 183 | + elseif (isset($constants[\strtoupper($property)])) |
|
| 184 | + { |
|
| 175 | 185 | //Read from a constant |
| 176 | 186 | $value = $constants[\strtoupper($property)]; |
| 177 | - } else { |
|
| 187 | + } |
|
| 188 | + else |
|
| 189 | + { |
|
| 178 | 190 | return null; |
| 179 | 191 | } |
| 180 | 192 | |
| 181 | 193 | //Merge with parent value requested |
| 182 | - if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())) { |
|
| 194 | + if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())) |
|
| 195 | + { |
|
| 183 | 196 | $parentValue = $parent->getProperty($property, $merge); |
| 184 | 197 | |
| 185 | - if (\is_array($parentValue)) { |
|
| 198 | + if (\is_array($parentValue)) |
|
| 199 | + { |
|
| 186 | 200 | //Class values prior to parent values |
| 187 | 201 | $value = \array_merge($parentValue, $value); |
| 188 | 202 | } |
| 189 | 203 | } |
| 190 | 204 | |
| 191 | - if (!$this->reflection->isSubclassOf(SchematicEntity::class)) { |
|
| 205 | + if (!$this->reflection->isSubclassOf(SchematicEntity::class)) |
|
| 206 | + { |
|
| 192 | 207 | return $value; |
| 193 | 208 | } |
| 194 | 209 | |
@@ -203,7 +218,8 @@ discard block |
||
| 203 | 218 | { |
| 204 | 219 | $parentClass = $this->reflection->getParentClass(); |
| 205 | 220 | |
| 206 | - if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) { |
|
| 221 | + if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) |
|
| 222 | + { |
|
| 207 | 223 | $parent = clone $this; |
| 208 | 224 | $parent->reflection = $this->getParentClass(); |
| 209 | 225 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function __construct( |
| 21 | 21 | private array $allowed, |
| 22 | 22 | private array $elements = [] |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function has(string $name): bool |
| 51 | 51 | { |
| 52 | - foreach ($this->elements as $element) { |
|
| 53 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
| 52 | + foreach ($this->elements as $element){ |
|
| 53 | + if ($element instanceof NamedInterface && $element->getName() === $name){ |
|
| 54 | 54 | return true; |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | $reflector = new \ReflectionObject($element); |
| 69 | 69 | |
| 70 | 70 | $allowed = false; |
| 71 | - foreach ($this->allowed as $class) { |
|
| 72 | - if ($reflector->isSubclassOf($class) || $element::class === $class) { |
|
| 71 | + foreach ($this->allowed as $class){ |
|
| 72 | + if ($reflector->isSubclassOf($class) || $element::class === $class){ |
|
| 73 | 73 | $allowed = true; |
| 74 | 74 | break; |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if (!$allowed) { |
|
| 78 | + if (!$allowed){ |
|
| 79 | 79 | $type = $element::class; |
| 80 | 80 | throw new ReactorException(\sprintf("Elements with type '%s' are not allowed", $type)); |
| 81 | 81 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function remove(string $name): self |
| 103 | 103 | { |
| 104 | - foreach ($this->elements as $index => $element) { |
|
| 105 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
| 104 | + foreach ($this->elements as $index => $element){ |
|
| 105 | + if ($element instanceof NamedInterface && $element->getName() === $name){ |
|
| 106 | 106 | unset($this->elements[$index]); |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | protected function find(string $name): AggregableInterface |
| 154 | 154 | { |
| 155 | - foreach ($this->elements as $element) { |
|
| 156 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
| 155 | + foreach ($this->elements as $element){ |
|
| 156 | + if ($element instanceof NamedInterface && $element->getName() === $name){ |
|
| 157 | 157 | return $element; |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -49,8 +49,10 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function has(string $name): bool |
| 51 | 51 | { |
| 52 | - foreach ($this->elements as $element) { |
|
| 53 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
| 52 | + foreach ($this->elements as $element) |
|
| 53 | + { |
|
| 54 | + if ($element instanceof NamedInterface && $element->getName() === $name) |
|
| 55 | + { |
|
| 54 | 56 | return true; |
| 55 | 57 | } |
| 56 | 58 | } |
@@ -68,14 +70,17 @@ discard block |
||
| 68 | 70 | $reflector = new \ReflectionObject($element); |
| 69 | 71 | |
| 70 | 72 | $allowed = false; |
| 71 | - foreach ($this->allowed as $class) { |
|
| 72 | - if ($reflector->isSubclassOf($class) || $element::class === $class) { |
|
| 73 | + foreach ($this->allowed as $class) |
|
| 74 | + { |
|
| 75 | + if ($reflector->isSubclassOf($class) || $element::class === $class) |
|
| 76 | + { |
|
| 73 | 77 | $allowed = true; |
| 74 | 78 | break; |
| 75 | 79 | } |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | - if (!$allowed) { |
|
| 82 | + if (!$allowed) |
|
| 83 | + { |
|
| 79 | 84 | $type = $element::class; |
| 80 | 85 | throw new ReactorException(\sprintf("Elements with type '%s' are not allowed", $type)); |
| 81 | 86 | } |
@@ -101,8 +106,10 @@ discard block |
||
| 101 | 106 | */ |
| 102 | 107 | public function remove(string $name): self |
| 103 | 108 | { |
| 104 | - foreach ($this->elements as $index => $element) { |
|
| 105 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
| 109 | + foreach ($this->elements as $index => $element) |
|
| 110 | + { |
|
| 111 | + if ($element instanceof NamedInterface && $element->getName() === $name) |
|
| 112 | + { |
|
| 106 | 113 | unset($this->elements[$index]); |
| 107 | 114 | } |
| 108 | 115 | } |
@@ -152,8 +159,10 @@ discard block |
||
| 152 | 159 | */ |
| 153 | 160 | protected function find(string $name): AggregableInterface |
| 154 | 161 | { |
| 155 | - foreach ($this->elements as $element) { |
|
| 156 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
| 162 | + foreach ($this->elements as $element) |
|
| 163 | + { |
|
| 164 | + if ($element instanceof NamedInterface && $element->getName() === $name) |
|
| 165 | + { |
|
| 157 | 166 | return $element; |
| 158 | 167 | } |
| 159 | 168 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly QueueInterface $connection, |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | string $action, |
| 32 | 32 | array $parameters = ['options' => null, 'payload' => []], |
| 33 | 33 | ): string { |
| 34 | - if ($parameters['options'] === null) { |
|
| 34 | + if ($parameters['options'] === null){ |
|
| 35 | 35 | $parameters['options'] = new Options(); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | $tracer = $this->getTracer(); |
| 39 | 39 | |
| 40 | - if (\method_exists($parameters['options'], 'withHeader')) { |
|
| 41 | - foreach ($tracer->getContext() as $key => $data) { |
|
| 40 | + if (\method_exists($parameters['options'], 'withHeader')){ |
|
| 41 | + foreach ($tracer->getContext() as $key => $data){ |
|
| 42 | 42 | $parameters['options'] = $parameters['options']->withHeader($key, $data); |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | private function getTracer(): TracerInterface |
| 60 | 60 | { |
| 61 | - try { |
|
| 61 | + try{ |
|
| 62 | 62 | return ContainerScope::getContainer()->get(TracerInterface::class); |
| 63 | - } catch (\Throwable $e) { |
|
| 63 | + }catch (\Throwable $e){ |
|
| 64 | 64 | return new NullTracer(); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -31,14 +31,17 @@ discard block |
||
| 31 | 31 | string $action, |
| 32 | 32 | array $parameters = ['options' => null, 'payload' => []], |
| 33 | 33 | ): string { |
| 34 | - if ($parameters['options'] === null) { |
|
| 34 | + if ($parameters['options'] === null) |
|
| 35 | + { |
|
| 35 | 36 | $parameters['options'] = new Options(); |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | $tracer = $this->getTracer(); |
| 39 | 40 | |
| 40 | - if (\method_exists($parameters['options'], 'withHeader')) { |
|
| 41 | - foreach ($tracer->getContext() as $key => $data) { |
|
| 41 | + if (\method_exists($parameters['options'], 'withHeader')) |
|
| 42 | + { |
|
| 43 | + foreach ($tracer->getContext() as $key => $data) |
|
| 44 | + { |
|
| 42 | 45 | $parameters['options'] = $parameters['options']->withHeader($key, $data); |
| 43 | 46 | } |
| 44 | 47 | } |
@@ -58,9 +61,12 @@ discard block |
||
| 58 | 61 | |
| 59 | 62 | private function getTracer(): TracerInterface |
| 60 | 63 | { |
| 61 | - try { |
|
| 64 | + try |
|
| 65 | + { |
|
| 62 | 66 | return ContainerScope::getContainer()->get(TracerInterface::class); |
| 63 | - } catch (\Throwable $e) { |
|
| 67 | + } |
|
| 68 | + catch (\Throwable $e) |
|
| 69 | + { |
|
| 64 | 70 | return new NullTracer(); |
| 65 | 71 | } |
| 66 | 72 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
| 68 | 68 | { |
| 69 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 69 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
| 70 | 70 | return $this->state->singletons[$alias]; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $binding = $this->state->bindings[$alias] ?? null; |
| 74 | 74 | |
| 75 | - if ($binding === null) { |
|
| 75 | + if ($binding === null){ |
|
| 76 | 76 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - try { |
|
| 79 | + try{ |
|
| 80 | 80 | $this->tracer->push( |
| 81 | 81 | false, |
| 82 | 82 | action: 'resolve from binding', |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 101 | 101 | default => $binding, |
| 102 | 102 | }; |
| 103 | - } finally { |
|
| 103 | + }finally{ |
|
| 104 | 104 | $this->state->bindings[$alias] ??= $binding; |
| 105 | 105 | $this->tracer->pop(true); |
| 106 | 106 | $this->tracer->pop(false); |
@@ -112,27 +112,27 @@ discard block |
||
| 112 | 112 | string $alias, |
| 113 | 113 | ?string $context, |
| 114 | 114 | array $arguments, |
| 115 | - ) { |
|
| 116 | - $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
|
| 115 | + ){ |
|
| 116 | + $ctx = new Ctx(alias : $alias, class : $alias, parameter : $context); |
|
| 117 | 117 | |
| 118 | 118 | // We have to construct class using external injector when we know exact context |
| 119 | - if ($arguments !== []) { |
|
| 119 | + if ($arguments !== []){ |
|
| 120 | 120 | // todo factory? |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $class = $ctx->class; |
| 124 | - try { |
|
| 124 | + try{ |
|
| 125 | 125 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 126 | - } catch (\ReflectionException $e) { |
|
| 126 | + }catch (\ReflectionException $e){ |
|
| 127 | 127 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | $injector = $binding->injector; |
| 131 | 131 | |
| 132 | - try { |
|
| 132 | + try{ |
|
| 133 | 133 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 134 | 134 | |
| 135 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 135 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 136 | 136 | throw new InjectionException( |
| 137 | 137 | \sprintf( |
| 138 | 138 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @psalm-suppress RedundantCondition |
| 147 | 147 | */ |
| 148 | 148 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
| 149 | - if (!$reflection->isInstance($instance)) { |
|
| 149 | + if (!$reflection->isInstance($instance)){ |
|
| 150 | 150 | throw new InjectionException( |
| 151 | 151 | \sprintf( |
| 152 | 152 | "Invalid injection response for '%s'.", |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | return $instance; |
| 159 | - } finally { |
|
| 159 | + }finally{ |
|
| 160 | 160 | $this->state->bindings[$reflection->getName()] ??= $binding; //new Injector($injector); |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | ): mixed { |
| 170 | 170 | $result = $binding->alias === $alias |
| 171 | 171 | ? $this->autowire( |
| 172 | - new Ctx(alias: $alias, class: $binding->alias, parameter: $context, singleton: $binding->singleton), |
|
| 172 | + new Ctx(alias : $alias, class : $binding->alias, parameter : $context, singleton : $binding->singleton), |
|
| 173 | 173 | $arguments, |
| 174 | 174 | ) |
| 175 | 175 | //Binding is pointing to something else |
| 176 | 176 | : $this->make($binding->alias, $arguments, $context); |
| 177 | 177 | |
| 178 | - if ($binding->singleton && $arguments === []) { |
|
| 178 | + if ($binding->singleton && $arguments === []){ |
|
| 179 | 179 | $this->state->singletons[$alias] = $result; |
| 180 | 180 | } |
| 181 | 181 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $avoidCache = $arguments !== []; |
| 192 | 192 | return $avoidCache |
| 193 | 193 | ? $this->createInstance( |
| 194 | - new Ctx(alias: $alias, class: $binding->value::class, parameter: $context), |
|
| 194 | + new Ctx(alias : $alias, class : $binding->value::class, parameter : $context), |
|
| 195 | 195 | $arguments, |
| 196 | 196 | ) |
| 197 | 197 | : $binding->value; |
@@ -210,17 +210,17 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | private function resolveFactory( |
| 213 | - \Spiral\Core\Config\Factory|DeferredFactory $binding, |
|
| 213 | + \Spiral\Core\Config\Factory | DeferredFactory $binding, |
|
| 214 | 214 | string $alias, |
| 215 | 215 | ?string $context, |
| 216 | 216 | array $arguments, |
| 217 | 217 | ): mixed { |
| 218 | - $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context, singleton: $binding->singleton); |
|
| 219 | - try { |
|
| 218 | + $ctx = new Ctx(alias : $alias, class : $alias, parameter : $context, singleton : $binding->singleton); |
|
| 219 | + try{ |
|
| 220 | 220 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
| 221 | 221 | ? ($binding->factory)() |
| 222 | 222 | : $this->invoker->invoke($binding->factory, $arguments); |
| 223 | - } catch (NotCallableException $e) { |
|
| 223 | + }catch (NotCallableException $e){ |
|
| 224 | 224 | throw new ContainerException( |
| 225 | 225 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 226 | 226 | $e->getCode(), |
@@ -239,19 +239,19 @@ discard block |
||
| 239 | 239 | ): ?object { |
| 240 | 240 | $avoidCache = $arguments !== []; |
| 241 | 241 | |
| 242 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 243 | - try { |
|
| 242 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
| 243 | + try{ |
|
| 244 | 244 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 245 | 245 | |
| 246 | 246 | $object = $this->createInstance( |
| 247 | 247 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
| 248 | 248 | $arguments, |
| 249 | 249 | ); |
| 250 | - if ($avoidCache) { |
|
| 250 | + if ($avoidCache){ |
|
| 251 | 251 | return $object; |
| 252 | 252 | } |
| 253 | 253 | $binding->reference = WeakReference::create($object); |
| 254 | - } catch (\Throwable) { |
|
| 254 | + }catch (\Throwable){ |
|
| 255 | 255 | throw new ContainerException( |
| 256 | 256 | $this->tracer->combineTraceMessage( |
| 257 | 257 | \sprintf( |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | ) |
| 262 | 262 | ) |
| 263 | 263 | ); |
| 264 | - } finally { |
|
| 264 | + }finally{ |
|
| 265 | 265 | $this->tracer->pop(); |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -273,18 +273,18 @@ discard block |
||
| 273 | 273 | { |
| 274 | 274 | $parent = $this->scope->getParent(); |
| 275 | 275 | |
| 276 | - if ($parent !== null) { |
|
| 277 | - try { |
|
| 276 | + if ($parent !== null){ |
|
| 277 | + try{ |
|
| 278 | 278 | $this->tracer->push(false, ...[ |
| 279 | 279 | 'current scope' => $this->scope->getScopeName(), |
| 280 | 280 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 281 | 281 | ]); |
| 282 | 282 | return $parent->make($alias, $parameters, $context); |
| 283 | - } catch (BadScopeException $e) { |
|
| 284 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 283 | + }catch (BadScopeException $e){ |
|
| 284 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
| 285 | 285 | throw $e; |
| 286 | 286 | } |
| 287 | - } catch (ContainerExceptionInterface $e) { |
|
| 287 | + }catch (ContainerExceptionInterface $e){ |
|
| 288 | 288 | $className = match (true) { |
| 289 | 289 | $e instanceof NotFoundException => NotFoundException::class, |
| 290 | 290 | default => ContainerException::class, |
@@ -293,19 +293,19 @@ discard block |
||
| 293 | 293 | 'Can\'t resolve `%s`.', |
| 294 | 294 | $alias, |
| 295 | 295 | )), previous: $e); |
| 296 | - } finally { |
|
| 296 | + }finally{ |
|
| 297 | 297 | $this->tracer->pop(false); |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 302 | - try { |
|
| 302 | + try{ |
|
| 303 | 303 | //No direct instructions how to construct class, make is automatically |
| 304 | 304 | return $this->autowire( |
| 305 | 305 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
| 306 | 306 | $parameters, |
| 307 | 307 | ); |
| 308 | - } finally { |
|
| 308 | + }finally{ |
|
| 309 | 309 | $this->tracer->pop(false); |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | && |
| 328 | 328 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
| 329 | 329 | )) |
| 330 | - ) { |
|
| 330 | + ){ |
|
| 331 | 331 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
| 332 | 332 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
| 333 | 333 | $this->tracer->getRootAlias(), |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | // Check scope name |
| 357 | 357 | $ctx->reflection = new \ReflectionClass($instance); |
| 358 | 358 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
| 359 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
| 359 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
| 360 | 360 | throw new BadScopeException($scopeName, $instance::class); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -383,24 +383,24 @@ discard block |
||
| 383 | 383 | array $parameters, |
| 384 | 384 | ): object { |
| 385 | 385 | $class = $ctx->class; |
| 386 | - try { |
|
| 386 | + try{ |
|
| 387 | 387 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 388 | - } catch (\ReflectionException $e) { |
|
| 388 | + }catch (\ReflectionException $e){ |
|
| 389 | 389 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | // Check scope name |
| 393 | 393 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
| 394 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 394 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
| 395 | 395 | throw new BadScopeException($scope, $class); |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | //We have to construct class using external injector when we know exact context |
| 399 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
| 399 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
| 400 | 400 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx->class, $ctx->parameter, $parameters); |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if (!$reflection->isInstantiable()) { |
|
| 403 | + if (!$reflection->isInstantiable()){ |
|
| 404 | 404 | $itIs = match (true) { |
| 405 | 405 | $reflection->isEnum() => 'Enum', |
| 406 | 406 | $reflection->isAbstract() => 'Abstract class', |
@@ -413,12 +413,12 @@ discard block |
||
| 413 | 413 | |
| 414 | 414 | $constructor = $reflection->getConstructor(); |
| 415 | 415 | |
| 416 | - if ($constructor !== null) { |
|
| 417 | - try { |
|
| 416 | + if ($constructor !== null){ |
|
| 417 | + try{ |
|
| 418 | 418 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 419 | 419 | $this->tracer->push(true); |
| 420 | 420 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
| 421 | - } catch (ValidationException $e) { |
|
| 421 | + }catch (ValidationException $e){ |
|
| 422 | 422 | throw new ContainerException( |
| 423 | 423 | $this->tracer->combineTraceMessage( |
| 424 | 424 | \sprintf( |
@@ -428,22 +428,22 @@ discard block |
||
| 428 | 428 | ) |
| 429 | 429 | ), |
| 430 | 430 | ); |
| 431 | - } finally { |
|
| 431 | + }finally{ |
|
| 432 | 432 | $this->tracer->pop(true); |
| 433 | 433 | $this->tracer->pop(false); |
| 434 | 434 | } |
| 435 | - try { |
|
| 435 | + try{ |
|
| 436 | 436 | // Using constructor with resolved arguments |
| 437 | 437 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
| 438 | 438 | $this->tracer->push(true); |
| 439 | 439 | $instance = new $class(...$arguments); |
| 440 | - } catch (\TypeError $e) { |
|
| 440 | + }catch (\TypeError $e){ |
|
| 441 | 441 | throw new WrongTypeException($constructor, $e); |
| 442 | - } finally { |
|
| 442 | + }finally{ |
|
| 443 | 443 | $this->tracer->pop(true); |
| 444 | 444 | $this->tracer->pop(false); |
| 445 | 445 | } |
| 446 | - } else { |
|
| 446 | + }else{ |
|
| 447 | 447 | // No constructor specified |
| 448 | 448 | $instance = $reflection->newInstance(); |
| 449 | 449 | } |
@@ -461,13 +461,13 @@ discard block |
||
| 461 | 461 | $instance = $this->runInflector($instance); |
| 462 | 462 | |
| 463 | 463 | //Declarative singletons |
| 464 | - if ($this->isSingleton($ctx)) { |
|
| 464 | + if ($this->isSingleton($ctx)){ |
|
| 465 | 465 | $this->state->singletons[$ctx->alias] = $instance; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // Register finalizer |
| 469 | 469 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 470 | - if ($finalizer !== null) { |
|
| 470 | + if ($finalizer !== null){ |
|
| 471 | 471 | $this->state->finalizers[] = $finalizer; |
| 472 | 472 | } |
| 473 | 473 | |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | */ |
| 480 | 480 | private function isSingleton(Ctx $ctx): bool |
| 481 | 481 | { |
| 482 | - if ($ctx->singleton === true) { |
|
| 482 | + if ($ctx->singleton === true){ |
|
| 483 | 483 | return true; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 486 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
| 487 | 487 | return true; |
| 488 | 488 | } |
| 489 | 489 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | * @var Finalize|null $attribute |
| 498 | 498 | */ |
| 499 | 499 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
| 500 | - if ($attribute === null) { |
|
| 500 | + if ($attribute === null){ |
|
| 501 | 501 | return null; |
| 502 | 502 | } |
| 503 | 503 | |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | { |
| 512 | 512 | $scope = $this->scope; |
| 513 | 513 | |
| 514 | - while ($scope !== null) { |
|
| 515 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 516 | - if ($instance instanceof $class) { |
|
| 517 | - foreach ($inflectors as $inflector) { |
|
| 514 | + while ($scope !== null){ |
|
| 515 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
| 516 | + if ($instance instanceof $class){ |
|
| 517 | + foreach ($inflectors as $inflector){ |
|
| 518 | 518 | $instance = $inflector->getParametersCount() > 1 |
| 519 | 519 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 520 | 520 | : ($inflector->inflector)($instance); |
@@ -66,17 +66,20 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
| 68 | 68 | { |
| 69 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 69 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
| 70 | + { |
|
| 70 | 71 | return $this->state->singletons[$alias]; |
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | $binding = $this->state->bindings[$alias] ?? null; |
| 74 | 75 | |
| 75 | - if ($binding === null) { |
|
| 76 | + if ($binding === null) |
|
| 77 | + { |
|
| 76 | 78 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 77 | 79 | } |
| 78 | 80 | |
| 79 | - try { |
|
| 81 | + try |
|
| 82 | + { |
|
| 80 | 83 | $this->tracer->push( |
| 81 | 84 | false, |
| 82 | 85 | action: 'resolve from binding', |
@@ -100,7 +103,9 @@ discard block |
||
| 100 | 103 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 101 | 104 | default => $binding, |
| 102 | 105 | }; |
| 103 | - } finally { |
|
| 106 | + } |
|
| 107 | + finally |
|
| 108 | + { |
|
| 104 | 109 | $this->state->bindings[$alias] ??= $binding; |
| 105 | 110 | $this->tracer->pop(true); |
| 106 | 111 | $this->tracer->pop(false); |
@@ -116,23 +121,29 @@ discard block |
||
| 116 | 121 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
| 117 | 122 | |
| 118 | 123 | // We have to construct class using external injector when we know exact context |
| 119 | - if ($arguments !== []) { |
|
| 124 | + if ($arguments !== []) |
|
| 125 | + { |
|
| 120 | 126 | // todo factory? |
| 121 | 127 | } |
| 122 | 128 | |
| 123 | 129 | $class = $ctx->class; |
| 124 | - try { |
|
| 130 | + try |
|
| 131 | + { |
|
| 125 | 132 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 126 | - } catch (\ReflectionException $e) { |
|
| 133 | + } |
|
| 134 | + catch (\ReflectionException $e) |
|
| 135 | + { |
|
| 127 | 136 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 128 | 137 | } |
| 129 | 138 | |
| 130 | 139 | $injector = $binding->injector; |
| 131 | 140 | |
| 132 | - try { |
|
| 141 | + try |
|
| 142 | + { |
|
| 133 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 134 | 144 | |
| 135 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 145 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 146 | + { |
|
| 136 | 147 | throw new InjectionException( |
| 137 | 148 | \sprintf( |
| 138 | 149 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -146,7 +157,8 @@ discard block |
||
| 146 | 157 | * @psalm-suppress RedundantCondition |
| 147 | 158 | */ |
| 148 | 159 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
| 149 | - if (!$reflection->isInstance($instance)) { |
|
| 160 | + if (!$reflection->isInstance($instance)) |
|
| 161 | + { |
|
| 150 | 162 | throw new InjectionException( |
| 151 | 163 | \sprintf( |
| 152 | 164 | "Invalid injection response for '%s'.", |
@@ -156,7 +168,9 @@ discard block |
||
| 156 | 168 | } |
| 157 | 169 | |
| 158 | 170 | return $instance; |
| 159 | - } finally { |
|
| 171 | + } |
|
| 172 | + finally |
|
| 173 | + { |
|
| 160 | 174 | $this->state->bindings[$reflection->getName()] ??= $binding; //new Injector($injector); |
| 161 | 175 | } |
| 162 | 176 | } |
@@ -175,7 +189,8 @@ discard block |
||
| 175 | 189 | //Binding is pointing to something else |
| 176 | 190 | : $this->make($binding->alias, $arguments, $context); |
| 177 | 191 | |
| 178 | - if ($binding->singleton && $arguments === []) { |
|
| 192 | + if ($binding->singleton && $arguments === []) |
|
| 193 | + { |
|
| 179 | 194 | $this->state->singletons[$alias] = $result; |
| 180 | 195 | } |
| 181 | 196 | |
@@ -216,11 +231,14 @@ discard block |
||
| 216 | 231 | array $arguments, |
| 217 | 232 | ): mixed { |
| 218 | 233 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context, singleton: $binding->singleton); |
| 219 | - try { |
|
| 234 | + try |
|
| 235 | + { |
|
| 220 | 236 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
| 221 | 237 | ? ($binding->factory)() |
| 222 | 238 | : $this->invoker->invoke($binding->factory, $arguments); |
| 223 | - } catch (NotCallableException $e) { |
|
| 239 | + } |
|
| 240 | + catch (NotCallableException $e) |
|
| 241 | + { |
|
| 224 | 242 | throw new ContainerException( |
| 225 | 243 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 226 | 244 | $e->getCode(), |
@@ -239,19 +257,24 @@ discard block |
||
| 239 | 257 | ): ?object { |
| 240 | 258 | $avoidCache = $arguments !== []; |
| 241 | 259 | |
| 242 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 243 | - try { |
|
| 260 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
| 261 | + { |
|
| 262 | + try |
|
| 263 | + { |
|
| 244 | 264 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 245 | 265 | |
| 246 | 266 | $object = $this->createInstance( |
| 247 | 267 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
| 248 | 268 | $arguments, |
| 249 | 269 | ); |
| 250 | - if ($avoidCache) { |
|
| 270 | + if ($avoidCache) |
|
| 271 | + { |
|
| 251 | 272 | return $object; |
| 252 | 273 | } |
| 253 | 274 | $binding->reference = WeakReference::create($object); |
| 254 | - } catch (\Throwable) { |
|
| 275 | + } |
|
| 276 | + catch (\Throwable) |
|
| 277 | + { |
|
| 255 | 278 | throw new ContainerException( |
| 256 | 279 | $this->tracer->combineTraceMessage( |
| 257 | 280 | \sprintf( |
@@ -261,7 +284,9 @@ discard block |
||
| 261 | 284 | ) |
| 262 | 285 | ) |
| 263 | 286 | ); |
| 264 | - } finally { |
|
| 287 | + } |
|
| 288 | + finally |
|
| 289 | + { |
|
| 265 | 290 | $this->tracer->pop(); |
| 266 | 291 | } |
| 267 | 292 | } |
@@ -273,18 +298,25 @@ discard block |
||
| 273 | 298 | { |
| 274 | 299 | $parent = $this->scope->getParent(); |
| 275 | 300 | |
| 276 | - if ($parent !== null) { |
|
| 277 | - try { |
|
| 301 | + if ($parent !== null) |
|
| 302 | + { |
|
| 303 | + try |
|
| 304 | + { |
|
| 278 | 305 | $this->tracer->push(false, ...[ |
| 279 | 306 | 'current scope' => $this->scope->getScopeName(), |
| 280 | 307 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 281 | 308 | ]); |
| 282 | 309 | return $parent->make($alias, $parameters, $context); |
| 283 | - } catch (BadScopeException $e) { |
|
| 284 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 310 | + } |
|
| 311 | + catch (BadScopeException $e) |
|
| 312 | + { |
|
| 313 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
| 314 | + { |
|
| 285 | 315 | throw $e; |
| 286 | 316 | } |
| 287 | - } catch (ContainerExceptionInterface $e) { |
|
| 317 | + } |
|
| 318 | + catch (ContainerExceptionInterface $e) |
|
| 319 | + { |
|
| 288 | 320 | $className = match (true) { |
| 289 | 321 | $e instanceof NotFoundException => NotFoundException::class, |
| 290 | 322 | default => ContainerException::class, |
@@ -293,19 +325,24 @@ discard block |
||
| 293 | 325 | 'Can\'t resolve `%s`.', |
| 294 | 326 | $alias, |
| 295 | 327 | )), previous: $e); |
| 296 | - } finally { |
|
| 328 | + } |
|
| 329 | + finally |
|
| 330 | + { |
|
| 297 | 331 | $this->tracer->pop(false); |
| 298 | 332 | } |
| 299 | 333 | } |
| 300 | 334 | |
| 301 | 335 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 302 | - try { |
|
| 336 | + try |
|
| 337 | + { |
|
| 303 | 338 | //No direct instructions how to construct class, make is automatically |
| 304 | 339 | return $this->autowire( |
| 305 | 340 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
| 306 | 341 | $parameters, |
| 307 | 342 | ); |
| 308 | - } finally { |
|
| 343 | + } |
|
| 344 | + finally |
|
| 345 | + { |
|
| 309 | 346 | $this->tracer->pop(false); |
| 310 | 347 | } |
| 311 | 348 | } |
@@ -356,7 +393,8 @@ discard block |
||
| 356 | 393 | // Check scope name |
| 357 | 394 | $ctx->reflection = new \ReflectionClass($instance); |
| 358 | 395 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
| 359 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
| 396 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) |
|
| 397 | + { |
|
| 360 | 398 | throw new BadScopeException($scopeName, $instance::class); |
| 361 | 399 | } |
| 362 | 400 | |
@@ -383,24 +421,30 @@ discard block |
||
| 383 | 421 | array $parameters, |
| 384 | 422 | ): object { |
| 385 | 423 | $class = $ctx->class; |
| 386 | - try { |
|
| 424 | + try |
|
| 425 | + { |
|
| 387 | 426 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 388 | - } catch (\ReflectionException $e) { |
|
| 427 | + } |
|
| 428 | + catch (\ReflectionException $e) |
|
| 429 | + { |
|
| 389 | 430 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 390 | 431 | } |
| 391 | 432 | |
| 392 | 433 | // Check scope name |
| 393 | 434 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
| 394 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 435 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
| 436 | + { |
|
| 395 | 437 | throw new BadScopeException($scope, $class); |
| 396 | 438 | } |
| 397 | 439 | |
| 398 | 440 | //We have to construct class using external injector when we know exact context |
| 399 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
| 441 | + if ($parameters === [] && $this->binder->hasInjector($class)) |
|
| 442 | + { |
|
| 400 | 443 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx->class, $ctx->parameter, $parameters); |
| 401 | 444 | } |
| 402 | 445 | |
| 403 | - if (!$reflection->isInstantiable()) { |
|
| 446 | + if (!$reflection->isInstantiable()) |
|
| 447 | + { |
|
| 404 | 448 | $itIs = match (true) { |
| 405 | 449 | $reflection->isEnum() => 'Enum', |
| 406 | 450 | $reflection->isAbstract() => 'Abstract class', |
@@ -413,12 +457,16 @@ discard block |
||
| 413 | 457 | |
| 414 | 458 | $constructor = $reflection->getConstructor(); |
| 415 | 459 | |
| 416 | - if ($constructor !== null) { |
|
| 417 | - try { |
|
| 460 | + if ($constructor !== null) |
|
| 461 | + { |
|
| 462 | + try |
|
| 463 | + { |
|
| 418 | 464 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 419 | 465 | $this->tracer->push(true); |
| 420 | 466 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
| 421 | - } catch (ValidationException $e) { |
|
| 467 | + } |
|
| 468 | + catch (ValidationException $e) |
|
| 469 | + { |
|
| 422 | 470 | throw new ContainerException( |
| 423 | 471 | $this->tracer->combineTraceMessage( |
| 424 | 472 | \sprintf( |
@@ -428,22 +476,31 @@ discard block |
||
| 428 | 476 | ) |
| 429 | 477 | ), |
| 430 | 478 | ); |
| 431 | - } finally { |
|
| 479 | + } |
|
| 480 | + finally |
|
| 481 | + { |
|
| 432 | 482 | $this->tracer->pop(true); |
| 433 | 483 | $this->tracer->pop(false); |
| 434 | 484 | } |
| 435 | - try { |
|
| 485 | + try |
|
| 486 | + { |
|
| 436 | 487 | // Using constructor with resolved arguments |
| 437 | 488 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
| 438 | 489 | $this->tracer->push(true); |
| 439 | 490 | $instance = new $class(...$arguments); |
| 440 | - } catch (\TypeError $e) { |
|
| 491 | + } |
|
| 492 | + catch (\TypeError $e) |
|
| 493 | + { |
|
| 441 | 494 | throw new WrongTypeException($constructor, $e); |
| 442 | - } finally { |
|
| 495 | + } |
|
| 496 | + finally |
|
| 497 | + { |
|
| 443 | 498 | $this->tracer->pop(true); |
| 444 | 499 | $this->tracer->pop(false); |
| 445 | 500 | } |
| 446 | - } else { |
|
| 501 | + } |
|
| 502 | + else |
|
| 503 | + { |
|
| 447 | 504 | // No constructor specified |
| 448 | 505 | $instance = $reflection->newInstance(); |
| 449 | 506 | } |
@@ -461,13 +518,15 @@ discard block |
||
| 461 | 518 | $instance = $this->runInflector($instance); |
| 462 | 519 | |
| 463 | 520 | //Declarative singletons |
| 464 | - if ($this->isSingleton($ctx)) { |
|
| 521 | + if ($this->isSingleton($ctx)) |
|
| 522 | + { |
|
| 465 | 523 | $this->state->singletons[$ctx->alias] = $instance; |
| 466 | 524 | } |
| 467 | 525 | |
| 468 | 526 | // Register finalizer |
| 469 | 527 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 470 | - if ($finalizer !== null) { |
|
| 528 | + if ($finalizer !== null) |
|
| 529 | + { |
|
| 471 | 530 | $this->state->finalizers[] = $finalizer; |
| 472 | 531 | } |
| 473 | 532 | |
@@ -479,11 +538,13 @@ discard block |
||
| 479 | 538 | */ |
| 480 | 539 | private function isSingleton(Ctx $ctx): bool |
| 481 | 540 | { |
| 482 | - if ($ctx->singleton === true) { |
|
| 541 | + if ($ctx->singleton === true) |
|
| 542 | + { |
|
| 483 | 543 | return true; |
| 484 | 544 | } |
| 485 | 545 | |
| 486 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 546 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
| 547 | + { |
|
| 487 | 548 | return true; |
| 488 | 549 | } |
| 489 | 550 | |
@@ -497,7 +558,8 @@ discard block |
||
| 497 | 558 | * @var Finalize|null $attribute |
| 498 | 559 | */ |
| 499 | 560 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
| 500 | - if ($attribute === null) { |
|
| 561 | + if ($attribute === null) |
|
| 562 | + { |
|
| 501 | 563 | return null; |
| 502 | 564 | } |
| 503 | 565 | |
@@ -511,10 +573,14 @@ discard block |
||
| 511 | 573 | { |
| 512 | 574 | $scope = $this->scope; |
| 513 | 575 | |
| 514 | - while ($scope !== null) { |
|
| 515 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 516 | - if ($instance instanceof $class) { |
|
| 517 | - foreach ($inflectors as $inflector) { |
|
| 576 | + while ($scope !== null) |
|
| 577 | + { |
|
| 578 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
| 579 | + { |
|
| 580 | + if ($instance instanceof $class) |
|
| 581 | + { |
|
| 582 | + foreach ($inflectors as $inflector) |
|
| 583 | + { |
|
| 518 | 584 | $instance = $inflector->getParametersCount() > 1 |
| 519 | 585 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 520 | 586 | : ($inflector->inflector)($instance); |
@@ -49,11 +49,11 @@ discard block |
||
| 49 | 49 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
| 50 | 50 | |
| 51 | 51 | private Internal\State $state; |
| 52 | - private ResolverInterface|Internal\Resolver $resolver; |
|
| 53 | - private FactoryInterface|Internal\Factory $factory; |
|
| 54 | - private ContainerInterface|Internal\Container $container; |
|
| 55 | - private BinderInterface|Internal\Binder $binder; |
|
| 56 | - private InvokerInterface|Internal\Invoker $invoker; |
|
| 52 | + private ResolverInterface | Internal\Resolver $resolver; |
|
| 53 | + private FactoryInterface | Internal\Factory $factory; |
|
| 54 | + private ContainerInterface | Internal\Container $container; |
|
| 55 | + private BinderInterface | Internal\Binder $binder; |
|
| 56 | + private InvokerInterface | Internal\Invoker $invoker; |
|
| 57 | 57 | private Internal\Scope $scope; |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | public function __construct( |
| 63 | 63 | private Config $config = new Config(), |
| 64 | 64 | ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
| 65 | - ) { |
|
| 65 | + ){ |
|
| 66 | 66 | $this->initServices($this, $scopeName); |
| 67 | 67 | |
| 68 | 68 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @throws ContainerException |
| 139 | 139 | * @throws \Throwable |
| 140 | 140 | */ |
| 141 | - public function get(string|Autowire $id, string $context = null): mixed |
|
| 141 | + public function get(string | Autowire $id, string $context = null): mixed |
|
| 142 | 142 | { |
| 143 | 143 | /** @psalm-suppress TooManyArguments */ |
| 144 | 144 | return $this->container->get($id, $context); |
@@ -166,16 +166,16 @@ discard block |
||
| 166 | 166 | $binds = &$this->state->bindings; |
| 167 | 167 | $singletons = &$this->state->singletons; |
| 168 | 168 | $cleanup = $previous = $prevSin = []; |
| 169 | - foreach ($bindings as $alias => $resolver) { |
|
| 169 | + foreach ($bindings as $alias => $resolver){ |
|
| 170 | 170 | // Store previous bindings |
| 171 | - if (isset($binds[$alias])) { |
|
| 171 | + if (isset($binds[$alias])){ |
|
| 172 | 172 | $previous[$alias] = $binds[$alias]; |
| 173 | - } else { |
|
| 173 | + }else{ |
|
| 174 | 174 | // Store bindings to be removed |
| 175 | 175 | $cleanup[] = $alias; |
| 176 | 176 | } |
| 177 | 177 | // Store previous singletons |
| 178 | - if (isset($singletons[$alias])) { |
|
| 178 | + if (isset($singletons[$alias])){ |
|
| 179 | 179 | $prevSin[$alias] = $singletons[$alias]; |
| 180 | 180 | unset($singletons[$alias]); |
| 181 | 181 | } |
@@ -183,21 +183,21 @@ discard block |
||
| 183 | 183 | $this->binder->bind($alias, $resolver); |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - try { |
|
| 186 | + try{ |
|
| 187 | 187 | return ContainerScope::getContainer() !== $this |
| 188 | 188 | ? ContainerScope::runScope($this, $scope) |
| 189 | 189 | : $scope($this); |
| 190 | - } finally { |
|
| 190 | + }finally{ |
|
| 191 | 191 | // Remove new bindings |
| 192 | - foreach ($cleanup as $alias) { |
|
| 192 | + foreach ($cleanup as $alias){ |
|
| 193 | 193 | unset($binds[$alias], $singletons[$alias]); |
| 194 | 194 | } |
| 195 | 195 | // Restore previous bindings |
| 196 | - foreach ($previous as $alias => $resolver) { |
|
| 196 | + foreach ($previous as $alias => $resolver){ |
|
| 197 | 197 | $binds[$alias] = $resolver; |
| 198 | 198 | } |
| 199 | 199 | // Restore singletons |
| 200 | - foreach ($prevSin as $alias => $instance) { |
|
| 200 | + foreach ($prevSin as $alias => $instance){ |
|
| 201 | 201 | $singletons[$alias] = $instance; |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -211,32 +211,32 @@ discard block |
||
| 211 | 211 | // Open scope |
| 212 | 212 | $container = new self($this->config, $name); |
| 213 | 213 | |
| 214 | - try { |
|
| 214 | + try{ |
|
| 215 | 215 | // Configure scope |
| 216 | 216 | $container->scope->setParent($this, $this->scope); |
| 217 | 217 | |
| 218 | 218 | // Add specific bindings |
| 219 | - foreach ($bindings as $alias => $resolver) { |
|
| 219 | + foreach ($bindings as $alias => $resolver){ |
|
| 220 | 220 | $container->binder->bind($alias, $resolver); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return ContainerScope::runScope( |
| 224 | 224 | $container, |
| 225 | 225 | static function (self $container) use ($autowire, $closure): mixed { |
| 226 | - try { |
|
| 226 | + try{ |
|
| 227 | 227 | return $autowire |
| 228 | 228 | ? $container->invoke($closure) |
| 229 | 229 | : $closure($container); |
| 230 | - } finally { |
|
| 230 | + }finally{ |
|
| 231 | 231 | $container->closeScope(); |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | ); |
| 235 | - } finally { |
|
| 235 | + }finally{ |
|
| 236 | 236 | // Check the container has not been leaked |
| 237 | 237 | $link = \WeakReference::create($container); |
| 238 | 238 | unset($container); |
| 239 | - if ($link->get() !== null) { |
|
| 239 | + if ($link->get() !== null){ |
|
| 240 | 240 | throw new ScopeContainerLeakedException($name, $this->scope->getParentScopeNames()); |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @psalm-param TResolver $resolver |
| 270 | 270 | */ |
| 271 | - public function bindSingleton(string $alias, string|array|callable|object $resolver): void |
|
| 271 | + public function bindSingleton(string $alias, string | array | callable | object $resolver): void |
|
| 272 | 272 | { |
| 273 | 273 | $this->binder->bindSingleton($alias, $resolver); |
| 274 | 274 | } |
@@ -335,8 +335,8 @@ discard block |
||
| 335 | 335 | ]); |
| 336 | 336 | |
| 337 | 337 | // Create container services |
| 338 | - foreach ($container->config as $property => $class) { |
|
| 339 | - if (\property_exists($container, $property)) { |
|
| 338 | + foreach ($container->config as $property => $class){ |
|
| 339 | + if (\property_exists($container, $property)){ |
|
| 340 | 340 | $container->$property = $constructor->get($property, $class); |
| 341 | 341 | } |
| 342 | 342 | } |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | private function closeScope(): void |
| 351 | 351 | { |
| 352 | 352 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
| 353 | - if (!isset($this->scope)) { |
|
| 353 | + if (!isset($this->scope)){ |
|
| 354 | 354 | $this->destruct(); |
| 355 | 355 | return; |
| 356 | 356 | } |
@@ -359,10 +359,10 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | // Run finalizers |
| 361 | 361 | $errors = []; |
| 362 | - foreach ($this->state->finalizers as $finalizer) { |
|
| 363 | - try { |
|
| 362 | + foreach ($this->state->finalizers as $finalizer){ |
|
| 363 | + try{ |
|
| 364 | 364 | $this->invoker->invoke($finalizer); |
| 365 | - } catch (\Throwable $e) { |
|
| 365 | + }catch (\Throwable $e){ |
|
| 366 | 366 | $errors[] = $e; |
| 367 | 367 | } |
| 368 | 368 | } |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | $this->destruct(); |
| 372 | 372 | |
| 373 | 373 | // Throw collected errors |
| 374 | - if ($errors !== []) { |
|
| 374 | + if ($errors !== []){ |
|
| 375 | 375 | throw new FinalizersException($scopeName, $errors); |
| 376 | 376 | } |
| 377 | 377 | } |
@@ -13,18 +13,18 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | public const INJECTOR = EnumLocatorInjector::class; |
| 15 | 15 | |
| 16 | - public function getEnums(object|string|null $target = null): array |
|
| 16 | + public function getEnums(object | string | null $target = null): array |
|
| 17 | 17 | { |
| 18 | - if (!empty($target)) { |
|
| 18 | + if (!empty($target)){ |
|
| 19 | 19 | $target = new \ReflectionClass($target); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | $result = []; |
| 23 | - foreach ($this->availableEnums() as $enum) { |
|
| 24 | - try { |
|
| 23 | + foreach ($this->availableEnums() as $enum){ |
|
| 24 | + try{ |
|
| 25 | 25 | $reflection = $this->enumReflection($enum); |
| 26 | - } catch (LocatorException $e) { |
|
| 27 | - if ($this->debug) { |
|
| 26 | + }catch (LocatorException $e){ |
|
| 27 | + if ($this->debug){ |
|
| 28 | 28 | throw $e; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | continue; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
| 35 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
| 36 | 36 | continue; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $enums = []; |
| 53 | 53 | |
| 54 | - foreach ($this->availableReflections() as $reflection) { |
|
| 54 | + foreach ($this->availableReflections() as $reflection){ |
|
| 55 | 55 | $enums = \array_merge($enums, $reflection->getEnums()); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
| 67 | 67 | { |
| 68 | - if ($target === null) { |
|
| 68 | + if ($target === null){ |
|
| 69 | 69 | return true; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if (!$target->isTrait()) { |
|
| 72 | + if (!$target->isTrait()){ |
|
| 73 | 73 | //Target is interface or class |
| 74 | 74 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 75 | 75 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |
@@ -15,16 +15,22 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function getEnums(object|string|null $target = null): array |
| 17 | 17 | { |
| 18 | - if (!empty($target)) { |
|
| 18 | + if (!empty($target)) |
|
| 19 | + { |
|
| 19 | 20 | $target = new \ReflectionClass($target); |
| 20 | 21 | } |
| 21 | 22 | |
| 22 | 23 | $result = []; |
| 23 | - foreach ($this->availableEnums() as $enum) { |
|
| 24 | - try { |
|
| 24 | + foreach ($this->availableEnums() as $enum) |
|
| 25 | + { |
|
| 26 | + try |
|
| 27 | + { |
|
| 25 | 28 | $reflection = $this->enumReflection($enum); |
| 26 | - } catch (LocatorException $e) { |
|
| 27 | - if ($this->debug) { |
|
| 29 | + } |
|
| 30 | + catch (LocatorException $e) |
|
| 31 | + { |
|
| 32 | + if ($this->debug) |
|
| 33 | + { |
|
| 28 | 34 | throw $e; |
| 29 | 35 | } |
| 30 | 36 | |
@@ -32,7 +38,8 @@ discard block |
||
| 32 | 38 | continue; |
| 33 | 39 | } |
| 34 | 40 | |
| 35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
| 41 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
| 42 | + { |
|
| 36 | 43 | continue; |
| 37 | 44 | } |
| 38 | 45 | |
@@ -51,7 +58,8 @@ discard block |
||
| 51 | 58 | { |
| 52 | 59 | $enums = []; |
| 53 | 60 | |
| 54 | - foreach ($this->availableReflections() as $reflection) { |
|
| 61 | + foreach ($this->availableReflections() as $reflection) |
|
| 62 | + { |
|
| 55 | 63 | $enums = \array_merge($enums, $reflection->getEnums()); |
| 56 | 64 | } |
| 57 | 65 | |
@@ -65,11 +73,13 @@ discard block |
||
| 65 | 73 | */ |
| 66 | 74 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
| 67 | 75 | { |
| 68 | - if ($target === null) { |
|
| 76 | + if ($target === null) |
|
| 77 | + { |
|
| 69 | 78 | return true; |
| 70 | 79 | } |
| 71 | 80 | |
| 72 | - if (!$target->isTrait()) { |
|
| 81 | + if (!$target->isTrait()) |
|
| 82 | + { |
|
| 73 | 83 | //Target is interface or class |
| 74 | 84 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 75 | 85 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |