Completed
Push — master ( bfd868...ee3a72 )
by Vincent
12:29 queued 10:26
created

AssertJsonapiObject::assertIsValidJsonapiObject()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 4
nop 1
dl 0
loc 22
ccs 14
cts 14
cp 1
crap 3
rs 9.8333
c 0
b 0
f 0
1
<?php
2
namespace VGirol\JsonApiAssert\Asserts;
3
4
use PHPUnit\Framework\Assert as PHPUnit;
5
use VGirol\JsonApiAssert\Messages;
6
7
trait AssertJsonapiObject
8
{
9
    /**
10
     * Asserts that a jsonapi object is valid.
11
     *
12
     * @param array $jsonapi
13
     * 
14
     * @throws PHPUnit\Framework\ExpectationFailedException
15
     */
16 6
    public static function assertIsValidJsonapiObject($jsonapi)
17
    {
18 6
        static::assertIsNotArrayOfObjects(
19 6
            $jsonapi,
20 6
            Messages::OBJECT_NOT_ARRAY
21
        );
22
23 5
        $allowed = ['version', 'meta'];
24 5
        static::assertContainsOnlyAllowedMembers(
25 5
            $allowed,
26 5
            $jsonapi
27
        );
28
29 4
        if (isset($jsonapi['version'])) {
30 4
            PHPUnit::assertIsString(
31 4
                $jsonapi['version'],
32 4
                Messages::JSONAPI_VERSION_IS_NOT_STRING
33
            );
34
        }
35
36 3
        if (isset($jsonapi['meta'])) {
37 2
            static::assertIsValidMetaObject($jsonapi['meta']);
0 ignored issues
show
Bug introduced by
The method assertIsValidMetaObject() does not exist on VGirol\JsonApiAssert\Asserts\AssertJsonapiObject. Did you maybe mean assertIsValidJsonapiObject()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            static::/** @scrutinizer ignore-call */ 
38
                    assertIsValidMetaObject($jsonapi['meta']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        }
39 2
    }
40
}
41