Completed
Push — master ( b6f077...d569a5 )
by Vitaly
05:48
created

AnnotationWithValue::checkValuePresence()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
/**
5
 * Created by Vitaly Iegorov <[email protected]>.
6
 * on 06.08.16 at 13:44
7
 */
8
namespace samsonframework\container\annotation;
9
10
/**
11
 *  Annotation with value.
12
 */
13
class AnnotationWithValue implements AnnotationInterface
14
{
15
    /** @var string[] Collection of class collection */
16
    protected $collection = [];
17
18
    /**
19
     * Scope constructor.
20
     *
21
     * @param array $valueOrValues Class collection
22
     *
23
     * @throws \InvalidArgumentException Thrown when neither string nor string[] is passed
24
     */
25 22
    public function __construct(array $valueOrValues)
26
    {
27 22
        if ($this->checkValuePresence($valueOrValues)) {
28
            // Convert empty values to null
29 22
            $value = $valueOrValues['value'] ?? null;
30
31
            // Always store array
32 22
            $this->collection = is_array($value) ? $value : [$value];
33
        } else {
34 1
            throw new \InvalidArgumentException('Only string or array is allowed');
35
        }
36 22
    }
37
38
    /**
39
     * Check if we received an array with keys.
40
     *
41
     * @param array $valueOrValues
42
     *
43
     * @return bool True if value key exists
44
     */
45 22
    protected function checkValuePresence(array $valueOrValues)
46
    {
47 22
        return count(array_keys($valueOrValues));
48
    }
49
}
50