Completed
Pull Request — v0.10 (#630)
by Tautrimas
93:19
created

AbstractValue::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Annotation;
13
14
/**
15
 * Abstract annotations used for handling value.
16
 */
17
abstract class AbstractValue
18
{
19
    /**
20
     * @var array
21
     */
22
    public $value;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param array $values
28
     *
29
     * @throws \InvalidArgumentException
30
     */
31
    public function __construct(array $values)
32
    {
33
        if (is_string($values['value'])) {
34
            $this->value = [$values['value']];
35
        } elseif (is_array($values['value'])) {
36
            $this->value = $values['value'];
37
        } else {
38
            throw new \InvalidArgumentException(
39
                'Annotation `' . get_class($this) . '` unexpected type given. Expected string or array, given `'
40
                . gettype($values['value']) . '`'
41
            );
42
        }
43
    }
44
}
45