AssertJsonapiObject   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 23
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertIsValidJsonapiObject() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiAssert\Asserts\Structure;
6
7
/**
8
 * Assertions relating to the jsonapi object
9
 */
10
trait AssertJsonapiObject
11
{
12
    /**
13
     * Asserts that a json fragment is a valid jsonapi object.
14
     *
15
     * It will do the following checks :
16
     * 1) asserts that the jsonapi object is not an array of objects (@see assertIsNotArrayOfObjects).
17
     * 2) asserts that the jsonapi object contains only the following allowed members : "version" and "meta"
18
     * (@see assertContainsOnlyAllowedMembers).
19
     *
20
     * Optionaly, if presents, it will checks :
21
     * 3) asserts that the version member is a string.
22
     * 4) asserts that meta member is valid (@see assertIsValidMetaObject).
23
     *
24
     * @param array   $json
25
     * @param boolean $strict If true, unsafe characters are not allowed when checking members name.
26
     *
27
     * @return void
28
     * @throws \PHPUnit\Framework\AssertionFailedError
29
     */
30 18
    public static function assertIsValidJsonapiObject($json, bool $strict): void
31
    {
32 18
        static::askService('validateJsonapiObject', $json, $strict);
33 3
    }
34
}
35