Passed
Push — main ( 5a0ee7...80b454 )
by Thierry
09:26
created

Export::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Export.php
5
 *
6
 * Jaxon attribute.
7
 * Specifies the methods to include in js export.
8
 *
9
 * @package jaxon-attributes
10
 * @author Thierry Feuzeu <[email protected]>
11
 * @copyright 2024 Thierry Feuzeu <[email protected]>
12
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
13
 * @link https://github.com/jaxon-php/jaxon-core
14
 */
15
16
namespace Jaxon\Attributes\Attribute;
17
18
use Jaxon\App\Metadata\Metadata;
19
use Attribute;
20
21
use function count;
22
23
#[Attribute(Attribute::TARGET_CLASS)]
24
class Export extends AbstractAttribute
25
{
26
    /**
27
     * @param array|null $base = null
28
     * @param array|null $only = null
29
     * @param array|null $except = null
30
     */
31
    public function __construct(private array|null $base = null,
32
        private array|null $only = null, private array|null $except = null)
33
    {}
34
35
    /**
36
     * @inheritDoc
37
     */
38
    public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void
39
    {
40
        $aMethods = [];
41
        foreach(['base', 'only', 'except'] as $key)
42
        {
43
            if($this->$key !== null && count($this->$key) > 0)
44
            {
45
                $aMethods[$key] = $this->$key;
46
            }
47
        }
48
49
        $xMetadata->export($sMethod)->setMethods($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

49
        $xMetadata->/** @scrutinizer ignore-call */ 
50
                    export($sMethod)->setMethods($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...
50
    }
51
}
52