ExcludeAnnotation   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A initAnnotation() 0 8 5
A getValue() 0 3 1
A parseAnnotation() 0 11 3
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
     * @var bool
31
     */
32
    protected $bValue;
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public static function parseAnnotation($value)
38
    {
39
        if($value === 'true')
40
        {
41
            return [true];
42
        }
43
        if($value === 'false')
44
        {
45
            return [false];
46
        }
47
        return [$value];
48
    }
49
50
    /**
51
     * @inheritDoc
52
     * @throws AnnotationException
53
     */
54
    public function initAnnotation(array $properties)
55
    {
56
        if(count($properties) !== 0 &&
57
            (count($properties) !== 1 || !isset($properties[0]) || !is_bool($properties[0])))
58
        {
59
            throw new AnnotationException('the @exclude annotation requires a single boolean or no property');
60
        }
61
        $this->bValue = $properties[0] ?? true;
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function getName(): string
68
    {
69
        return 'protected';
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function getValue()
76
    {
77
        return $this->bValue;
78
    }
79
}
80