CallableTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 28
dl 0
loc 83
rs 10
c 3
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCallableFunctionPlugin() 0 3 1
A getCallableRegistry() 0 3 1
A registerCallables() 0 35 1
A getCallableClassPlugin() 0 3 1
A getCallableDirPlugin() 0 3 1
1
<?php
2
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\App\Config\ConfigManager;
6
use Jaxon\App\I18n\Translator;
7
use Jaxon\App\Pagination;
8
use Jaxon\Di\ClassContainer;
9
use Jaxon\Di\Container;
10
use Jaxon\Plugin\Request\CallableClass\CallableClassPlugin;
11
use Jaxon\Plugin\Request\CallableClass\CallableDirPlugin;
12
use Jaxon\Plugin\Request\CallableClass\CallableRegistry;
13
use Jaxon\Plugin\Request\CallableFunction\CallableFunctionPlugin;
14
use Jaxon\Request\Validator;
15
use Jaxon\Utils\Template\TemplateEngine;
16
17
trait CallableTrait
18
{
19
    /**
20
     * Register the values into the container
21
     *
22
     * @return void
23
     */
24
    private function registerCallables()
25
    {
26
        // Validator
27
        $this->set(Validator::class, function($di) {
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($di) {
Loading history...
28
            return new Validator($di->g(ConfigManager::class), $di->g(Translator::class));
29
        });
30
        // Callable objects registry
31
        $this->set(CallableRegistry::class, function($di) {
32
            $xRegistry = new CallableRegistry($di->g(ClassContainer::class));
33
            // Register the pagination component, but do not export to js.
34
            $xRegistry->registerClass(Pagination::class,
35
                ['excluded' => true, 'namespace' => 'Jaxon\App']);
36
            return $xRegistry;
37
        });
38
        // Callable class plugin
39
        $this->set(CallableClassPlugin::class, function($di) {
40
            $sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.class');
41
            $bDebug = $di->g(ConfigManager::class)->getOption('core.debug.on', false);
42
            return new CallableClassPlugin($sPrefix, $bDebug,
43
                $di->g(Container::class), $di->g(ClassContainer::class),
44
                $di->g(CallableRegistry::class), $di->g(TemplateEngine::class),
45
                $di->g(Translator::class), $di->g(Validator::class));
46
        });
47
        // Callable dir plugin
48
        $this->set(CallableDirPlugin::class, function($di) {
49
            return new CallableDirPlugin($di->g(ClassContainer::class),
50
                $di->g(CallableRegistry::class), $di->g(Translator::class));
51
        });
52
        // Callable function plugin
53
        $this->set(CallableFunctionPlugin::class, function($di) {
54
            $sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.function');
55
            $bDebug = $di->g(ConfigManager::class)->getOption('core.debug.on', false);
56
            return new CallableFunctionPlugin($sPrefix, $bDebug,
57
                $di->g(Container::class), $di->g(TemplateEngine::class),
58
                $di->g(Translator::class), $di->g(Validator::class));
59
        });
60
    }
61
62
    /**
63
     * Get the callable registry
64
     *
65
     * @return CallableRegistry
66
     */
67
    public function getCallableRegistry(): CallableRegistry
68
    {
69
        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

69
        return $this->/** @scrutinizer ignore-call */ g(CallableRegistry::class);
Loading history...
70
    }
71
72
    /**
73
     * Get the callable function plugin
74
     *
75
     * @return CallableFunctionPlugin
76
     */
77
    public function getCallableFunctionPlugin(): CallableFunctionPlugin
78
    {
79
        return $this->g(CallableFunctionPlugin::class);
80
    }
81
82
    /**
83
     * Get the callable class plugin
84
     *
85
     * @return CallableClassPlugin
86
     */
87
    public function getCallableClassPlugin(): CallableClassPlugin
88
    {
89
        return $this->g(CallableClassPlugin::class);
90
    }
91
92
    /**
93
     * Get the callable dir plugin
94
     *
95
     * @return CallableDirPlugin
96
     */
97
    public function getCallableDirPlugin(): CallableDirPlugin
98
    {
99
        return $this->g(CallableDirPlugin::class);
100
    }
101
}
102