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 AmmitPhp\Ammit\UI\Resolver;
6
use AmmitPhp\Ammit\UI\Resolver\Validator\InvalidArgumentException;
7
8
9
class ValueExtractor
10
{
11
    /**
12
     * @param mixed $params
13
     * @param string $key
14
     *
15
     * @return mixed
16
     * @throws InvalidArgumentException If unable to extract
17
     */
18
    public function fromArray($params, string $key)
19
    {
20
        if (false === is_array($params)) {
21
            throw new InvalidArgumentException(
22
                sprintf('Value "%s" is not an array.', $params),
23
                0,
24
                null,
25
                $params
26
            );
27
        }
28
29
        if (false === array_key_exists($key, $params)) {
30
            throw new InvalidArgumentException(
31
                sprintf('Array does not contain an element with key "%s"', $key),
32
                0,
33
                null,
34
                $params
35
            );
36
        }
37
38
        return $params[$key];
39
    }
40
}
41