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

RequestTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerRequests() 0 30 1
A getRequestHandler() 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\Plugin\Manager\PluginManager;
8
use Jaxon\Request\Factory\Factory;
9
use Jaxon\Request\Factory\ParameterFactory;
10
use Jaxon\Request\Factory\RequestFactory;
11
use Jaxon\Request\Handler\ArgumentManager;
12
use Jaxon\Request\Handler\CallbackManager;
13
use Jaxon\Request\Handler\RequestHandler;
14
use Jaxon\Request\Handler\UploadHandler;
15
use Jaxon\Request\Plugin\CallableClass\CallableRegistry;
16
use Jaxon\Response\Plugin\DataBag\DataBagPlugin;
17
use Jaxon\Response\ResponseManager;
18
use Jaxon\Ui\Dialogs\DialogFacade;
19
use Jaxon\Ui\Pagination\Paginator;
20
use Jaxon\Utils\Translation\Translator;
21
22
trait RequestTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait RequestTrait
Loading history...
23
{
24
    /**
25
     * Register the values into the container
26
     *
27
     * @return void
28
     */
29
    private function registerRequests()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
30
    {
31
        // Argument Manager
32
        $this->set(ArgumentManager::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

32
        $this->/** @scrutinizer ignore-call */ 
33
               set(ArgumentManager::class, function($c) {
Loading history...
33
            return new ArgumentManager($c->g(ConfigManager::class), $c->g(Translator::class));
34
        });
35
        // Callback Manager
36
        $this->set(CallbackManager::class, function() {
37
            return new CallbackManager();
38
        });
39
        // Request Handler
40
        $this->set(RequestHandler::class, function($c) {
41
            return new RequestHandler($c->g(Container::class), $c->g(ConfigManager::class),
42
                $c->g(ArgumentManager::class), $c->g(PluginManager::class), $c->g(ResponseManager::class),
43
                $c->g(CallbackManager::class), $c->g(UploadHandler::class), $c->g(DataBagPlugin::class),
44
                $c->g(Translator::class));
45
        });
46
        // Request Factory
47
        $this->set(Factory::class, function($c) {
48
            return new Factory($c->g(CallableRegistry::class), $c->g(RequestFactory::class),
49
                $c->g(ParameterFactory::class));
50
        });
51
        // Factory for requests to functions
52
        $this->set(RequestFactory::class, function($c) {
53
            $sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.function');
54
            return new RequestFactory($sPrefix, $c->g(DialogFacade::class), $c->g(Paginator::class));
55
        });
56
        // Parameter Factory
57
        $this->set(ParameterFactory::class, function() {
58
            return new ParameterFactory();
59
        });
60
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
61
62
    /**
63
     * Get the request handler
64
     *
65
     * @return RequestHandler
66
     */
67
    public function getRequestHandler(): RequestHandler
68
    {
69
        return $this->g(RequestHandler::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(RequestHandler::class);
Loading history...
70
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
71
}
72