Passed
Push — main ( 5a6d0d...5b503b )
by Thierry
05:42 queued 04:00
created

DatabagAnnotation::saveValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * DatabagAnnotation.php
5
 *
6
 * Jaxon annotation for data bags.
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_string;
22
use function preg_split;
23
24
/**
25
 * Specifies a data bag stored in the browser and included in ajax requests to a method.
26
 *
27
 * @usage('class' => true, 'method' => true, 'multiple' => true, 'inherited' => true)
28
 */
29
class DatabagAnnotation extends AbstractAnnotation
30
{
31
    /**
32
     * The data bag name
33
     *
34
     * @var string
35
     */
36
    protected $sName = '';
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public static function parseAnnotation($value)
42
    {
43
        $aParams = preg_split('/[\s]+/', $value, 2);
44
        return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]];
45
    }
46
47
    /**
48
     * @inheritDoc
49
     * @throws AnnotationException
50
     */
51
    public function initAnnotation(array $properties)
52
    {
53
        if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name']))
54
        {
55
            throw new AnnotationException('The @databag annotation requires a property "name" of type string');
56
        }
57
        $this->sName = $properties['name'];
58
    }
59
60
    /**
61
     * @inheritDoc
62
     */
63
    public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void
64
    {
65
        $xMetadata->databag($sMethod)->addValue($this->sName);
0 ignored issues
show
Bug introduced by
The method databag() 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

65
        $xMetadata->/** @scrutinizer ignore-call */ 
66
                    databag($sMethod)->addValue($this->sName);

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...
66
    }
67
}
68