@@ -100,8 +100,10 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | $eval = new ConstExprEvaluator($this->evaluator($file, $context)); |
| 102 | 102 | |
| 103 | - foreach ($groups as $group) { |
|
| 104 | - foreach ($group->attrs as $attr) { |
|
| 103 | + foreach ($groups as $group) |
|
| 104 | + { |
|
| 105 | + foreach ($group->attrs as $attr) |
|
| 106 | + { |
|
| 105 | 107 | $arguments = $this->parseAttributeArguments($attr, $file, $eval); |
| 106 | 108 | |
| 107 | 109 | yield new AttributePrototype($attr->name->toString(), $arguments); |
@@ -125,7 +127,8 @@ discard block |
||
| 125 | 127 | */ |
| 126 | 128 | private function read(string $file): string |
| 127 | 129 | { |
| 128 | - if (!\is_readable($file)) { |
|
| 130 | + if (!\is_readable($file)) |
|
| 131 | + { |
|
| 129 | 132 | throw new \InvalidArgumentException('Unable to read file "' . $file . '"'); |
| 130 | 133 | } |
| 131 | 134 | |
@@ -139,8 +142,10 @@ discard block |
||
| 139 | 142 | */ |
| 140 | 143 | private function evaluator(string $file, array $context): \Closure |
| 141 | 144 | { |
| 142 | - return static function (Expr $expr) use ($file, $context) { |
|
| 143 | - switch (\get_class($expr)) { |
|
| 145 | + return static function (Expr $expr) use ($file, $context) |
|
| 146 | + { |
|
| 147 | + switch (\get_class($expr)) |
|
| 148 | + { |
|
| 144 | 149 | case Scalar\MagicConst\File::class: |
| 145 | 150 | return $file; |
| 146 | 151 | |
@@ -160,13 +165,15 @@ discard block |
||
| 160 | 165 | $constant = $expr->name->toString(); |
| 161 | 166 | $class = $expr->class->toString(); |
| 162 | 167 | |
| 163 | - if (\strtolower($constant) === 'class') { |
|
| 168 | + if (\strtolower($constant) === 'class') |
|
| 169 | + { |
|
| 164 | 170 | return $class; |
| 165 | 171 | } |
| 166 | 172 | |
| 167 | 173 | $definition = $class . '::' . $constant; |
| 168 | 174 | |
| 169 | - if (! \defined($definition)) { |
|
| 175 | + if (! \defined($definition)) |
|
| 176 | + { |
|
| 170 | 177 | $exception = new \ParseError(\sprintf(self::ERROR_BAD_CONSTANT, $definition)); |
| 171 | 178 | throw Exception::withLocation($exception, $file, $expr->getStartLine()); |
| 172 | 179 | } |
@@ -174,7 +181,8 @@ discard block |
||
| 174 | 181 | return \constant($definition); |
| 175 | 182 | } |
| 176 | 183 | |
| 177 | - if ($expr instanceof Scalar\MagicConst) { |
|
| 184 | + if ($expr instanceof Scalar\MagicConst) |
|
| 185 | + { |
|
| 178 | 186 | return $context[$expr->getName()] ?? ''; |
| 179 | 187 | } |
| 180 | 188 | |
@@ -196,13 +204,16 @@ discard block |
||
| 196 | 204 | $hasNamedArguments = false; |
| 197 | 205 | $arguments = []; |
| 198 | 206 | |
| 199 | - foreach ($attr->args as $argument) { |
|
| 207 | + foreach ($attr->args as $argument) |
|
| 208 | + { |
|
| 200 | 209 | $value = $eval->evaluateDirectly($argument->value); |
| 201 | 210 | |
| 202 | - if ($argument->name === null) { |
|
| 211 | + if ($argument->name === null) |
|
| 212 | + { |
|
| 203 | 213 | $arguments[] = $value; |
| 204 | 214 | |
| 205 | - if ($hasNamedArguments) { |
|
| 215 | + if ($hasNamedArguments) |
|
| 216 | + { |
|
| 206 | 217 | $exception = new \ParseError(self::ERROR_NAMED_ARGUMENTS_ORDER); |
| 207 | 218 | throw Exception::withLocation($exception, $file, $argument->getStartLine()); |
| 208 | 219 | } |