Total Complexity | 6 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
19 | class AssertionAnnotation extends AbstractAnnotation |
||
20 | { |
||
21 | /** |
||
22 | * @var string|null $expected The expected value, null if none. |
||
23 | */ |
||
24 | private $expected; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | public function getType(): int |
||
30 | { |
||
31 | return AnnotationInterface::TYPE_ASSERT; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function compile(): void |
||
38 | { |
||
39 | if (strlen($this->getStringContent()) > 0) { |
||
40 | // Decode JSON content |
||
41 | try { |
||
42 | $decoded = Json::decode($this->getStringContent()); |
||
43 | } catch (JsonException $exception) { |
||
44 | throw new AnnotationParseException('"assertion" annotation content is invalid (invalid JSON content)'); |
||
45 | } |
||
46 | if (! is_string($decoded)) { |
||
47 | throw new AnnotationParseException( |
||
48 | '"assertion" annotation content is invalid (expected value must be a string)' |
||
49 | ); |
||
50 | } |
||
51 | $this->expected = $decoded; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return string The expected value, null if none. |
||
57 | */ |
||
58 | public function getExpected(): ?string |
||
61 | } |
||
62 | } |
||
63 |