ValueExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 22 3
1
<?php
2
declare(strict_types = 1);
3
4
5
namespace Imedia\Ammit\UI\Resolver;
6
use Imedia\Ammit\UI\Resolver\Validator\InvalidArgumentException;
7
8
9
/**
10
 * @author Guillaume MOREL <[email protected]>
11
 */
12
class ValueExtractor
13
{
14
    /**
15
     * @param mixed $params
16
     * @param string $key
17
     *
18
     * @return mixed
19
     * @throws InvalidArgumentException If unable to extract
20
     */
21
    public function fromArray($params, string $key)
22
    {
23
        if (false === is_array($params)) {
24
            throw new InvalidArgumentException(
25
                sprintf('Value "%s" is not an array.', $params),
26
                0,
27
                null,
28
                $params
29
            );
30
        }
31
32
        if (false === array_key_exists($key, $params)) {
33
            throw new InvalidArgumentException(
34
                sprintf('Array does not contain an element with key "%s"', $key),
35
                0,
36
                null,
37
                $params
38
            );
39
        }
40
41
        return $params[$key];
42
    }
43
}
44