| Conditions | 7 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | function isValidNameError(string $name, $node = null): ?ValidationException |
||
| 37 | { |
||
| 38 | invariant(\is_string($name), 'Expected string'); |
||
| 39 | |||
| 40 | if (\strlen($name) > 1 && $name{0} === '_' && $name{1} === '_') { |
||
| 41 | return new ValidationException( |
||
| 42 | sprintf('Name "%s" must not begin with "__", which is reserved by GraphQL introspection.', $name), |
||
| 43 | $node instanceof NodeInterface ? [$node] : null |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (preg_match("/^[_a-zA-Z][_a-zA-Z0-9]*$/", $name) === 0) { |
||
| 48 | return new ValidationException( |
||
| 49 | sprintf('Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "%s" does not.', $name), |
||
| 50 | $node instanceof NodeInterface ? [$node] : null |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | |||
| 54 | return null; |
||
| 55 | } |
||
| 56 |