Passed
Push — main ( 87fed9...27211a )
by Thierry
04:04
created

ExportAnnotation::saveValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * ExportAnnotation.php
5
 *
6
 * @package jaxon-annotations
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2022 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-annotations
11
 */
12
13
namespace Jaxon\Annotations\Annotation;
14
15
use Jaxon\App\Metadata\Metadata;
16
use mindplay\annotations\AnnotationException;
17
18
use function count;
19
use function is_array;
20
use function json_decode;
21
22
/**
23
 * Specifies the methods to include in js export.
24
 *
25
 * @usage('class' => true)
26
 */
27
class ExportAnnotation extends AbstractAnnotation
28
{
29
    /**
30
     * @var array
31
     */
32
    private $aMethods = [];
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public static function parseAnnotation($value)
38
    {
39
        $aParams = json_decode($value, true);
40
        return is_array($aParams) ? $aParams : [];
41
    }
42
43
    /**
44
     * @inheritDoc
45
     * @throws AnnotationException
46
     */
47
    public function initAnnotation(array $properties)
48
    {
49
        foreach(['base', 'only', 'except'] as $key)
50
        {
51
            if(isset($properties[$key]) && is_array($properties[$key]) &&
52
                count($properties[$key]) > 0)
53
            {
54
                $this->aMethods[$key] = $properties[$key];
55
            }
56
        }
57
    }
58
59
    /**
60
     * @inheritDoc
61
     */
62
    public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void
63
    {
64
        $xMetadata->export($sMethod)->setMethods($this->aMethods);
65
    }
66
}
67