AssertJsonapiObject::assertIsValidJsonapiObject()   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 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