Passed
Pull Request — master (#94)
by Thierry
02:19
created

RequestTrait::getParameterReader()   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\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\ParameterReader;
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\Http\UriDetector;
21
use Jaxon\Utils\Translation\Translator;
22
use Nyholm\Psr7\Factory\Psr17Factory;
23
use Nyholm\Psr7Server\ServerRequestCreator;
24
use Psr\Http\Message\ServerRequestInterface;
25
26
trait RequestTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait RequestTrait
Loading history...
27
{
28
    /**
29
     * Register the values into the container
30
     *
31
     * @return void
32
     */
33
    private function registerRequests()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
34
    {
35
        // The server request
36
        $this->set(ServerRequestInterface::class, function() {
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

36
        $this->/** @scrutinizer ignore-call */ 
37
               set(ServerRequestInterface::class, function() {
Loading history...
37
            $xRequestFactory = new Psr17Factory();
38
            $xRequestCreator = new ServerRequestCreator(
39
                $xRequestFactory, // ServerRequestFactory
40
                $xRequestFactory, // UriFactory
41
                $xRequestFactory, // UploadedFileFactory
42
                $xRequestFactory  // StreamFactory
43
            );
44
            return $xRequestCreator->fromGlobals();
45
        });
46
        // The parameter reader
47
        $this->set(ParameterReader::class, function($c) {
48
            return new ParameterReader($c->g(Container::class), $c->g(ConfigManager::class),
49
                $c->g(Translator::class), $c->g(UriDetector::class));
50
        });
51
        // Callback Manager
52
        $this->set(CallbackManager::class, function() {
53
            return new CallbackManager();
54
        });
55
        // Request Handler
56
        $this->set(RequestHandler::class, function($c) {
57
            return new RequestHandler($c->g(Container::class), $c->g(ConfigManager::class),
58
                $c->g(PluginManager::class), $c->g(ResponseManager::class), $c->g(CallbackManager::class),
59
                $c->g(ServerRequestInterface::class), $c->g(UploadHandler::class),
60
                $c->g(DataBagPlugin::class), $c->g(Translator::class));
61
        });
62
        // Request Factory
63
        $this->set(Factory::class, function($c) {
64
            return new Factory($c->g(CallableRegistry::class), $c->g(RequestFactory::class),
65
                $c->g(ParameterFactory::class));
66
        });
67
        // Factory for requests to functions
68
        $this->set(RequestFactory::class, function($c) {
69
            $sPrefix = $c->g(ConfigManager::class)->getOption('core.prefix.function');
70
            return new RequestFactory($sPrefix, $c->g(DialogFacade::class), $c->g(Paginator::class));
71
        });
72
        // Parameter Factory
73
        $this->set(ParameterFactory::class, function() {
74
            return new ParameterFactory();
75
        });
76
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
77
78
    /**
79
     * Get the request
80
     *
81
     * @return ServerRequestInterface
82
     */
83
    public function getRequest(): ServerRequestInterface
84
    {
85
        return $this->g(ServerRequestInterface::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

85
        return $this->/** @scrutinizer ignore-call */ g(ServerRequestInterface::class);
Loading history...
86
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
87
88
    /**
89
     * Get the request handler
90
     *
91
     * @return RequestHandler
92
     */
93
    public function getRequestHandler(): RequestHandler
94
    {
95
        return $this->g(RequestHandler::class);
96
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
97
98
    /**
99
     * Get the callback manager
100
     *
101
     * @return CallbackManager
102
     */
103
    public function getCallbackManager(): CallbackManager
104
    {
105
        return $this->g(CallbackManager::class);
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
107
108
    /**
109
     * Get the parameter reader
110
     *
111
     * @return ParameterReader
112
     */
113
    public function getParameterReader(): ParameterReader
114
    {
115
        return $this->g(ParameterReader::class);
116
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
117
}
118