Passed
Push — main ( 5ca287...d84479 )
by Thierry
05:24
created

RequestTrait::getUploadHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\App\Config\ConfigManager;
6
use Jaxon\App\Dialog\Manager\DialogCommand;
7
use Jaxon\App\I18n\Translator;
8
use Jaxon\Di\ComponentContainer;
9
use Jaxon\Di\Container;
10
use Jaxon\Plugin\Manager\PluginManager;
11
use Jaxon\Plugin\Response\Databag\DatabagPlugin;
12
use Jaxon\Request\Handler\CallbackManager;
13
use Jaxon\Request\Handler\ParameterReader;
14
use Jaxon\Request\Handler\RequestHandler;
15
use Jaxon\Request\Upload\UploadHandlerInterface;
16
use Jaxon\Response\Manager\ResponseManager;
17
use Jaxon\Script\CallFactory;
18
use Jaxon\Script\ParameterFactory;
19
use Jaxon\Utils\Http\UriDetector;
20
21
trait RequestTrait
22
{
23
    /**
24
     * Register the values into the container
25
     *
26
     * @return void
27
     */
28
    private function registerRequests(): void
29
    {
30
        // The parameter reader
31
        $this->set(ParameterReader::class, function($di) {
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(ParameterReader::class, function($di) {
Loading history...
32
            return new ParameterReader($di->g(Container::class), $di->g(Translator::class),
33
                $di->g(ConfigManager::class), $di->g(UriDetector::class));
34
        });
35
        // Callback Manager
36
        $this->set(CallbackManager::class, function($di) {
37
            return new CallbackManager($di->g(ResponseManager::class));
0 ignored issues
show
Unused Code introduced by
The call to Jaxon\Request\Handler\Ca...kManager::__construct() has too many arguments starting with $di->g(Jaxon\Response\Ma...ResponseManager::class). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            return /** @scrutinizer ignore-call */ new CallbackManager($di->g(ResponseManager::class));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
38
        });
39
        // By default, register a null upload handler
40
        $this->set(UploadHandlerInterface::class, function() {
41
            return null;
42
        });
43
        // Request Handler
44
        $this->set(RequestHandler::class, function($di) {
45
            return new RequestHandler($di->g(Container::class), $di->g(PluginManager::class),
46
                $di->g(ResponseManager::class), $di->g(CallbackManager::class),
47
                $di->g(DatabagPlugin::class));
48
        });
49
        // Requests and calls Factory
50
        $this->set(CallFactory::class, function($di) {
51
            return new CallFactory($di->g(ComponentContainer::class), $di->g(DialogCommand::class));
52
        });
53
        // Factory for function parameters
54
        $this->set(ParameterFactory::class, function() {
55
            return new ParameterFactory();
56
        });
57
    }
58
59
    /**
60
     * Get the callback manager
61
     *
62
     * @return CallbackManager
63
     */
64
    public function callback(): CallbackManager
65
    {
66
        return $this->g(CallbackManager::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

66
        return $this->/** @scrutinizer ignore-call */ g(CallbackManager::class);
Loading history...
67
    }
68
69
    /**
70
     * Get the js call factory
71
     *
72
     * @return CallFactory
73
     */
74
    public function getCallFactory(): CallFactory
75
    {
76
        return $this->g(CallFactory::class);
77
    }
78
79
    /**
80
     * Get the js call parameter factory
81
     *
82
     * @return ParameterFactory
83
     */
84
    public function getParameterFactory(): ParameterFactory
85
    {
86
        return $this->g(ParameterFactory::class);
87
    }
88
89
    /**
90
     * Get the request handler
91
     *
92
     * @return RequestHandler
93
     */
94
    public function getRequestHandler(): RequestHandler
95
    {
96
        return $this->g(RequestHandler::class);
97
    }
98
99
    /**
100
     * Get the upload handler
101
     *
102
     * @return UploadHandlerInterface|null
103
     */
104
    public function getUploadHandler(): ?UploadHandlerInterface
105
    {
106
        return $this->g(UploadHandlerInterface::class);
107
    }
108
109
    /**
110
     * Get the parameter reader
111
     *
112
     * @return ParameterReader
113
     */
114
    public function getParameterReader(): ParameterReader
115
    {
116
        return $this->g(ParameterReader::class);
117
    }
118
}
119