Passed
Push — main ( 89b529...7375af )
by Thierry
14:15 queued 11:40
created

ExportAnnotation::initAnnotation()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 4
nc 3
nop 1
dl 0
loc 8
rs 9.6111
c 1
b 0
f 0
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, 'multiple' => false, 'inherited' => 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);
0 ignored issues
show
Bug introduced by
The method export() does not exist on Jaxon\App\Metadata\Metadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        $xMetadata->/** @scrutinizer ignore-call */ 
65
                    export($sMethod)->setMethods($this->aMethods);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
    }
66
}
67