Completed
Push — master ( 0d47c0...ecf131 )
by Jesse
05:02
created

KeyRequiring::mustHaveTheKeyInThe()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapping\Property\Relationship;
5
6
use function assert;
7
use Stratadox\Hydration\Mapping\Property\MissingTheKey;
8
use Stratadox\HydrationMapping\ExposesDataKey;
9
use Stratadox\HydrationMapping\UnmappableInput;
10
11
trait KeyRequiring
12
{
13
    /**
14
     * Asserts that our key is present in the input array.
15
     *
16
     * @param array $data       Input data that must contain our key.
17
     * @throws UnmappableInput  When the input data does not contain our key.
18
     */
19
    private function mustHaveTheKeyInThe(array $data): void
20
    {
21
        $mapping = $this;
22
        assert($mapping instanceof ExposesDataKey);
23
        if (!isset($data[$mapping->key()])) {
0 ignored issues
show
Bug introduced by
It seems like key() 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

23
        if (!isset($data[$mapping->/** @scrutinizer ignore-call */ key()])) {
Loading history...
24
            throw MissingTheKey::inTheInput($data, $mapping, $mapping->key());
0 ignored issues
show
Bug introduced by
$mapping of type Stratadox\Hydration\Mapp...lationship\KeyRequiring is incompatible with the type Stratadox\HydrationMapping\MapsProperty expected by parameter $mapping of Stratadox\Hydration\Mapp...ingTheKey::inTheInput(). ( Ignorable by Annotation )

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

24
            throw MissingTheKey::inTheInput($data, /** @scrutinizer ignore-type */ $mapping, $mapping->key());
Loading history...
25
        }
26
    }
27
}
28