Passed
Push — master ( ba3204...969249 )
by Thierry
02:16
created

CallableTrait.php$0 ➔ getCallableFunctionPlugin()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
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\App\Config\ConfigManager;
6
use Jaxon\App\I18n\Translator;
7
use Jaxon\Di\Container;
8
use Jaxon\Plugin\AnnotationReaderInterface;
9
use Jaxon\Plugin\Request\CallableClass\CallableClassPlugin;
10
use Jaxon\Plugin\Request\CallableClass\CallableRegistry;
11
use Jaxon\Plugin\Request\CallableClass\CallableRepository;
12
use Jaxon\Plugin\Request\CallableDir\CallableDirPlugin;
13
use Jaxon\Plugin\Request\CallableFunction\CallableFunctionPlugin;
14
use Jaxon\Request\Handler\ParameterReader;
15
use Jaxon\Request\Validator;
16
use Jaxon\Utils\Template\TemplateEngine;
17
18
trait CallableTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait CallableTrait
Loading history...
19
{
20
    /**
21
     * Register the values into the container
22
     *
23
     * @return void
24
     */
25
    private function registerCallables()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
26
    {
27
        // By default, register a fake annotation reader.
28
        $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

28
        $this->/** @scrutinizer ignore-call */ 
29
               set(AnnotationReaderInterface::class, function() {
Loading history...
29
            return new class implements AnnotationReaderInterface
30
            {
31
                public function getAttributes(string $sClass, array $aMethods = [], array $aProperties = []): 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...
32
                {
33
                    return [false, [], []];
34
                }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
35
            };
36
        });
37
        // Validator
38
        $this->set(Validator::class, function($c) {
39
            return new Validator($c->g(ConfigManager::class), $c->g(Translator::class));
40
        });
41
        // Callable objects repository
42
        $this->set(CallableRepository::class, function($c) {
43
            return new CallableRepository($c->g(Container::class), $c->g(Translator::class));
44
        });
45
        // Callable objects registry
46
        $this->set(CallableRegistry::class, function($c) {
47
            return new CallableRegistry($c->g(Container::class),
48
                $c->g(CallableRepository::class), $c->g(Translator::class));
49
        });
50
        // Callable class plugin
51
        $this->set(CallableClassPlugin::class, function($c) {
52
            $sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.class');
53
            return new CallableClassPlugin($sPrefix, $c->g(Container::class), $c->g(ParameterReader::class),
54
                $c->g(CallableRegistry::class), $c->g(CallableRepository::class),
55
                $c->g(TemplateEngine::class), $c->g(Translator::class), $c->g(Validator::class));
56
        });
57
        // Callable dir plugin
58
        $this->set(CallableDirPlugin::class, function($c) {
59
            return new CallableDirPlugin($c->g(CallableRegistry::class), $c->g(Translator::class));
60
        });
61
        // Callable function plugin
62
        $this->set(CallableFunctionPlugin::class, function($c) {
63
            $sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.function');
64
            return new CallableFunctionPlugin($sPrefix, $c->g(ParameterReader::class),
65
                $c->g(TemplateEngine::class), $c->g(Translator::class), $c->g(Validator::class));
66
        });
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
68
69
    /**
70
     * Get the callable registry
71
     *
72
     * @return CallableRegistry
73
     */
74
    public function getCallableRegistry(): CallableRegistry
75
    {
76
        return $this->g(CallableRegistry::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

76
        return $this->/** @scrutinizer ignore-call */ g(CallableRegistry::class);
Loading history...
77
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
78
79
    /**
80
     * Get the callable repository
81
     *
82
     * @return CallableRepository
83
     */
84
    public function getCallableRepository(): CallableRepository
85
    {
86
        return $this->g(CallableRepository::class);
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
88
89
    /**
90
     * Get the callable function plugin
91
     *
92
     * @return CallableFunctionPlugin
93
     */
94
    public function getCallableFunctionPlugin(): CallableFunctionPlugin
95
    {
96
        return $this->g(CallableFunctionPlugin::class);
97
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
98
99
    /**
100
     * Get the callable class plugin
101
     *
102
     * @return CallableClassPlugin
103
     */
104
    public function getCallableClassPlugin(): CallableClassPlugin
105
    {
106
        return $this->g(CallableClassPlugin::class);
107
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
108
109
    /**
110
     * Get the callable dir plugin
111
     *
112
     * @return CallableDirPlugin
113
     */
114
    public function getCallableDirPlugin(): CallableDirPlugin
115
    {
116
        return $this->g(CallableDirPlugin::class);
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
118
}
119