Total Complexity | 2 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | trait AssertMemberName |
||
14 | { |
||
15 | /** |
||
16 | * Asserts that a member name is valid. |
||
17 | * |
||
18 | * It will do the following checks : |
||
19 | * 1) asserts that the name is a string with at least one character. |
||
20 | * 2) asserts that the name has only allowed characters. |
||
21 | * 3) asserts that it starts and ends with a globally allowed character. |
||
22 | * |
||
23 | * @link https://jsonapi.org/format/#document-member-names-allowed-characters |
||
24 | * |
||
25 | * @param string $name |
||
26 | * @param boolean $strict If true, unsafe characters are not allowed when checking members name. |
||
27 | * |
||
28 | * @return void |
||
29 | * @throws \PHPUnit\Framework\AssertionFailedError |
||
30 | */ |
||
31 | 27 | public static function assertIsValidMemberName($name, bool $strict): void |
|
32 | { |
||
33 | 27 | PHPUnit::assertThat($name, self::memberNameConstraint($strict)); |
|
34 | 9 | } |
|
35 | |||
36 | /** |
||
37 | * Returns a new instance of the \VGirol\JsonApiAssert\Constraint\MemberNameConstraint class. |
||
38 | * |
||
39 | * @param bool $strict |
||
40 | * |
||
41 | * @return \VGirol\JsonApiAssert\Constraint\MemberNameConstraint |
||
42 | */ |
||
43 | 27 | private static function memberNameConstraint(bool $strict): MemberNameConstraint |
|
46 | } |
||
47 | } |
||
48 |