Passed
Push — main ( fe5adf...e99a91 )
by Thierry
01:50
created

ExcludeAnnotation::parseAnnotation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * ExcludeAnnotation.php
5
 *
6
 * Jaxon annotation for exclude classes or methods from js export.
7
 *
8
 * @package jaxon-annotations
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2022 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-annotations
13
 */
14
15
namespace Jaxon\Annotations\Annotation;
16
17
use mindplay\annotations\AnnotationException;
18
19
use function count;
20
use function is_bool;
21
22
/**
23
 * Specifies if a class or method is excluded from js export.
24
 *
25
 * @usage('class' => true, 'method'=>true)
26
 */
27
class ExcludeAnnotation extends AbstractAnnotation
28
{
29
    /**
30
     * The name of the upload field
31
     *
32
     * @var bool
33
     */
34
    protected $bValue;
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public static function parseAnnotation($value)
40
    {
41
        if($value === 'true')
42
        {
43
            return [true];
44
        }
45
        if($value === 'false')
46
        {
47
            return [false];
48
        }
49
        return [$value];
50
    }
51
52
    /**
53
     * @inheritDoc
54
     * @throws AnnotationException
55
     */
56
    public function initAnnotation(array $properties)
57
    {
58
        if(count($properties) !== 0 &&
59
            (count($properties) !== 1 || !isset($properties[0]) || !is_bool($properties[0])))
60
        {
61
            throw new AnnotationException('the @exclude annotation requires a single boolean or no property');
62
        }
63
        $this->bValue = $properties[0] ?? true;
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    public function getName(): string
70
    {
71
        return 'protected';
72
    }
73
74
    /**
75
     * @inheritDoc
76
     */
77
    public function getValue()
78
    {
79
        return $this->bValue;
80
    }
81
}
82