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

PluginTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerPlugins() 0 33 3
A getPluginManager() 0 3 1
A getCodeGenerator() 0 3 1
A getUploadHandler() 0 3 1
A getJQueryPlugin() 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\Jaxon;
6
use Jaxon\Config\ConfigManager;
7
use Jaxon\Di\Container;
8
use Jaxon\Plugin\Code\AssetManager;
9
use Jaxon\Plugin\Code\CodeGenerator;
10
use Jaxon\Plugin\Manager\PluginManager;
11
use Jaxon\Request\Handler\UploadHandler;
12
use Jaxon\Request\Upload\UploadManager;
13
use Jaxon\Request\Validator;
14
use Jaxon\Response\Plugin\DataBag\DataBagPlugin;
15
use Jaxon\Response\Plugin\JQuery\JQueryPlugin;
16
use Jaxon\Response\ResponseManager;
17
use Jaxon\Ui\View\ViewManager;
18
use Jaxon\Utils\File\FileMinifier;
0 ignored issues
show
Bug introduced by
The type Jaxon\Utils\File\FileMinifier 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...
19
use Jaxon\Utils\Http\UriDetector;
20
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...
21
use Jaxon\Utils\Translation\Translator;
22
23
trait PluginTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait PluginTrait
Loading history...
24
{
25
    /**
26
     * Register the values into the container
27
     *
28
     * @return void
29
     */
30
    private function registerPlugins()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
31
    {
32
        // Plugin manager
33
        $this->set(PluginManager::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

33
        $this->/** @scrutinizer ignore-call */ 
34
               set(PluginManager::class, function($c) {
Loading history...
34
            return new PluginManager($c->g(Container::class), $c->g(ConfigManager::class),
35
                $c->g(ViewManager::class), $c->g(CodeGenerator::class), $c->g(Translator::class));
36
        });
37
        // Code Generation
38
        $this->set(AssetManager::class, function($c) {
39
            return new AssetManager($c->g(ConfigManager::class), $c->g(UriDetector::class), $c->g(FileMinifier::class));
40
        });
41
        $this->set(CodeGenerator::class, function($c) {
42
            $sVersion = $c->g(Jaxon::class)->getVersion();
43
            return new CodeGenerator($sVersion, $c->g(Container::class),
44
                $c->g(TemplateEngine::class), $c->g(AssetManager::class));
45
        });
46
        // File upload manager
47
        $this->set(UploadManager::class, function($c) {
48
            return new UploadManager($c->g(ConfigManager::class), $c->g(Validator::class), $c->g(Translator::class));
49
        });
50
        // File upload plugin
51
        $this->set(UploadHandler::class, function($c) {
52
            return !$c->g(ConfigManager::class)->getOption('core.upload.enabled') ? null :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
53
                new UploadHandler($c->g(UploadManager::class), $c->g(ResponseManager::class), $c->g(Translator::class));
54
        });
55
        // JQuery response plugin
56
        $this->set(JQueryPlugin::class, function($c) {
57
            $jQueryNs = $c->g(ConfigManager::class)->getOption('core.jquery.no_conflict', false) ? 'jQuery' : '$';
58
            return new JQueryPlugin($jQueryNs);
59
        });
60
        // DataBagPlugin response plugin
61
        $this->set(DataBagPlugin::class, function() {
62
            return new DataBagPlugin();
63
        });
64
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
65
66
    /**
67
     * Get the plugin manager
68
     *
69
     * @return PluginManager
70
     */
71
    public function getPluginManager(): PluginManager
72
    {
73
        return $this->g(PluginManager::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

73
        return $this->/** @scrutinizer ignore-call */ g(PluginManager::class);
Loading history...
74
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
75
76
    /**
77
     * Get the code generator
78
     *
79
     * @return CodeGenerator
80
     */
81
    public function getCodeGenerator(): CodeGenerator
82
    {
83
        return $this->g(CodeGenerator::class);
84
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
85
86
    /**
87
     * Get the upload handler
88
     *
89
     * @return UploadHandler|null
90
     */
91
    public function getUploadHandler(): ?UploadHandler
92
    {
93
        return $this->g(UploadHandler::class);
94
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
95
96
    /**
97
     * Get the jQuery plugin
98
     *
99
     * @return JQueryPlugin
100
     */
101
    public function getJQueryPlugin(): JQueryPlugin
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
102
    {
103
        return $this->g(JQueryPlugin::class);
104
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
105
}
106