AbstractCallable::bag()   A
last analyzed

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
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Jaxon\App;
4
5
use Jaxon\Di\Container;
6
use Jaxon\App\Session\SessionInterface;
7
use Jaxon\App\Stash\Stash;
8
use Jaxon\App\View\ViewRenderer;
9
use Jaxon\Exception\SetupException;
10
use Jaxon\Script\JxnCall;
11
use Jaxon\Plugin\Request\CallableClass\CallableClassHelper;
12
use Jaxon\Plugin\Response\DataBag\DataBagContext;
13
use Jaxon\Request\TargetInterface;
14
use Jaxon\Response\AjaxResponse;
15
use Psr\Log\LoggerInterface;
16
17
abstract class AbstractCallable
18
{
19
    /**
20
     * @var CallableClassHelper
21
     */
22
    protected $xHelper = null;
23
24
    /**
25
     * Initialize the callable class
26
     *
27
     * @param Container $di
28
     * @param CallableClassHelper $xHelper
29
     *
30
     * @return void
31
     */
32
    abstract public function _initCallable(Container $di, CallableClassHelper $xHelper);
33
34
    /**
35
     * Get the Ajax response
36
     *
37
     * @return AjaxResponse
38
     */
39
    abstract protected function _response(): AjaxResponse;
40
41
    /**
42
     * Get the Jaxon request target
43
     *
44
     * @return TargetInterface
45
     */
46
    protected function target(): TargetInterface
47
    {
48
        return $this->xHelper->xTarget;
49
    }
50
51
    /**
52
     * Get the temp cache
53
     *
54
     * @return Stash
55
     */
56
    protected function stash(): Stash
57
    {
58
        return $this->xHelper->xStash;
59
    }
60
61
    /**
62
     * Get an instance of a Jaxon class by name
63
     *
64
     * @param string $sClassName the class name
65
     *
66
     * @return mixed
67
     * @throws SetupException
68
     */
69
    public function cl(string $sClassName)
70
    {
71
        return $this->xHelper->cl($sClassName);
72
    }
73
74
    /**
75
     * Get the js call factory.
76
     *
77
     * @param string $sClassName
78
     *
79
     * @return JxnCall
80
     */
81
    public function rq(string $sClassName = ''): JxnCall
82
    {
83
        return $this->xHelper->rq($sClassName);
84
    }
85
86
    /**
87
     * Get the logger
88
     *
89
     * @return LoggerInterface
90
     */
91
    public function logger(): LoggerInterface
92
    {
93
        return $this->xHelper->xLogger;
94
    }
95
96
    /**
97
     * Get the view renderer
98
     *
99
     * @return ViewRenderer
100
     */
101
    public function view(): ViewRenderer
102
    {
103
        return $this->xHelper->xViewRenderer;
104
    }
105
106
    /**
107
     * Get the session manager
108
     *
109
     * @return SessionInterface
110
     */
111
    public function session(): SessionInterface
112
    {
113
        return $this->xHelper->xSessionManager;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->xHelper->xSessionManager could return the type null which is incompatible with the type-hinted return Jaxon\App\Session\SessionInterface. Consider adding an additional type-check to rule them out.
Loading history...
114
    }
115
116
    /**
117
     * Get the uploaded files
118
     *
119
     * @return array
120
     */
121
    public function files(): array
122
    {
123
        return $this->xHelper->xUploadHandler->files();
0 ignored issues
show
Bug introduced by
The method files() does not exist on null. ( Ignorable by Annotation )

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

123
        return $this->xHelper->xUploadHandler->/** @scrutinizer ignore-call */ files();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
124
    }
125
126
    /**
127
     * Get a data bag.
128
     *
129
     * @param string  $sBagName
130
     *
131
     * @return DataBagContext
132
     */
133
    public function bag(string $sBagName): DataBagContext
134
    {
135
        return $this->_response()->bag($sBagName);
136
    }
137
}
138