Passed
Push — master ( 291d13...46262d )
by Thierry
02:24
created

CallableTrait::getCallableRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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

65
        return $this->/** @scrutinizer ignore-call */ g(CallableRegistry::class);
Loading history...
66
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
67
68
    /**
69
     * Get the callable repository
70
     *
71
     * @return CallableRepository
72
     */
73
    public function getCallableRepository(): CallableRepository
74
    {
75
        return $this->g(CallableRepository::class);
76
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
77
78
    /**
79
     * Get the callable function plugin
80
     *
81
     * @return CallableFunctionPlugin
82
     */
83
    public function getCallableFunctionPlugin(): CallableFunctionPlugin
84
    {
85
        return $this->g(CallableFunctionPlugin::class);
86
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
87
88
    /**
89
     * Get the callable class plugin
90
     *
91
     * @return CallableClassPlugin
92
     */
93
    public function getCallableClassPlugin(): CallableClassPlugin
94
    {
95
        return $this->g(CallableClassPlugin::class);
96
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
97
98
    /**
99
     * Get the callable dir plugin
100
     *
101
     * @return CallableDirPlugin
102
     */
103
    public function getCallableDirPlugin(): CallableDirPlugin
104
    {
105
        return $this->g(CallableDirPlugin::class);
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
107
}
108