@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function render(?Reflector $reflector): string |
| 70 | 70 | { |
| 71 | - switch (true) { |
|
| 71 | + switch (true){ |
|
| 72 | 72 | case $reflector instanceof ReflectionClass: |
| 73 | 73 | return $this->renderClassContext($reflector); |
| 74 | 74 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function renderClassContext(ReflectionClass $class): string |
| 93 | 93 | { |
| 94 | - if ($class->isAnonymous()) { |
|
| 94 | + if ($class->isAnonymous()){ |
|
| 95 | 95 | return \sprintf(self::FORMAT_ANONYMOUS_CLASS, $class->getFileName(), $class->getStartLine()); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | public function renderFunctionContext(ReflectionFunction $fn): string |
| 109 | 109 | { |
| 110 | - if ($fn->isClosure()) { |
|
| 110 | + if ($fn->isClosure()){ |
|
| 111 | 111 | return \sprintf(self::FORMAT_ANONYMOUS_FUNCTION, $fn->getFileName(), $fn->getStartLine()); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | public function renderCallableContext(ReflectionFunctionAbstract $function): string |
| 118 | 118 | { |
| 119 | - if ($function instanceof ReflectionMethod) { |
|
| 119 | + if ($function instanceof ReflectionMethod){ |
|
| 120 | 120 | return $this->renderMethodContext($function); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if ($function instanceof ReflectionFunction) { |
|
| 123 | + if ($function instanceof ReflectionFunction){ |
|
| 124 | 124 | return $this->renderFunctionContext($function); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -68,7 +68,8 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function render(?Reflector $reflector): string |
| 70 | 70 | { |
| 71 | - switch (true) { |
|
| 71 | + switch (true) |
|
| 72 | + { |
|
| 72 | 73 | case $reflector instanceof ReflectionClass: |
| 73 | 74 | return $this->renderClassContext($reflector); |
| 74 | 75 | |
@@ -91,7 +92,8 @@ discard block |
||
| 91 | 92 | |
| 92 | 93 | public function renderClassContext(ReflectionClass $class): string |
| 93 | 94 | { |
| 94 | - if ($class->isAnonymous()) { |
|
| 95 | + if ($class->isAnonymous()) |
|
| 96 | + { |
|
| 95 | 97 | return \sprintf(self::FORMAT_ANONYMOUS_CLASS, $class->getFileName(), $class->getStartLine()); |
| 96 | 98 | } |
| 97 | 99 | |
@@ -107,7 +109,8 @@ discard block |
||
| 107 | 109 | |
| 108 | 110 | public function renderFunctionContext(ReflectionFunction $fn): string |
| 109 | 111 | { |
| 110 | - if ($fn->isClosure()) { |
|
| 112 | + if ($fn->isClosure()) |
|
| 113 | + { |
|
| 111 | 114 | return \sprintf(self::FORMAT_ANONYMOUS_FUNCTION, $fn->getFileName(), $fn->getStartLine()); |
| 112 | 115 | } |
| 113 | 116 | |
@@ -116,11 +119,13 @@ discard block |
||
| 116 | 119 | |
| 117 | 120 | public function renderCallableContext(ReflectionFunctionAbstract $function): string |
| 118 | 121 | { |
| 119 | - if ($function instanceof ReflectionMethod) { |
|
| 122 | + if ($function instanceof ReflectionMethod) |
|
| 123 | + { |
|
| 120 | 124 | return $this->renderMethodContext($function); |
| 121 | 125 | } |
| 122 | 126 | |
| 123 | - if ($function instanceof ReflectionFunction) { |
|
| 127 | + if ($function instanceof ReflectionFunction) |
|
| 128 | + { |
|
| 124 | 129 | return $this->renderFunctionContext($function); |
| 125 | 130 | } |
| 126 | 131 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function forClass(ReflectionClass $class): string |
| 35 | 35 | { |
| 36 | - if ($class->isUserDefined()) { |
|
| 36 | + if ($class->isUserDefined()){ |
|
| 37 | 37 | return (string)\filemtime( |
| 38 | 38 | $class->getFileName() |
| 39 | 39 | ); |
@@ -69,23 +69,23 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function forFunction(ReflectionFunctionAbstract $fn): string |
| 71 | 71 | { |
| 72 | - if ($fn instanceof ReflectionMethod) { |
|
| 72 | + if ($fn instanceof ReflectionMethod){ |
|
| 73 | 73 | return $this->forClass( |
| 74 | 74 | $fn->getDeclaringClass() |
| 75 | 75 | ); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ($fn->isUserDefined()) { |
|
| 78 | + if ($fn->isUserDefined()){ |
|
| 79 | 79 | return (string)\filemtime( |
| 80 | 80 | $fn->getFileName() |
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ($extension = $fn->getExtension()) { |
|
| 84 | + if ($extension = $fn->getExtension()){ |
|
| 85 | 85 | return $extension->getVersion(); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - throw new LogicException('Can not determine modification time of [' . $fn->getName() . ']'); |
|
| 88 | + throw new LogicException('Can not determine modification time of ['.$fn->getName().']'); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -33,7 +33,8 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function forClass(ReflectionClass $class): string |
| 35 | 35 | { |
| 36 | - if ($class->isUserDefined()) { |
|
| 36 | + if ($class->isUserDefined()) |
|
| 37 | + { |
|
| 37 | 38 | return (string)\filemtime( |
| 38 | 39 | $class->getFileName() |
| 39 | 40 | ); |
@@ -69,19 +70,22 @@ discard block |
||
| 69 | 70 | */ |
| 70 | 71 | public function forFunction(ReflectionFunctionAbstract $fn): string |
| 71 | 72 | { |
| 72 | - if ($fn instanceof ReflectionMethod) { |
|
| 73 | + if ($fn instanceof ReflectionMethod) |
|
| 74 | + { |
|
| 73 | 75 | return $this->forClass( |
| 74 | 76 | $fn->getDeclaringClass() |
| 75 | 77 | ); |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | - if ($fn->isUserDefined()) { |
|
| 80 | + if ($fn->isUserDefined()) |
|
| 81 | + { |
|
| 79 | 82 | return (string)\filemtime( |
| 80 | 83 | $fn->getFileName() |
| 81 | 84 | ); |
| 82 | 85 | } |
| 83 | 86 | |
| 84 | - if ($extension = $fn->getExtension()) { |
|
| 87 | + if ($extension = $fn->getExtension()) |
|
| 88 | + { |
|
| 85 | 89 | return $extension->getVersion(); |
| 86 | 90 | } |
| 87 | 91 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function forClass(ReflectionClass $class): string |
| 64 | 64 | { |
| 65 | - if ($class->isAnonymous()) { |
|
| 65 | + if ($class->isAnonymous()){ |
|
| 66 | 66 | return \vsprintf(self::TPL_ANONYMOUS_CLASS, [ |
| 67 | 67 | $class->getFileName(), |
| 68 | 68 | $class->getStartLine(), |
@@ -111,14 +111,14 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function forFunction(ReflectionFunctionAbstract $fn): string |
| 113 | 113 | { |
| 114 | - if ($fn instanceof ReflectionMethod) { |
|
| 114 | + if ($fn instanceof ReflectionMethod){ |
|
| 115 | 115 | return \vsprintf(self::TPL_METHOD, [ |
| 116 | 116 | $this->forClass($fn->getDeclaringClass()), |
| 117 | 117 | $fn->getName(), |
| 118 | 118 | ]); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ($fn->isClosure()) { |
|
| 121 | + if ($fn->isClosure()){ |
|
| 122 | 122 | return \vsprintf(self::TPL_ANONYMOUS_FN, [ |
| 123 | 123 | $fn->getFileName(), |
| 124 | 124 | $fn->getStartLine(), |
@@ -62,7 +62,8 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function forClass(ReflectionClass $class): string |
| 64 | 64 | { |
| 65 | - if ($class->isAnonymous()) { |
|
| 65 | + if ($class->isAnonymous()) |
|
| 66 | + { |
|
| 66 | 67 | return \vsprintf(self::TPL_ANONYMOUS_CLASS, [ |
| 67 | 68 | $class->getFileName(), |
| 68 | 69 | $class->getStartLine(), |
@@ -111,14 +112,16 @@ discard block |
||
| 111 | 112 | */ |
| 112 | 113 | public function forFunction(ReflectionFunctionAbstract $fn): string |
| 113 | 114 | { |
| 114 | - if ($fn instanceof ReflectionMethod) { |
|
| 115 | + if ($fn instanceof ReflectionMethod) |
|
| 116 | + { |
|
| 115 | 117 | return \vsprintf(self::TPL_METHOD, [ |
| 116 | 118 | $this->forClass($fn->getDeclaringClass()), |
| 117 | 119 | $fn->getName(), |
| 118 | 120 | ]); |
| 119 | 121 | } |
| 120 | 122 | |
| 121 | - if ($fn->isClosure()) { |
|
| 123 | + if ($fn->isClosure()) |
|
| 124 | + { |
|
| 122 | 125 | return \vsprintf(self::TPL_ANONYMOUS_FN, [ |
| 123 | 126 | $fn->getFileName(), |
| 124 | 127 | $fn->getStartLine(), |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | 36 | private const ERROR_INVALID_PROPERTY = |
| 37 | - 'The attribute #[%s] declared on %s does not have a property named "%s".' . "\n" . |
|
| 37 | + 'The attribute #[%s] declared on %s does not have a property named "%s".'."\n". |
|
| 38 | 38 | 'Available properties: %s' |
| 39 | 39 | ; |
| 40 | 40 | |
@@ -61,23 +61,23 @@ discard block |
||
| 61 | 61 | $arguments = $this->formatArguments($arguments); |
| 62 | 62 | |
| 63 | 63 | // Using constructor |
| 64 | - if ($this->getConstructor($attr)) { |
|
| 64 | + if ($this->getConstructor($attr)){ |
|
| 65 | 65 | return $attr->newInstance($arguments); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Using direct insert |
| 69 | 69 | $instance = $attr->newInstanceWithoutConstructor(); |
| 70 | 70 | |
| 71 | - foreach ($arguments as $name => $value) { |
|
| 72 | - try { |
|
| 71 | + foreach ($arguments as $name => $value){ |
|
| 72 | + try{ |
|
| 73 | 73 | $property = $attr->getProperty($name); |
| 74 | 74 | |
| 75 | - if (!$property->isPublic()) { |
|
| 75 | + if (!$property->isPublic()){ |
|
| 76 | 76 | throw $this->propertyNotFound($attr, $name, $context); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $instance->$name = $value; |
| 80 | - } catch (Throwable $e) { |
|
| 80 | + }catch (Throwable $e){ |
|
| 81 | 81 | throw $this->propertyNotFound($attr, $name, $context); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | $result = []; |
| 91 | 91 | |
| 92 | - foreach ($arguments as $name => $value) { |
|
| 93 | - if (\is_int($name)) { |
|
| 92 | + foreach ($arguments as $name => $value){ |
|
| 93 | + if (\is_int($name)){ |
|
| 94 | 94 | $this->validateArgumentPosition($name, $value); |
| 95 | 95 | |
| 96 | 96 | $name = self::DEFAULT_PROPERTY_NAME; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | private function validateArgumentPosition(int $index, $value): void |
| 109 | 109 | { |
| 110 | - if ($index === 0) { |
|
| 110 | + if ($index === 0){ |
|
| 111 | 111 | return; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -61,23 +61,29 @@ discard block |
||
| 61 | 61 | $arguments = $this->formatArguments($arguments); |
| 62 | 62 | |
| 63 | 63 | // Using constructor |
| 64 | - if ($this->getConstructor($attr)) { |
|
| 64 | + if ($this->getConstructor($attr)) |
|
| 65 | + { |
|
| 65 | 66 | return $attr->newInstance($arguments); |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | // Using direct insert |
| 69 | 70 | $instance = $attr->newInstanceWithoutConstructor(); |
| 70 | 71 | |
| 71 | - foreach ($arguments as $name => $value) { |
|
| 72 | - try { |
|
| 72 | + foreach ($arguments as $name => $value) |
|
| 73 | + { |
|
| 74 | + try |
|
| 75 | + { |
|
| 73 | 76 | $property = $attr->getProperty($name); |
| 74 | 77 | |
| 75 | - if (!$property->isPublic()) { |
|
| 78 | + if (!$property->isPublic()) |
|
| 79 | + { |
|
| 76 | 80 | throw $this->propertyNotFound($attr, $name, $context); |
| 77 | 81 | } |
| 78 | 82 | |
| 79 | 83 | $instance->$name = $value; |
| 80 | - } catch (Throwable $e) { |
|
| 84 | + } |
|
| 85 | + catch (Throwable $e) |
|
| 86 | + { |
|
| 81 | 87 | throw $this->propertyNotFound($attr, $name, $context); |
| 82 | 88 | } |
| 83 | 89 | } |
@@ -89,8 +95,10 @@ discard block |
||
| 89 | 95 | { |
| 90 | 96 | $result = []; |
| 91 | 97 | |
| 92 | - foreach ($arguments as $name => $value) { |
|
| 93 | - if (\is_int($name)) { |
|
| 98 | + foreach ($arguments as $name => $value) |
|
| 99 | + { |
|
| 100 | + if (\is_int($name)) |
|
| 101 | + { |
|
| 94 | 102 | $this->validateArgumentPosition($name, $value); |
| 95 | 103 | |
| 96 | 104 | $name = self::DEFAULT_PROPERTY_NAME; |
@@ -107,7 +115,8 @@ discard block |
||
| 107 | 115 | */ |
| 108 | 116 | private function validateArgumentPosition(int $index, $value): void |
| 109 | 117 | { |
| 110 | - if ($index === 0) { |
|
| 118 | + if ($index === 0) |
|
| 119 | + { |
|
| 111 | 120 | return; |
| 112 | 121 | } |
| 113 | 122 | |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | protected function getConstructor(ReflectionClass $class): ?ReflectionMethod |
| 39 | 39 | { |
| 40 | - if ($class->hasMethod(self::CONSTRUCTOR_NAME)) { |
|
| 40 | + if ($class->hasMethod(self::CONSTRUCTOR_NAME)){ |
|
| 41 | 41 | return $class->getMethod(self::CONSTRUCTOR_NAME); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ($constructor = $this->getTraitConstructors($class)) { |
|
| 44 | + if ($constructor = $this->getTraitConstructors($class)){ |
|
| 45 | 45 | return $constructor; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if ($parent = $class->getParentClass()) { |
|
| 48 | + if ($parent = $class->getParentClass()){ |
|
| 49 | 49 | return $this->getConstructor($parent); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | private function getTraitConstructors(ReflectionClass $class): ?ReflectionMethod |
| 56 | 56 | { |
| 57 | - foreach ($class->getTraits() as $trait) { |
|
| 58 | - if ($constructor = $this->getConstructor($trait)) { |
|
| 57 | + foreach ($class->getTraits() as $trait){ |
|
| 58 | + if ($constructor = $this->getConstructor($trait)){ |
|
| 59 | 59 | return $constructor; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ($constructor = $this->getTraitConstructors($trait)) { |
|
| 62 | + if ($constructor = $this->getTraitConstructors($trait)){ |
|
| 63 | 63 | return $constructor; |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -37,15 +37,18 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | protected function getConstructor(ReflectionClass $class): ?ReflectionMethod |
| 39 | 39 | { |
| 40 | - if ($class->hasMethod(self::CONSTRUCTOR_NAME)) { |
|
| 40 | + if ($class->hasMethod(self::CONSTRUCTOR_NAME)) |
|
| 41 | + { |
|
| 41 | 42 | return $class->getMethod(self::CONSTRUCTOR_NAME); |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | - if ($constructor = $this->getTraitConstructors($class)) { |
|
| 45 | + if ($constructor = $this->getTraitConstructors($class)) |
|
| 46 | + { |
|
| 45 | 47 | return $constructor; |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - if ($parent = $class->getParentClass()) { |
|
| 50 | + if ($parent = $class->getParentClass()) |
|
| 51 | + { |
|
| 49 | 52 | return $this->getConstructor($parent); |
| 50 | 53 | } |
| 51 | 54 | |
@@ -54,12 +57,15 @@ discard block |
||
| 54 | 57 | |
| 55 | 58 | private function getTraitConstructors(ReflectionClass $class): ?ReflectionMethod |
| 56 | 59 | { |
| 57 | - foreach ($class->getTraits() as $trait) { |
|
| 58 | - if ($constructor = $this->getConstructor($trait)) { |
|
| 60 | + foreach ($class->getTraits() as $trait) |
|
| 61 | + { |
|
| 62 | + if ($constructor = $this->getConstructor($trait)) |
|
| 63 | + { |
|
| 59 | 64 | return $constructor; |
| 60 | 65 | } |
| 61 | 66 | |
| 62 | - if ($constructor = $this->getTraitConstructors($trait)) { |
|
| 67 | + if ($constructor = $this->getTraitConstructors($trait)) |
|
| 68 | + { |
|
| 63 | 69 | return $constructor; |
| 64 | 70 | } |
| 65 | 71 | } |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function instantiate(ReflectionClass $attr, array $arguments, Reflector $context = null): object |
| 43 | 43 | { |
| 44 | - if ($this->isNamedArgumentsSupported()) { |
|
| 45 | - try { |
|
| 44 | + if ($this->isNamedArgumentsSupported()){ |
|
| 45 | + try{ |
|
| 46 | 46 | return $attr->newInstanceArgs($arguments); |
| 47 | - } catch (Throwable $e) { |
|
| 47 | + }catch (Throwable $e){ |
|
| 48 | 48 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $constructor = $this->getConstructor($attr); |
| 53 | 53 | |
| 54 | - if ($constructor === null) { |
|
| 54 | + if ($constructor === null){ |
|
| 55 | 55 | return $attr->newInstanceWithoutConstructor(); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -72,16 +72,16 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $passed = []; |
| 74 | 74 | |
| 75 | - try { |
|
| 76 | - foreach ($constructor->getParameters() as $parameter) { |
|
| 75 | + try{ |
|
| 76 | + foreach ($constructor->getParameters() as $parameter){ |
|
| 77 | 77 | $passed[] = $this->resolveParameter($ctx, $parameter, $arguments); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if (\count($arguments)) { |
|
| 80 | + if (\count($arguments)){ |
|
| 81 | 81 | $message = \sprintf(self::ERROR_UNKNOWN_ARGUMENT, \array_key_first($arguments)); |
| 82 | 82 | throw new BadMethodCallException($message); |
| 83 | 83 | } |
| 84 | - } catch (Throwable $e) { |
|
| 84 | + }catch (Throwable $e){ |
|
| 85 | 85 | throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine()); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -94,19 +94,19 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | private function resolveParameter(ReflectionClass $ctx, ReflectionParameter $param, array &$arguments) |
| 96 | 96 | { |
| 97 | - switch (true) { |
|
| 97 | + switch (true){ |
|
| 98 | 98 | case \array_key_exists($param->getName(), $arguments): |
| 99 | - try { |
|
| 99 | + try{ |
|
| 100 | 100 | return $arguments[$param->getName()]; |
| 101 | - } finally { |
|
| 101 | + }finally{ |
|
| 102 | 102 | unset($arguments[$param->getName()]); |
| 103 | 103 | } |
| 104 | 104 | // no actual falling through |
| 105 | 105 | |
| 106 | 106 | case \array_key_exists($param->getPosition(), $arguments): |
| 107 | - try { |
|
| 107 | + try{ |
|
| 108 | 108 | return $arguments[$param->getPosition()]; |
| 109 | - } finally { |
|
| 109 | + }finally{ |
|
| 110 | 110 | unset($arguments[$param->getPosition()]); |
| 111 | 111 | } |
| 112 | 112 | // no actual falling through |
@@ -41,17 +41,22 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function instantiate(ReflectionClass $attr, array $arguments, Reflector $context = null): object |
| 43 | 43 | { |
| 44 | - if ($this->isNamedArgumentsSupported()) { |
|
| 45 | - try { |
|
| 44 | + if ($this->isNamedArgumentsSupported()) |
|
| 45 | + { |
|
| 46 | + try |
|
| 47 | + { |
|
| 46 | 48 | return $attr->newInstanceArgs($arguments); |
| 47 | - } catch (Throwable $e) { |
|
| 49 | + } |
|
| 50 | + catch (Throwable $e) |
|
| 51 | + { |
|
| 48 | 52 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
| 49 | 53 | } |
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | $constructor = $this->getConstructor($attr); |
| 53 | 57 | |
| 54 | - if ($constructor === null) { |
|
| 58 | + if ($constructor === null) |
|
| 59 | + { |
|
| 55 | 60 | return $attr->newInstanceWithoutConstructor(); |
| 56 | 61 | } |
| 57 | 62 | |
@@ -72,16 +77,21 @@ discard block |
||
| 72 | 77 | { |
| 73 | 78 | $passed = []; |
| 74 | 79 | |
| 75 | - try { |
|
| 76 | - foreach ($constructor->getParameters() as $parameter) { |
|
| 80 | + try |
|
| 81 | + { |
|
| 82 | + foreach ($constructor->getParameters() as $parameter) |
|
| 83 | + { |
|
| 77 | 84 | $passed[] = $this->resolveParameter($ctx, $parameter, $arguments); |
| 78 | 85 | } |
| 79 | 86 | |
| 80 | - if (\count($arguments)) { |
|
| 87 | + if (\count($arguments)) |
|
| 88 | + { |
|
| 81 | 89 | $message = \sprintf(self::ERROR_UNKNOWN_ARGUMENT, \array_key_first($arguments)); |
| 82 | 90 | throw new BadMethodCallException($message); |
| 83 | 91 | } |
| 84 | - } catch (Throwable $e) { |
|
| 92 | + } |
|
| 93 | + catch (Throwable $e) |
|
| 94 | + { |
|
| 85 | 95 | throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine()); |
| 86 | 96 | } |
| 87 | 97 | |
@@ -94,19 +104,26 @@ discard block |
||
| 94 | 104 | */ |
| 95 | 105 | private function resolveParameter(ReflectionClass $ctx, ReflectionParameter $param, array &$arguments) |
| 96 | 106 | { |
| 97 | - switch (true) { |
|
| 107 | + switch (true) |
|
| 108 | + { |
|
| 98 | 109 | case \array_key_exists($param->getName(), $arguments): |
| 99 | - try { |
|
| 110 | + try |
|
| 111 | + { |
|
| 100 | 112 | return $arguments[$param->getName()]; |
| 101 | - } finally { |
|
| 113 | + } |
|
| 114 | + finally |
|
| 115 | + { |
|
| 102 | 116 | unset($arguments[$param->getName()]); |
| 103 | 117 | } |
| 104 | 118 | // no actual falling through |
| 105 | 119 | |
| 106 | 120 | case \array_key_exists($param->getPosition(), $arguments): |
| 107 | - try { |
|
| 121 | + try |
|
| 122 | + { |
|
| 108 | 123 | return $arguments[$param->getPosition()]; |
| 109 | - } finally { |
|
| 124 | + } |
|
| 125 | + finally |
|
| 126 | + { |
|
| 110 | 127 | unset($arguments[$param->getPosition()]); |
| 111 | 128 | } |
| 112 | 129 | // no actual falling through |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | public function instantiate(ReflectionClass $attr, array $arguments, Reflector $context = null): object |
| 44 | 44 | { |
| 45 | - if ($this->isNamedArguments($attr)) { |
|
| 45 | + if ($this->isNamedArguments($attr)){ |
|
| 46 | 46 | return $this->named->instantiate($attr, $arguments, $context); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -42,7 +42,8 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | public function instantiate(ReflectionClass $attr, array $arguments, Reflector $context = null): object |
| 44 | 44 | { |
| 45 | - if ($this->isNamedArguments($attr)) { |
|
| 45 | + if ($this->isNamedArguments($attr)) |
|
| 46 | + { |
|
| 46 | 47 | return $this->named->instantiate($attr, $arguments, $context); |
| 47 | 48 | } |
| 48 | 49 | |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $attributes = $this->getClassAttributes($class, $name); |
| 54 | 54 | |
| 55 | - foreach ($attributes as $attribute => $arguments) { |
|
| 55 | + foreach ($attributes as $attribute => $arguments){ |
|
| 56 | 56 | yield $this->instantiator->instantiate($attribute, $arguments, $class); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - foreach ($class->getTraits() as $trait) { |
|
| 59 | + foreach ($class->getTraits() as $trait){ |
|
| 60 | 60 | yield from $this->getClassMetadata($trait, $name); |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $attributes = $this->getFunctionAttributes($function, $name); |
| 71 | 71 | |
| 72 | - foreach ($attributes as $attribute => $arguments) { |
|
| 72 | + foreach ($attributes as $attribute => $arguments){ |
|
| 73 | 73 | yield $this->instantiator->instantiate($attribute, $arguments, $function); |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | { |
| 83 | 83 | $attributes = $this->getPropertyAttributes($property, $name); |
| 84 | 84 | |
| 85 | - foreach ($attributes as $attribute => $arguments) { |
|
| 85 | + foreach ($attributes as $attribute => $arguments){ |
|
| 86 | 86 | yield $this->instantiator->instantiate($attribute, $arguments, $property); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | $attributes = $this->getConstantAttributes($constant, $name); |
| 97 | 97 | |
| 98 | - foreach ($attributes as $attribute => $arguments) { |
|
| 98 | + foreach ($attributes as $attribute => $arguments){ |
|
| 99 | 99 | yield $this->instantiator->instantiate($attribute, $arguments, $constant); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $attributes = $this->getParameterAttributes($parameter, $name); |
| 110 | 110 | |
| 111 | - foreach ($attributes as $attribute => $arguments) { |
|
| 111 | + foreach ($attributes as $attribute => $arguments){ |
|
| 112 | 112 | yield $this->instantiator->instantiate($attribute, $arguments, $parameter); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | protected function assertClassExists(string $class, Reflector $context): void |
| 117 | 117 | { |
| 118 | - if (!\class_exists($class)) { |
|
| 118 | + if (!\class_exists($class)){ |
|
| 119 | 119 | $message = \vsprintf('The metadata class "%s" in %s was not found', [ |
| 120 | 120 | $class, |
| 121 | 121 | $this->renderer->render($context), |
@@ -52,11 +52,13 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $attributes = $this->getClassAttributes($class, $name); |
| 54 | 54 | |
| 55 | - foreach ($attributes as $attribute => $arguments) { |
|
| 55 | + foreach ($attributes as $attribute => $arguments) |
|
| 56 | + { |
|
| 56 | 57 | yield $this->instantiator->instantiate($attribute, $arguments, $class); |
| 57 | 58 | } |
| 58 | 59 | |
| 59 | - foreach ($class->getTraits() as $trait) { |
|
| 60 | + foreach ($class->getTraits() as $trait) |
|
| 61 | + { |
|
| 60 | 62 | yield from $this->getClassMetadata($trait, $name); |
| 61 | 63 | } |
| 62 | 64 | } |
@@ -69,7 +71,8 @@ discard block |
||
| 69 | 71 | { |
| 70 | 72 | $attributes = $this->getFunctionAttributes($function, $name); |
| 71 | 73 | |
| 72 | - foreach ($attributes as $attribute => $arguments) { |
|
| 74 | + foreach ($attributes as $attribute => $arguments) |
|
| 75 | + { |
|
| 73 | 76 | yield $this->instantiator->instantiate($attribute, $arguments, $function); |
| 74 | 77 | } |
| 75 | 78 | } |
@@ -82,7 +85,8 @@ discard block |
||
| 82 | 85 | { |
| 83 | 86 | $attributes = $this->getPropertyAttributes($property, $name); |
| 84 | 87 | |
| 85 | - foreach ($attributes as $attribute => $arguments) { |
|
| 88 | + foreach ($attributes as $attribute => $arguments) |
|
| 89 | + { |
|
| 86 | 90 | yield $this->instantiator->instantiate($attribute, $arguments, $property); |
| 87 | 91 | } |
| 88 | 92 | } |
@@ -95,7 +99,8 @@ discard block |
||
| 95 | 99 | { |
| 96 | 100 | $attributes = $this->getConstantAttributes($constant, $name); |
| 97 | 101 | |
| 98 | - foreach ($attributes as $attribute => $arguments) { |
|
| 102 | + foreach ($attributes as $attribute => $arguments) |
|
| 103 | + { |
|
| 99 | 104 | yield $this->instantiator->instantiate($attribute, $arguments, $constant); |
| 100 | 105 | } |
| 101 | 106 | } |
@@ -108,14 +113,16 @@ discard block |
||
| 108 | 113 | { |
| 109 | 114 | $attributes = $this->getParameterAttributes($parameter, $name); |
| 110 | 115 | |
| 111 | - foreach ($attributes as $attribute => $arguments) { |
|
| 116 | + foreach ($attributes as $attribute => $arguments) |
|
| 117 | + { |
|
| 112 | 118 | yield $this->instantiator->instantiate($attribute, $arguments, $parameter); |
| 113 | 119 | } |
| 114 | 120 | } |
| 115 | 121 | |
| 116 | 122 | protected function assertClassExists(string $class, Reflector $context): void |
| 117 | 123 | { |
| 118 | - if (!\class_exists($class)) { |
|
| 124 | + if (!\class_exists($class)) |
|
| 125 | + { |
|
| 119 | 126 | $message = \vsprintf('The metadata class "%s" in %s was not found', [ |
| 120 | 127 | $class, |
| 121 | 128 | $this->renderer->render($context), |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | // 1) Can not parse internal classes |
| 101 | 101 | // 2) Anonymous classes don't support attributes (PHP semantic) |
| 102 | - if ($class->isInternal() || $class->isAnonymous()) { |
|
| 102 | + if ($class->isInternal() || $class->isAnonymous()){ |
|
| 103 | 103 | return []; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | protected function getFunctionAttributes(ReflectionFunctionAbstract $function, ?string $name): iterable |
| 115 | 115 | { |
| 116 | 116 | // Can not parse internal functions |
| 117 | - if ($function->isInternal()) { |
|
| 117 | + if ($function->isInternal()){ |
|
| 118 | 118 | return []; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $class = $property->getDeclaringClass(); |
| 133 | 133 | |
| 134 | 134 | // Can not parse property of internal class |
| 135 | - if ($class->isInternal()) { |
|
| 135 | + if ($class->isInternal()){ |
|
| 136 | 136 | return []; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $class = $const->getDeclaringClass(); |
| 150 | 150 | |
| 151 | 151 | // Can not parse internal classes |
| 152 | - if ($class->isInternal()) { |
|
| 152 | + if ($class->isInternal()){ |
|
| 153 | 153 | return []; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $function = $param->getDeclaringFunction(); |
| 167 | 167 | |
| 168 | 168 | // Can not parse parameter of internal function |
| 169 | - if ($function->isInternal()) { |
|
| 169 | + if ($function->isInternal()){ |
|
| 170 | 170 | return []; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | private function parseAttributes(string $file, int $context): array |
| 185 | 185 | { |
| 186 | - if (!isset($this->attributes[$file])) { |
|
| 186 | + if (!isset($this->attributes[$file])){ |
|
| 187 | 187 | $found = $this->parser->parse($file); |
| 188 | 188 | |
| 189 | 189 | $this->attributes[$file] = [ |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | private function format(iterable $attributes, ?string $name, Reflector $context): iterable |
| 207 | 207 | { |
| 208 | - foreach ($attributes as $prototype) { |
|
| 209 | - if ($prototype->name !== $name && $name !== null && !\is_subclass_of($prototype->name, $name)) { |
|
| 208 | + foreach ($attributes as $prototype){ |
|
| 209 | + if ($prototype->name !== $name && $name !== null && !\is_subclass_of($prototype->name, $name)){ |
|
| 210 | 210 | continue; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | $line = $function->getEndLine(); |
| 243 | 243 | |
| 244 | - if ($result = $attributes[$line] ?? null) { |
|
| 244 | + if ($result = $attributes[$line] ?? null){ |
|
| 245 | 245 | return $result; |
| 246 | 246 | } |
| 247 | 247 | |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | * $ast->getEndLine(); // 2 (last significant character of a function) |
| 267 | 267 | * </code> |
| 268 | 268 | */ |
| 269 | - if ($function->isClosure()) { |
|
| 270 | - while ($line-- > $function->getStartLine()) { |
|
| 271 | - if ($result = $attributes[$line] ?? null) { |
|
| 269 | + if ($function->isClosure()){ |
|
| 270 | + while ($line-- > $function->getStartLine()){ |
|
| 271 | + if ($result = $attributes[$line] ?? null){ |
|
| 272 | 272 | return $result; |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -99,7 +99,8 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | // 1) Can not parse internal classes |
| 101 | 101 | // 2) Anonymous classes don't support attributes (PHP semantic) |
| 102 | - if ($class->isInternal() || $class->isAnonymous()) { |
|
| 102 | + if ($class->isInternal() || $class->isAnonymous()) |
|
| 103 | + { |
|
| 103 | 104 | return []; |
| 104 | 105 | } |
| 105 | 106 | |
@@ -114,7 +115,8 @@ discard block |
||
| 114 | 115 | protected function getFunctionAttributes(ReflectionFunctionAbstract $function, ?string $name): iterable |
| 115 | 116 | { |
| 116 | 117 | // Can not parse internal functions |
| 117 | - if ($function->isInternal()) { |
|
| 118 | + if ($function->isInternal()) |
|
| 119 | + { |
|
| 118 | 120 | return []; |
| 119 | 121 | } |
| 120 | 122 | |
@@ -132,7 +134,8 @@ discard block |
||
| 132 | 134 | $class = $property->getDeclaringClass(); |
| 133 | 135 | |
| 134 | 136 | // Can not parse property of internal class |
| 135 | - if ($class->isInternal()) { |
|
| 137 | + if ($class->isInternal()) |
|
| 138 | + { |
|
| 136 | 139 | return []; |
| 137 | 140 | } |
| 138 | 141 | |
@@ -149,7 +152,8 @@ discard block |
||
| 149 | 152 | $class = $const->getDeclaringClass(); |
| 150 | 153 | |
| 151 | 154 | // Can not parse internal classes |
| 152 | - if ($class->isInternal()) { |
|
| 155 | + if ($class->isInternal()) |
|
| 156 | + { |
|
| 153 | 157 | return []; |
| 154 | 158 | } |
| 155 | 159 | |
@@ -166,7 +170,8 @@ discard block |
||
| 166 | 170 | $function = $param->getDeclaringFunction(); |
| 167 | 171 | |
| 168 | 172 | // Can not parse parameter of internal function |
| 169 | - if ($function->isInternal()) { |
|
| 173 | + if ($function->isInternal()) |
|
| 174 | + { |
|
| 170 | 175 | return []; |
| 171 | 176 | } |
| 172 | 177 | |
@@ -183,7 +188,8 @@ discard block |
||
| 183 | 188 | */ |
| 184 | 189 | private function parseAttributes(string $file, int $context): array |
| 185 | 190 | { |
| 186 | - if (!isset($this->attributes[$file])) { |
|
| 191 | + if (!isset($this->attributes[$file])) |
|
| 192 | + { |
|
| 187 | 193 | $found = $this->parser->parse($file); |
| 188 | 194 | |
| 189 | 195 | $this->attributes[$file] = [ |
@@ -205,8 +211,10 @@ discard block |
||
| 205 | 211 | */ |
| 206 | 212 | private function format(iterable $attributes, ?string $name, Reflector $context): iterable |
| 207 | 213 | { |
| 208 | - foreach ($attributes as $prototype) { |
|
| 209 | - if ($prototype->name !== $name && $name !== null && !\is_subclass_of($prototype->name, $name)) { |
|
| 214 | + foreach ($attributes as $prototype) |
|
| 215 | + { |
|
| 216 | + if ($prototype->name !== $name && $name !== null && !\is_subclass_of($prototype->name, $name)) |
|
| 217 | + { |
|
| 210 | 218 | continue; |
| 211 | 219 | } |
| 212 | 220 | |
@@ -241,7 +249,8 @@ discard block |
||
| 241 | 249 | */ |
| 242 | 250 | $line = $function->getEndLine(); |
| 243 | 251 | |
| 244 | - if ($result = $attributes[$line] ?? null) { |
|
| 252 | + if ($result = $attributes[$line] ?? null) |
|
| 253 | + { |
|
| 245 | 254 | return $result; |
| 246 | 255 | } |
| 247 | 256 | |
@@ -266,9 +275,12 @@ discard block |
||
| 266 | 275 | * $ast->getEndLine(); // 2 (last significant character of a function) |
| 267 | 276 | * </code> |
| 268 | 277 | */ |
| 269 | - if ($function->isClosure()) { |
|
| 270 | - while ($line-- > $function->getStartLine()) { |
|
| 271 | - if ($result = $attributes[$line] ?? null) { |
|
| 278 | + if ($function->isClosure()) |
|
| 279 | + { |
|
| 280 | + while ($line-- > $function->getStartLine()) |
|
| 281 | + { |
|
| 282 | + if ($result = $attributes[$line] ?? null) |
|
| 283 | + { |
|
| 272 | 284 | return $result; |
| 273 | 285 | } |
| 274 | 286 | } |