Passed
Push — master ( 46262d...417a35 )
by Thierry
02:15
created

AnnotationTrait.php$1 ➔ onChanges()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\Annotations\AnnotationReader;
6
use Jaxon\App\Config\ConfigEventManager;
7
use Jaxon\App\Config\ConfigListenerInterface;
8
use Jaxon\Plugin\AnnotationReaderInterface;
9
use Jaxon\Utils\Config\Config;
10
11
use function class_exists;
12
13
trait AnnotationTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AnnotationTrait
Loading history...
14
{
15
    /**
16
     * Register the values into the container
17
     *
18
     * @return void
19
     */
20
    private function registerAnnotations()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
21
    {
22
        // By default, register a fake annotation reader.
23
        $this->set(AnnotationReaderInterface::class, function() {
0 ignored issues
show
Bug introduced by
It seems like set() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        $this->/** @scrutinizer ignore-call */ 
24
               set(AnnotationReaderInterface::class, function() {
Loading history...
24
            return new class implements AnnotationReaderInterface
25
            {
26
                public function getAttributes(string $sClass, array $aMethods): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getAttributes()
Loading history...
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
27
                {
28
                    return [false, [], []];
29
                }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
30
            };
31
        });
32
33
        if(class_exists(AnnotationReader::class))
34
        {
35
            $sEventListenerKey = AnnotationReader::class . '\\ConfigListener';
36
            // The annotation package is installed, register the real annotation reader,
37
            // but only if the feature is activated in the config.
38
            $this->set($sEventListenerKey, function() {
39
                return new class implements ConfigListenerInterface
40
                {
41
                    public function onChanges(Config $xConfig)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onChanges()
Loading history...
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
42
                    {
43
                        if($xConfig->getOption('core.annotations.on'))
44
                        {
45
                            AnnotationReader::register(jaxon()->di());
46
                        }
47
                    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
48
49
                    public function onChange(Config $xConfig, string $sName)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onChange()
Loading history...
50
                    {
51
                        if($sName === 'core.annotations.on' && $xConfig->getOption('core.annotations.on'))
52
                        {
53
                            AnnotationReader::register(jaxon()->di());
54
                        }
55
                    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
56
                };
57
            });
58
59
            // Register the event listener
60
            $xEventManager = $this->g(ConfigEventManager::class);
0 ignored issues
show
Bug introduced by
It seems like g() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

60
            /** @scrutinizer ignore-call */ 
61
            $xEventManager = $this->g(ConfigEventManager::class);
Loading history...
61
            $xEventManager->addListener($sEventListenerKey);
62
        }
63
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
64
}
65