ExcludeAnnotation   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A saveValue() 0 3 1
A initAnnotation() 0 8 5
A parseAnnotation() 0 3 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 Jaxon\App\Metadata\Metadata;
18
use mindplay\annotations\AnnotationException;
19
20
use function count;
21
use function is_bool;
22
23
/**
24
 * Specifies if a class or method is excluded from js export.
25
 *
26
 * @usage('class' => true, 'method' => true)
27
 */
28
class ExcludeAnnotation extends AbstractAnnotation
29
{
30
    /**
31
     * @var bool
32
     */
33
    protected $bValue;
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public static function parseAnnotation($value)
39
    {
40
        return [$value === 'true' ? true : ($value === 'false' ? false : $value)];
41
    }
42
43
    /**
44
     * @inheritDoc
45
     * @throws AnnotationException
46
     */
47
    public function initAnnotation(array $properties)
48
    {
49
        if(count($properties) !== 0 && (count($properties) !== 1
50
            || !isset($properties[0]) || !is_bool($properties[0])))
51
        {
52
            throw new AnnotationException('the @exclude annotation requires a single boolean or no property');
53
        }
54
        $this->bValue = $properties[0] ?? true;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void
61
    {
62
        $xMetadata->exclude($sMethod)->setValue($this->bValue);
63
    }
64
}
65