@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | ReaderInterface $reader, |
33 | 33 | CacheItemPoolInterface $cache, |
34 | 34 | KeyGeneratorInterface $generator = null |
35 | - ) { |
|
35 | + ){ |
|
36 | 36 | $this->cache = $cache; |
37 | 37 | |
38 | 38 | parent::__construct($reader, $generator); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $item = $this->cache->getItem($key); |
48 | 48 | |
49 | - if (!$item->isHit()) { |
|
49 | + if (!$item->isHit()){ |
|
50 | 50 | $this->cache->save( |
51 | 51 | $item->set($then()) |
52 | 52 | ); |
@@ -46,7 +46,8 @@ |
||
46 | 46 | { |
47 | 47 | $item = $this->cache->getItem($key); |
48 | 48 | |
49 | - if (!$item->isHit()) { |
|
49 | + if (!$item->isHit()) |
|
50 | + { |
|
50 | 51 | $this->cache->save( |
51 | 52 | $item->set($then()) |
52 | 53 | ); |
@@ -41,7 +41,7 @@ |
||
41 | 41 | */ |
42 | 42 | protected function cached(string $key, callable $then): iterable |
43 | 43 | { |
44 | - if (!$this->cache->has($key)) { |
|
44 | + if (!$this->cache->has($key)){ |
|
45 | 45 | $this->cache->set($key, $then()); |
46 | 46 | } |
47 | 47 |
@@ -41,7 +41,8 @@ |
||
41 | 41 | */ |
42 | 42 | protected function cached(string $key, callable $then): iterable |
43 | 43 | { |
44 | - if (!$this->cache->has($key)) { |
|
44 | + if (!$this->cache->has($key)) |
|
45 | + { |
|
45 | 46 | $this->cache->set($key, $then()); |
46 | 47 | } |
47 | 48 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function firstClassMetadata(\ReflectionClass $class, string $name): ?object |
20 | 20 | { |
21 | - foreach ($this->getClassMetadata($class, $name) as $attribute) { |
|
21 | + foreach ($this->getClassMetadata($class, $name) as $attribute){ |
|
22 | 22 | return $attribute; |
23 | 23 | } |
24 | 24 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function firstFunctionMetadata(\ReflectionFunctionAbstract $function, string $name): ?object |
32 | 32 | { |
33 | - foreach ($this->getFunctionMetadata($function, $name) as $attribute) { |
|
33 | + foreach ($this->getFunctionMetadata($function, $name) as $attribute){ |
|
34 | 34 | return $attribute; |
35 | 35 | } |
36 | 36 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function firstPropertyMetadata(\ReflectionProperty $property, string $name): ?object |
44 | 44 | { |
45 | - foreach ($this->getPropertyMetadata($property, $name) as $attribute) { |
|
45 | + foreach ($this->getPropertyMetadata($property, $name) as $attribute){ |
|
46 | 46 | return $attribute; |
47 | 47 | } |
48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function firstConstantMetadata(\ReflectionClassConstant $constant, string $name): ?object |
56 | 56 | { |
57 | - foreach ($this->getConstantMetadata($constant, $name) as $attribute) { |
|
57 | + foreach ($this->getConstantMetadata($constant, $name) as $attribute){ |
|
58 | 58 | return $attribute; |
59 | 59 | } |
60 | 60 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function firstParameterMetadata(\ReflectionParameter $parameter, string $name): ?object |
68 | 68 | { |
69 | - foreach ($this->getParameterMetadata($parameter, $name) as $attribute) { |
|
69 | + foreach ($this->getParameterMetadata($parameter, $name) as $attribute){ |
|
70 | 70 | return $attribute; |
71 | 71 | } |
72 | 72 | |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function filter(?string $name, iterable $annotations): iterable |
83 | 83 | { |
84 | - if ($name === null) { |
|
84 | + if ($name === null){ |
|
85 | 85 | yield from $annotations; |
86 | 86 | |
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | - foreach ($annotations as $annotation) { |
|
91 | - if ($annotation instanceof $name) { |
|
90 | + foreach ($annotations as $annotation){ |
|
91 | + if ($annotation instanceof $name){ |
|
92 | 92 | yield $annotation; |
93 | 93 | } |
94 | 94 | } |
@@ -18,7 +18,8 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function firstClassMetadata(\ReflectionClass $class, string $name): ?object |
20 | 20 | { |
21 | - foreach ($this->getClassMetadata($class, $name) as $attribute) { |
|
21 | + foreach ($this->getClassMetadata($class, $name) as $attribute) |
|
22 | + { |
|
22 | 23 | return $attribute; |
23 | 24 | } |
24 | 25 | |
@@ -30,7 +31,8 @@ discard block |
||
30 | 31 | */ |
31 | 32 | public function firstFunctionMetadata(\ReflectionFunctionAbstract $function, string $name): ?object |
32 | 33 | { |
33 | - foreach ($this->getFunctionMetadata($function, $name) as $attribute) { |
|
34 | + foreach ($this->getFunctionMetadata($function, $name) as $attribute) |
|
35 | + { |
|
34 | 36 | return $attribute; |
35 | 37 | } |
36 | 38 | |
@@ -42,7 +44,8 @@ discard block |
||
42 | 44 | */ |
43 | 45 | public function firstPropertyMetadata(\ReflectionProperty $property, string $name): ?object |
44 | 46 | { |
45 | - foreach ($this->getPropertyMetadata($property, $name) as $attribute) { |
|
47 | + foreach ($this->getPropertyMetadata($property, $name) as $attribute) |
|
48 | + { |
|
46 | 49 | return $attribute; |
47 | 50 | } |
48 | 51 | |
@@ -54,7 +57,8 @@ discard block |
||
54 | 57 | */ |
55 | 58 | public function firstConstantMetadata(\ReflectionClassConstant $constant, string $name): ?object |
56 | 59 | { |
57 | - foreach ($this->getConstantMetadata($constant, $name) as $attribute) { |
|
60 | + foreach ($this->getConstantMetadata($constant, $name) as $attribute) |
|
61 | + { |
|
58 | 62 | return $attribute; |
59 | 63 | } |
60 | 64 | |
@@ -66,7 +70,8 @@ discard block |
||
66 | 70 | */ |
67 | 71 | public function firstParameterMetadata(\ReflectionParameter $parameter, string $name): ?object |
68 | 72 | { |
69 | - foreach ($this->getParameterMetadata($parameter, $name) as $attribute) { |
|
73 | + foreach ($this->getParameterMetadata($parameter, $name) as $attribute) |
|
74 | + { |
|
70 | 75 | return $attribute; |
71 | 76 | } |
72 | 77 | |
@@ -81,14 +86,17 @@ discard block |
||
81 | 86 | */ |
82 | 87 | protected function filter(?string $name, iterable $annotations): iterable |
83 | 88 | { |
84 | - if ($name === null) { |
|
89 | + if ($name === null) |
|
90 | + { |
|
85 | 91 | yield from $annotations; |
86 | 92 | |
87 | 93 | return; |
88 | 94 | } |
89 | 95 | |
90 | - foreach ($annotations as $annotation) { |
|
91 | - if ($annotation instanceof $name) { |
|
96 | + foreach ($annotations as $annotation) |
|
97 | + { |
|
98 | + if ($annotation instanceof $name) |
|
99 | + { |
|
92 | 100 | yield $annotation; |
93 | 101 | } |
94 | 102 | } |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
36 | 36 | { |
37 | - if ($this->isNamedArgumentsSupported()) { |
|
38 | - try { |
|
37 | + if ($this->isNamedArgumentsSupported()){ |
|
38 | + try{ |
|
39 | 39 | return $attr->newInstanceArgs($arguments); |
40 | - } catch (\Throwable $e) { |
|
40 | + }catch (\Throwable $e){ |
|
41 | 41 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | $constructor = $this->getConstructor($attr); |
46 | 46 | |
47 | - if ($constructor === null) { |
|
47 | + if ($constructor === null){ |
|
48 | 48 | return $attr->newInstanceWithoutConstructor(); |
49 | 49 | } |
50 | 50 | |
@@ -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 | |
@@ -97,19 +97,19 @@ discard block |
||
97 | 97 | */ |
98 | 98 | private function resolveParameter(\ReflectionClass $ctx, \ReflectionParameter $param, array &$arguments) |
99 | 99 | { |
100 | - switch (true) { |
|
100 | + switch (true){ |
|
101 | 101 | case \array_key_exists($param->getName(), $arguments): |
102 | - try { |
|
102 | + try{ |
|
103 | 103 | return $arguments[$param->getName()]; |
104 | - } finally { |
|
104 | + }finally{ |
|
105 | 105 | unset($arguments[$param->getName()]); |
106 | 106 | } |
107 | 107 | // no actual falling through |
108 | 108 | |
109 | 109 | case \array_key_exists($param->getPosition(), $arguments): |
110 | - try { |
|
110 | + try{ |
|
111 | 111 | return $arguments[$param->getPosition()]; |
112 | - } finally { |
|
112 | + }finally{ |
|
113 | 113 | unset($arguments[$param->getPosition()]); |
114 | 114 | } |
115 | 115 | // no actual falling through |
@@ -34,17 +34,22 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
36 | 36 | { |
37 | - if ($this->isNamedArgumentsSupported()) { |
|
38 | - try { |
|
37 | + if ($this->isNamedArgumentsSupported()) |
|
38 | + { |
|
39 | + try |
|
40 | + { |
|
39 | 41 | return $attr->newInstanceArgs($arguments); |
40 | - } catch (\Throwable $e) { |
|
42 | + } |
|
43 | + catch (\Throwable $e) |
|
44 | + { |
|
41 | 45 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
42 | 46 | } |
43 | 47 | } |
44 | 48 | |
45 | 49 | $constructor = $this->getConstructor($attr); |
46 | 50 | |
47 | - if ($constructor === null) { |
|
51 | + if ($constructor === null) |
|
52 | + { |
|
48 | 53 | return $attr->newInstanceWithoutConstructor(); |
49 | 54 | } |
50 | 55 | |
@@ -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 | |
@@ -97,19 +107,26 @@ discard block |
||
97 | 107 | */ |
98 | 108 | private function resolveParameter(\ReflectionClass $ctx, \ReflectionParameter $param, array &$arguments) |
99 | 109 | { |
100 | - switch (true) { |
|
110 | + switch (true) |
|
111 | + { |
|
101 | 112 | case \array_key_exists($param->getName(), $arguments): |
102 | - try { |
|
113 | + try |
|
114 | + { |
|
103 | 115 | return $arguments[$param->getName()]; |
104 | - } finally { |
|
116 | + } |
|
117 | + finally |
|
118 | + { |
|
105 | 119 | unset($arguments[$param->getName()]); |
106 | 120 | } |
107 | 121 | // no actual falling through |
108 | 122 | |
109 | 123 | case \array_key_exists($param->getPosition(), $arguments): |
110 | - try { |
|
124 | + try |
|
125 | + { |
|
111 | 126 | return $arguments[$param->getPosition()]; |
112 | - } finally { |
|
127 | + } |
|
128 | + finally |
|
129 | + { |
|
113 | 130 | unset($arguments[$param->getPosition()]); |
114 | 131 | } |
115 | 132 | // no actual falling through |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
51 | 51 | { |
52 | - if ($this->isNamedArguments($attr)) { |
|
52 | + if ($this->isNamedArguments($attr)){ |
|
53 | 53 | return $this->named->instantiate($attr, $arguments, $context); |
54 | 54 | } |
55 | 55 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | private function providesNamedArgumentsAttribute(\ReflectionClass $class): bool |
75 | 75 | { |
76 | - if (\class_exists(MarkerAnnotation::class)) { |
|
76 | + if (\class_exists(MarkerAnnotation::class)){ |
|
77 | 77 | return $this->reader->firstClassMetadata($class, MarkerAnnotation::class) !== null; |
78 | 78 | } |
79 | 79 |
@@ -49,7 +49,8 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
51 | 51 | { |
52 | - if ($this->isNamedArguments($attr)) { |
|
52 | + if ($this->isNamedArguments($attr)) |
|
53 | + { |
|
53 | 54 | return $this->named->instantiate($attr, $arguments, $context); |
54 | 55 | } |
55 | 56 | |
@@ -73,7 +74,8 @@ discard block |
||
73 | 74 | */ |
74 | 75 | private function providesNamedArgumentsAttribute(\ReflectionClass $class): bool |
75 | 76 | { |
76 | - if (\class_exists(MarkerAnnotation::class)) { |
|
77 | + if (\class_exists(MarkerAnnotation::class)) |
|
78 | + { |
|
77 | 79 | return $this->reader->firstClassMetadata($class, MarkerAnnotation::class) !== null; |
78 | 80 | } |
79 | 81 |
@@ -124,7 +124,7 @@ |
||
124 | 124 | */ |
125 | 125 | protected function iterableToArray(iterable $attributes): array |
126 | 126 | { |
127 | - if ($attributes instanceof \Traversable) { |
|
127 | + if ($attributes instanceof \Traversable){ |
|
128 | 128 | return \iterator_to_array($attributes, false); |
129 | 129 | } |
130 | 130 |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function getClassMetadata(\ReflectionClass $class, string $name = null): iterable |
43 | 43 | { |
44 | - $result = $this->cached($this->key->forClass($class), function () use ($class) { |
|
44 | + $result = $this->cached($this->key->forClass($class), function () use ($class) |
|
45 | + { |
|
45 | 46 | return $this->iterableToArray(parent::getClassMetadata($class)); |
46 | 47 | }); |
47 | 48 | |
@@ -53,7 +54,8 @@ discard block |
||
53 | 54 | */ |
54 | 55 | public function getFunctionMetadata(\ReflectionFunctionAbstract $function, string $name = null): iterable |
55 | 56 | { |
56 | - $result = $this->cached($this->key->forFunction($function), function () use ($function) { |
|
57 | + $result = $this->cached($this->key->forFunction($function), function () use ($function) |
|
58 | + { |
|
57 | 59 | return $this->iterableToArray(parent::getFunctionMetadata($function)); |
58 | 60 | }); |
59 | 61 | |
@@ -65,7 +67,8 @@ discard block |
||
65 | 67 | */ |
66 | 68 | public function getPropertyMetadata(\ReflectionProperty $property, string $name = null): iterable |
67 | 69 | { |
68 | - $result = $this->cached($this->key->forProperty($property), function () use ($property) { |
|
70 | + $result = $this->cached($this->key->forProperty($property), function () use ($property) |
|
71 | + { |
|
69 | 72 | return $this->iterableToArray(parent::getPropertyMetadata($property)); |
70 | 73 | }); |
71 | 74 | |
@@ -77,7 +80,8 @@ discard block |
||
77 | 80 | */ |
78 | 81 | public function getConstantMetadata(\ReflectionClassConstant $constant, string $name = null): iterable |
79 | 82 | { |
80 | - $result = $this->cached($this->key->forConstant($constant), function () use ($constant) { |
|
83 | + $result = $this->cached($this->key->forConstant($constant), function () use ($constant) |
|
84 | + { |
|
81 | 85 | return $this->iterableToArray(parent::getConstantMetadata($constant)); |
82 | 86 | }); |
83 | 87 | |
@@ -89,7 +93,8 @@ discard block |
||
89 | 93 | */ |
90 | 94 | public function getParameterMetadata(\ReflectionParameter $parameter, string $name = null): iterable |
91 | 95 | { |
92 | - $result = $this->cached($this->key->forParameter($parameter), function () use ($parameter) { |
|
96 | + $result = $this->cached($this->key->forParameter($parameter), function () use ($parameter) |
|
97 | + { |
|
93 | 98 | return $this->iterableToArray(parent::getParameterMetadata($parameter)); |
94 | 99 | }); |
95 | 100 | |
@@ -124,7 +129,8 @@ discard block |
||
124 | 129 | */ |
125 | 130 | protected function iterableToArray(iterable $attributes): array |
126 | 131 | { |
127 | - if ($attributes instanceof \Traversable) { |
|
132 | + if ($attributes instanceof \Traversable) |
|
133 | + { |
|
128 | 134 | return \iterator_to_array($attributes, false); |
129 | 135 | } |
130 | 136 |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | private function checkAvailability(): void |
86 | 86 | { |
87 | - if (!self::isAvailable()) { |
|
87 | + if (!self::isAvailable()){ |
|
88 | 88 | throw new InitializationException('Requires the PHP >= 8.0'); |
89 | 89 | } |
90 | 90 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | private function format(\Reflector $context, iterable $attributes): iterable |
99 | 99 | { |
100 | - foreach ($attributes as $attribute) { |
|
100 | + foreach ($attributes as $attribute){ |
|
101 | 101 | $this->assertClassExists($attribute->getName(), $context); |
102 | 102 | |
103 | 103 | yield new \ReflectionClass($attribute->getName()) => $attribute->getArguments(); |
@@ -84,7 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | private function checkAvailability(): void |
86 | 86 | { |
87 | - if (!self::isAvailable()) { |
|
87 | + if (!self::isAvailable()) |
|
88 | + { |
|
88 | 89 | throw new InitializationException('Requires the PHP >= 8.0'); |
89 | 90 | } |
90 | 91 | } |
@@ -97,7 +98,8 @@ discard block |
||
97 | 98 | */ |
98 | 99 | private function format(\Reflector $context, iterable $attributes): iterable |
99 | 100 | { |
100 | - foreach ($attributes as $attribute) { |
|
101 | + foreach ($attributes as $attribute) |
|
102 | + { |
|
101 | 103 | $this->assertClassExists($attribute->getName(), $context); |
102 | 104 | |
103 | 105 | yield new \ReflectionClass($attribute->getName()) => $attribute->getArguments(); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function render(?\Reflector $reflector): string |
65 | 65 | { |
66 | - switch (true) { |
|
66 | + switch (true){ |
|
67 | 67 | case $reflector instanceof \ReflectionClass: |
68 | 68 | return $this->renderClassContext($reflector); |
69 | 69 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function renderClassContext(\ReflectionClass $class): string |
92 | 92 | { |
93 | - if ($class->isAnonymous()) { |
|
93 | + if ($class->isAnonymous()){ |
|
94 | 94 | return \sprintf(self::FORMAT_ANONYMOUS_CLASS, $class->getFileName(), $class->getStartLine()); |
95 | 95 | } |
96 | 96 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function renderFunctionContext(\ReflectionFunction $fn): string |
116 | 116 | { |
117 | - if ($fn->isClosure()) { |
|
117 | + if ($fn->isClosure()){ |
|
118 | 118 | return \sprintf(self::FORMAT_ANONYMOUS_FUNCTION, $fn->getFileName(), $fn->getStartLine()); |
119 | 119 | } |
120 | 120 | |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function renderCallableContext(\ReflectionFunctionAbstract $function): string |
129 | 129 | { |
130 | - if ($function instanceof \ReflectionMethod) { |
|
130 | + if ($function instanceof \ReflectionMethod){ |
|
131 | 131 | return $this->renderMethodContext($function); |
132 | 132 | } |
133 | 133 | |
134 | - if ($function instanceof \ReflectionFunction) { |
|
134 | + if ($function instanceof \ReflectionFunction){ |
|
135 | 135 | return $this->renderFunctionContext($function); |
136 | 136 | } |
137 | 137 |
@@ -63,7 +63,8 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function render(?\Reflector $reflector): string |
65 | 65 | { |
66 | - switch (true) { |
|
66 | + switch (true) |
|
67 | + { |
|
67 | 68 | case $reflector instanceof \ReflectionClass: |
68 | 69 | return $this->renderClassContext($reflector); |
69 | 70 | |
@@ -90,7 +91,8 @@ discard block |
||
90 | 91 | */ |
91 | 92 | public function renderClassContext(\ReflectionClass $class): string |
92 | 93 | { |
93 | - if ($class->isAnonymous()) { |
|
94 | + if ($class->isAnonymous()) |
|
95 | + { |
|
94 | 96 | return \sprintf(self::FORMAT_ANONYMOUS_CLASS, $class->getFileName(), $class->getStartLine()); |
95 | 97 | } |
96 | 98 | |
@@ -114,7 +116,8 @@ discard block |
||
114 | 116 | */ |
115 | 117 | public function renderFunctionContext(\ReflectionFunction $fn): string |
116 | 118 | { |
117 | - if ($fn->isClosure()) { |
|
119 | + if ($fn->isClosure()) |
|
120 | + { |
|
118 | 121 | return \sprintf(self::FORMAT_ANONYMOUS_FUNCTION, $fn->getFileName(), $fn->getStartLine()); |
119 | 122 | } |
120 | 123 | |
@@ -127,11 +130,13 @@ discard block |
||
127 | 130 | */ |
128 | 131 | public function renderCallableContext(\ReflectionFunctionAbstract $function): string |
129 | 132 | { |
130 | - if ($function instanceof \ReflectionMethod) { |
|
133 | + if ($function instanceof \ReflectionMethod) |
|
134 | + { |
|
131 | 135 | return $this->renderMethodContext($function); |
132 | 136 | } |
133 | 137 | |
134 | - if ($function instanceof \ReflectionFunction) { |
|
138 | + if ($function instanceof \ReflectionFunction) |
|
139 | + { |
|
135 | 140 | return $this->renderFunctionContext($function); |
136 | 141 | } |
137 | 142 |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | { |
119 | 119 | $eval = new ConstExprEvaluator($this->evaluator($file, $context)); |
120 | 120 | |
121 | - foreach ($groups as $group) { |
|
122 | - foreach ($group->attrs as $attr) { |
|
121 | + foreach ($groups as $group){ |
|
122 | + foreach ($group->attrs as $attr){ |
|
123 | 123 | $arguments = $this->parseAttributeArguments($attr, $file, $eval); |
124 | 124 | |
125 | 125 | yield new AttributePrototype($attr->name->toString(), $arguments); |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | */ |
144 | 144 | private function read(string $file): string |
145 | 145 | { |
146 | - if (!\is_readable($file)) { |
|
147 | - throw new \InvalidArgumentException('Unable to read file "' . $file . '"'); |
|
146 | + if (!\is_readable($file)){ |
|
147 | + throw new \InvalidArgumentException('Unable to read file "'.$file.'"'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return \file_get_contents($file); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | private function evaluator(string $file, array $context): \Closure |
159 | 159 | { |
160 | 160 | return static function (Expr $expr) use ($file, $context) { |
161 | - switch (\get_class($expr)) { |
|
161 | + switch (\get_class($expr)){ |
|
162 | 162 | case Scalar\MagicConst\File::class: |
163 | 163 | return $file; |
164 | 164 | |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | $namespace = $context[self::CTX_NAMESPACE] ?? ''; |
173 | 173 | $function = $context[self::CTX_FUNCTION] ?? ''; |
174 | 174 | |
175 | - return \ltrim($namespace . '\\' . $function, '\\'); |
|
175 | + return \ltrim($namespace.'\\'.$function, '\\'); |
|
176 | 176 | |
177 | 177 | case Expr\ClassConstFetch::class: |
178 | 178 | $constant = $expr->name->toString(); |
179 | 179 | $class = $expr->class->toString(); |
180 | 180 | |
181 | - if (\strtolower($constant) === 'class') { |
|
181 | + if (\strtolower($constant) === 'class'){ |
|
182 | 182 | return $class; |
183 | 183 | } |
184 | 184 | |
185 | - $definition = $class . '::' . $constant; |
|
185 | + $definition = $class.'::'.$constant; |
|
186 | 186 | |
187 | - if (!\defined($definition)) { |
|
187 | + if (!\defined($definition)){ |
|
188 | 188 | $exception = new \ParseError(\sprintf(self::ERROR_BAD_CONSTANT, $definition)); |
189 | 189 | throw Exception::withLocation($exception, $file, $expr->getStartLine()); |
190 | 190 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | return \constant($definition); |
193 | 193 | } |
194 | 194 | |
195 | - if ($expr instanceof Scalar\MagicConst) { |
|
195 | + if ($expr instanceof Scalar\MagicConst){ |
|
196 | 196 | return $context[$expr->getName()] ?? ''; |
197 | 197 | } |
198 | 198 | |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | $hasNamedArguments = false; |
215 | 215 | $arguments = []; |
216 | 216 | |
217 | - foreach ($attr->args as $argument) { |
|
217 | + foreach ($attr->args as $argument){ |
|
218 | 218 | $value = $eval->evaluateDirectly($argument->value); |
219 | 219 | |
220 | - if ($argument->name === null) { |
|
220 | + if ($argument->name === null){ |
|
221 | 221 | $arguments[] = $value; |
222 | 222 | |
223 | - if ($hasNamedArguments) { |
|
223 | + if ($hasNamedArguments){ |
|
224 | 224 | $exception = new \ParseError(self::ERROR_NAMED_ARGUMENTS_ORDER); |
225 | 225 | throw Exception::withLocation($exception, $file, $argument->getStartLine()); |
226 | 226 | } |
@@ -118,8 +118,10 @@ discard block |
||
118 | 118 | { |
119 | 119 | $eval = new ConstExprEvaluator($this->evaluator($file, $context)); |
120 | 120 | |
121 | - foreach ($groups as $group) { |
|
122 | - foreach ($group->attrs as $attr) { |
|
121 | + foreach ($groups as $group) |
|
122 | + { |
|
123 | + foreach ($group->attrs as $attr) |
|
124 | + { |
|
123 | 125 | $arguments = $this->parseAttributeArguments($attr, $file, $eval); |
124 | 126 | |
125 | 127 | yield new AttributePrototype($attr->name->toString(), $arguments); |
@@ -143,7 +145,8 @@ discard block |
||
143 | 145 | */ |
144 | 146 | private function read(string $file): string |
145 | 147 | { |
146 | - if (!\is_readable($file)) { |
|
148 | + if (!\is_readable($file)) |
|
149 | + { |
|
147 | 150 | throw new \InvalidArgumentException('Unable to read file "' . $file . '"'); |
148 | 151 | } |
149 | 152 | |
@@ -157,8 +160,10 @@ discard block |
||
157 | 160 | */ |
158 | 161 | private function evaluator(string $file, array $context): \Closure |
159 | 162 | { |
160 | - return static function (Expr $expr) use ($file, $context) { |
|
161 | - switch (\get_class($expr)) { |
|
163 | + return static function (Expr $expr) use ($file, $context) |
|
164 | + { |
|
165 | + switch (\get_class($expr)) |
|
166 | + { |
|
162 | 167 | case Scalar\MagicConst\File::class: |
163 | 168 | return $file; |
164 | 169 | |
@@ -178,13 +183,15 @@ discard block |
||
178 | 183 | $constant = $expr->name->toString(); |
179 | 184 | $class = $expr->class->toString(); |
180 | 185 | |
181 | - if (\strtolower($constant) === 'class') { |
|
186 | + if (\strtolower($constant) === 'class') |
|
187 | + { |
|
182 | 188 | return $class; |
183 | 189 | } |
184 | 190 | |
185 | 191 | $definition = $class . '::' . $constant; |
186 | 192 | |
187 | - if (!\defined($definition)) { |
|
193 | + if (!\defined($definition)) |
|
194 | + { |
|
188 | 195 | $exception = new \ParseError(\sprintf(self::ERROR_BAD_CONSTANT, $definition)); |
189 | 196 | throw Exception::withLocation($exception, $file, $expr->getStartLine()); |
190 | 197 | } |
@@ -192,7 +199,8 @@ discard block |
||
192 | 199 | return \constant($definition); |
193 | 200 | } |
194 | 201 | |
195 | - if ($expr instanceof Scalar\MagicConst) { |
|
202 | + if ($expr instanceof Scalar\MagicConst) |
|
203 | + { |
|
196 | 204 | return $context[$expr->getName()] ?? ''; |
197 | 205 | } |
198 | 206 | |
@@ -214,13 +222,16 @@ discard block |
||
214 | 222 | $hasNamedArguments = false; |
215 | 223 | $arguments = []; |
216 | 224 | |
217 | - foreach ($attr->args as $argument) { |
|
225 | + foreach ($attr->args as $argument) |
|
226 | + { |
|
218 | 227 | $value = $eval->evaluateDirectly($argument->value); |
219 | 228 | |
220 | - if ($argument->name === null) { |
|
229 | + if ($argument->name === null) |
|
230 | + { |
|
221 | 231 | $arguments[] = $value; |
222 | 232 | |
223 | - if ($hasNamedArguments) { |
|
233 | + if ($hasNamedArguments) |
|
234 | + { |
|
224 | 235 | $exception = new \ParseError(self::ERROR_NAMED_ARGUMENTS_ORDER); |
225 | 236 | throw Exception::withLocation($exception, $file, $argument->getStartLine()); |
226 | 237 | } |