Passed
Push — master ( bf2aee...a6dc35 )
by Thierry
02:22
created

CallableTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCallableFunctionPlugin() 0 3 1
A registerCallables() 0 32 1
A getClassRegistry() 0 3 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\Config\ConfigManager;
6
use Jaxon\Di\Container;
7
use Jaxon\Request\Handler\RequestHandler;
8
use Jaxon\Request\Plugin\CallableClass\CallableRegistry;
9
use Jaxon\Request\Plugin\CallableClass\CallableRepository;
10
use Jaxon\Request\Plugin\CallableClass\CallableClassPlugin;
11
use Jaxon\Request\Plugin\CallableClass\CallableDirPlugin;
12
use Jaxon\Request\Plugin\CallableFunction\CallableFunctionPlugin;
13
use Jaxon\Request\Validator;
14
use Jaxon\Response\ResponseManager;
15
use Jaxon\Utils\Template\TemplateEngine;
0 ignored issues
show
Bug introduced by
The type Jaxon\Utils\Template\TemplateEngine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Jaxon\Utils\Translation\Translator;
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
        // Validator
28
        $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

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

67
        return $this->/** @scrutinizer ignore-call */ g(CallableRegistry::class);
Loading history...
68
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
69
70
    /**
71
     * Get the callable function plugin
72
     *
73
     * @return CallableFunctionPlugin
74
     */
75
    public function getCallableFunctionPlugin(): CallableFunctionPlugin
76
    {
77
        return $this->g(CallableFunctionPlugin::class);
78
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
79
}
80