Passed
Push — main ( 27211a...7f530d )
by Thierry
03:53
created

AttributeTrait::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Jaxon\Attributes\Tests;
4
5
use Jaxon\App\Metadata\InputData;
6
use Jaxon\App\Metadata\Metadata;
7
use Jaxon\Config\ConfigSetter;
8
use Jaxon\Plugin\Request\CallableClass\ComponentOptions;
9
use ReflectionClass;
10
11
use function Jaxon\jaxon;
12
13
trait AttributeTrait
14
{
15
    /**
16
     * Get the metadata from a given class
17
     *
18
     * @param ReflectionClass|string $xClass
19
     * @param array $aMethods
20
     * @param array $aProperties
21
     *
22
     * @return Metadata|null
23
     */
24
    public function getAttributes(ReflectionClass|string $xClass,
25
        array $aMethods = [], array $aProperties = []): ?Metadata
26
    {
27
        $xInputData = new InputData($xClass, $aMethods, $aProperties);
28
        $xMetadataReader = jaxon()->di()->getMetadataReader('attributes');
29
        return $xMetadataReader->getAttributes($xInputData);
30
    }
31
32
    /**
33
     * @param ReflectionClass $xClass
34
     *
35
     * @return ComponentOptions
36
     */
37
    public function getOptions(ReflectionClass $xClass): ComponentOptions
38
    {
39
        $xConfigSetter = new ConfigSetter();
40
        $aOptions = [
41
            'separator' => '.',
42
            'protected' => [],
43
            'functions' => [],
44
            'config' => $xConfigSetter->newConfig(['metadata' => ['format' => 'attributes']]),
45
        ];
46
        return jaxon()->cdi()->getComponentOptions($xClass, $aOptions);
47
    }
48
}
49