Code Duplication    Length = 36-37 lines in 2 locations

src/annotation/AnnotationValueTrait.php 1 location

@@ 13-48 (lines=36) @@
10
/**
11
 *  Annotation with value trait.
12
 */
13
trait AnnotationValueTrait
14
{
15
    /**
16
     * Parse annotation value.
17
     *
18
     * @param array $valueOrValues Class collection
19
     *
20
     * @return array Parsed annotation key=>value collection
21
     *
22
     * @throws \InvalidArgumentException Thrown when neither string nor string[] is passed
23
     */
24
    public function parseAnnotationValue(array $valueOrValues) : array
25
    {
26
        if ($this->checkValuePresence($valueOrValues)) {
27
            // Convert empty values to null
28
            $value = $valueOrValues['value'] ?? null;
29
30
            // Always store array
31
            return is_array($value) ? $value : [$value];
32
        } else {
33
            throw new \InvalidArgumentException('Only string or array is allowed');
34
        }
35
    }
36
37
    /**
38
     * Check if we received an array with keys.
39
     *
40
     * @param array $valueOrValues
41
     *
42
     * @return bool True if value key exists
43
     */
44
    protected function checkValuePresence(array $valueOrValues)
45
    {
46
        return count(array_filter(array_keys($valueOrValues)));
47
    }
48
}
49

src/annotation/AnnotationWithValue.php 1 location

@@ 13-49 (lines=37) @@
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
    public function __construct(array $valueOrValues)
26
    {
27
        if ($this->checkValuePresence($valueOrValues)) {
28
            // Convert empty values to null
29
            $value = $valueOrValues['value'] ?? null;
30
31
            // Always store array
32
            $this->collection = is_array($value) ? $value : [$value];
33
        } else {
34
            throw new \InvalidArgumentException('Only string or array is allowed');
35
        }
36
    }
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
    protected function checkValuePresence(array $valueOrValues)
46
    {
47
        return count(array_filter(array_keys($valueOrValues)));
48
    }
49
}
50