Completed
Push — develop ( 74dbd7...d5cb43 )
by Paul
02:08
created

ParamsAnnotation::getParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Annotation;
4
5
use PhpUnitGen\Annotation\AnnotationInterface\AnnotationInterface;
6
use PhpUnitGen\Exception\AnnotationParseException;
7
use PhpUnitGen\Exception\JsonException;
8
use PhpUnitGen\Util\Json;
9
use Respect\Validation\Validator;
10
11
/**
12
 * Class ParamsAnnotation.
13
 *
14
 * @author     Paul Thébaud <[email protected]>.
15
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
16
 * @license    https://opensource.org/licenses/MIT The MIT license.
17
 * @link       https://github.com/paul-thebaud/phpunit-generator
18
 * @since      Class available since Release 2.0.0.
19
 */
20
class ParamsAnnotation extends AbstractAnnotation
21
{
22
    /**
23
     * @var string[] $parameters The method call parameters.
24
     */
25
    private $parameters;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getType(): int
31
    {
32
        return AnnotationInterface::TYPE_PARAMS;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function compile(): void
39
    {
40
        // Decode JSON content
41
        try {
42
            $decoded = Json::decode('[' . $this->getStringContent() . ']');
43
        } catch (JsonException $exception) {
44
            throw new AnnotationParseException('"params" annotation content is invalid (invalid JSON content)');
45
        }
46
        if (! Validator::arrayVal()->each(Validator::stringType(), Validator::intType())->validate($decoded)) {
47
            throw new AnnotationParseException('"params" annotation content is invalid (must contains strings only)');
48
        }
49
        $this->parameters = $decoded;
50
    }
51
52
    /**
53
     * @return string[] The constructor parameters.
54
     */
55
    public function getParameters(): array
56
    {
57
        return $this->parameters;
58
    }
59
}
60