ValidateMetaObject::validateMetaObject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiStructure\Concern;
6
7
use VGirol\JsonApiStructure\Messages;
8
9
/**
10
 * Validations relating to the meta object
11
 */
12
trait ValidateMetaObject
13
{
14
    /**
15
     * Assert that a json fragment is a valid meta object.
16
     *
17
     * It will do the following checks :
18
     * 1) validates that the meta object is not an array of objects (@see mustNotBeArrayOfObjects).
19
     * 2) validates that each member of the meta object is valid (@see validateMemberName).
20
     *
21
     * @param array   $json
22
     * @param boolean $strict If true, unsafe characters are not allowed when checking members name.
23
     *
24
     * @return void
25
     * @throws \VGirol\JsonApiStructure\Exception\ValidationException
26
     */
27 75
    public function validateMetaObject($json, bool $strict): void
28
    {
29 75
        $this->mustNotBeArrayOfObjects($json, Messages::META_OBJECT_MUST_BE_ARRAY, 403);
0 ignored issues
show
Bug introduced by
It seems like mustNotBeArrayOfObjects() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

29
        $this->/** @scrutinizer ignore-call */ 
30
               mustNotBeArrayOfObjects($json, Messages::META_OBJECT_MUST_BE_ARRAY, 403);
Loading history...
30
31 69
        foreach (array_keys($json) as $key) {
32 69
            $this->validateMemberName($key, $strict);
0 ignored issues
show
Bug introduced by
The method validateMemberName() does not exist on VGirol\JsonApiStructure\Concern\ValidateMetaObject. Did you maybe mean validateMetaObject()? ( Ignorable by Annotation )

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

32
            $this->/** @scrutinizer ignore-call */ 
33
                   validateMemberName($key, $strict);

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...
33
        }
34 27
    }
35
}
36