AssertLinksObject::assertIsValidLinkObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiAssert\Asserts\Structure;
6
7
/**
8
 * Assertions relating to the links object
9
 */
10
trait AssertLinksObject
11
{
12
    /**
13
     * Asserts that a json fragment is a valid links object.
14
     *
15
     * It will do the following checks :
16
     * 1) asserts that it contains only allowed members (@see assertContainsOnlyAllowedMembers).
17
     * 2) asserts that each member of the links object is a valid link object (@see assertIsValidLinkObject).
18
     *
19
     * @param array         $json
20
     * @param array<string> $allowedMembers
21
     * @param boolean       $strict         If true, unsafe characters are not allowed when checking members name.
22
     *
23
     * @return void
24
     * @throws \PHPUnit\Framework\AssertionFailedError
25
     */
26 15
    public static function assertIsValidLinksObject($json, array $allowedMembers, bool $strict): void
27
    {
28 15
        static::askService('validateLinksObject', $json, $allowedMembers, $strict);
29 3
    }
30
31
    /**
32
     * Asserts that a json fragment is a valid link object.
33
     *
34
     * It will do the following checks :
35
     * 1) asserts that the link object is a string, an array or the `null` value.
36
     * 2) in case it is an array :
37
     *      3) asserts that it has the "href" member.
38
     *      4) asserts that it contains only the following allowed members : "href" and "meta"
39
     *       (@see assertContainsOnlyAllowedMembers).
40
     *      5) if present, asserts that the "meta" object is valid (@see assertIsValidMetaObject).
41
     *
42
     * @param array|string|null $json
43
     * @param boolean           $strict If true, unsafe characters are not allowed when checking members name.
44
     *
45
     * @return void
46
     * @throws \PHPUnit\Framework\AssertionFailedError
47
     */
48 24
    public static function assertIsValidLinkObject($json, bool $strict): void
49
    {
50 24
        static::askService('validateLinkObject', $json, $strict);
51 9
    }
52
}
53