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