Passed
Push — master ( cd350b...3a08d5 )
by Thierry
03:10
created

PluginTrait::getCodeGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Container\Traits;
4
5
use Jaxon\Jaxon;
6
use Jaxon\Plugin\Code\AssetManager;
7
use Jaxon\Plugin\Code\CodeGenerator;
8
use Jaxon\Plugin\PluginManager;
9
use Jaxon\Request\Plugin\Upload\UploadManager;
10
use Jaxon\Request\Plugin\Upload\UploadPlugin;
11
use Jaxon\Request\Validator;
12
use Jaxon\Response\ResponseManager;
13
use Jaxon\Response\Plugin\DataBag\DataBagPlugin;
14
use Jaxon\Response\Plugin\JQuery\JQueryPlugin;
15
use Jaxon\Utils\Config\Config;
16
use Jaxon\Utils\File\Minifier;
17
use Jaxon\Utils\Http\UriDetector;
18
use Jaxon\Utils\Template\Engine as TemplateEngine;
19
use Jaxon\Utils\Translation\Translator;
20
21
trait PluginTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait PluginTrait
Loading history...
22
{
23
    /**
24
     * Register the values into the container
25
     *
26
     * @return void
27
     */
28
    private function registerPlugins()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
29
    {
30
        // Plugin manager
31
        $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

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

68
        return $this->/** @scrutinizer ignore-call */ g(PluginManager::class);
Loading history...
69
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
70
71
    /**
72
     * Get the code generator
73
     *
74
     * @return CodeGenerator
75
     */
76
    public function getCodeGenerator(): CodeGenerator
77
    {
78
        return $this->g(CodeGenerator::class);
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
80
81
    /**
82
     * Get the upload plugin
83
     *
84
     * @return UploadPlugin|null
85
     */
86
    public function getUploadPlugin(): ?UploadPlugin
87
    {
88
        return $this->g(UploadPlugin::class);
89
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
90
}
91