Passed
Push — master ( 882e76...c8b5d2 )
by Thierry
10:05
created

AppTrait::ajaxResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * AppTrait.php
5
 *
6
 * Jaxon application
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2022 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
14
15
namespace Jaxon\App\Traits;
16
17
use Jaxon\App\AppInterface;
18
use Jaxon\App\Bootstrap;
19
use Jaxon\App\Config\ConfigManager;
20
use Jaxon\App\I18n\Translator;
21
use Jaxon\Di\Container;
22
use Jaxon\Exception\RequestException;
23
use Jaxon\Plugin\Manager\PluginManager;
24
use Jaxon\Response\Manager\ResponseManager;
25
use Jaxon\Response\ResponseInterface;
26
use Psr\Container\ContainerInterface;
27
use Psr\Log\LoggerInterface;
28
29
use Closure;
30
31
trait AppTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AppTrait
Loading history...
32
{
33
    use AjaxTrait;
34
35
    /**
36
     * @param Container $xContainer
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
37
     *
38
     * @return void
39
     */
40
    private function initApp(Container $xContainer)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
41
    {
42
        $this->xContainer = $xContainer;
43
        // Set the attributes from the container
44
        $this->xConfigManager = $xContainer->g(ConfigManager::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
45
        $this->xResponseManager = $xContainer->g(ResponseManager::class);
46
        $this->xPluginManager = $xContainer->g(PluginManager::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
47
        $this->xTranslator = $xContainer->g(Translator::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
48
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
49
50
    /**
51
     * Get the Jaxon application bootstrapper.
52
     *
53
     * @return Bootstrap
54
     */
55
    protected function bootstrap(): Bootstrap
56
    {
57
        return $this->di()->getBootstrap();
58
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
59
60
    /**
61
     * Set the ajax endpoint URI
62
     *
63
     * @param string $sUri    The ajax endpoint URI
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
64
     *
65
     * @return void
66
     */
67
    public function uri(string $sUri)
68
    {
69
        $this->setOption('core.request.uri', $sUri);
70
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
71
72
    /**
73
     * Set the javascript asset
74
     *
75
     * @param bool $bExport    Whether to export the js code in a file
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
76
     * @param bool $bMinify    Whether to minify the exported js file
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
77
     * @param string $sUri    The URI to access the js file
78
     * @param string $sDir    The directory where to create the js file
79
     *
80
     * @return void
81
     */
82
    public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = '')
83
    {
84
        $this->bootstrap()->asset($bExport, $bMinify, $sUri, $sDir);
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
86
87
    /**
88
     * Read the options from the file, if provided, and return the config
89
     *
90
     * @param string $sConfigFile The full path to the config file
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
91
     * @param string $sConfigSection The section of the config file to be loaded
92
     *
93
     * @return ConfigManager
94
     */
95
    public function config(string $sConfigFile = '', string $sConfigSection = ''): ConfigManager
0 ignored issues
show
Unused Code introduced by
The parameter $sConfigSection is not used and could be removed. ( Ignorable by Annotation )

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

95
    public function config(string $sConfigFile = '', /** @scrutinizer ignore-unused */ string $sConfigSection = ''): ConfigManager

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $sConfigFile is not used and could be removed. ( Ignorable by Annotation )

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

95
    public function config(/** @scrutinizer ignore-unused */ string $sConfigFile = '', string $sConfigSection = ''): ConfigManager

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        return $this->xConfigManager;
98
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
99
100
    /**
101
     * Get the HTTP response
102
     *
103
     * @param string $sCode    The HTTP response code
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
104
     *
105
     * @return mixed
106
     */
107
    abstract public function httpResponse(string $sCode = '200');
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
108
109
    /**
110
     * Get the Jaxon ajax response
111
     *
112
     * @return ResponseInterface
113
     */
114
    public function ajaxResponse(): ResponseInterface
115
    {
116
        return $this->xResponseManager->getResponse();
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
118
119
    /**
120
     * Process an incoming Jaxon request, and return the response.
121
     *
122
     * @return void
123
     * @throws RequestException
124
     */
125
    public function processRequest()
126
    {
127
        $this->di()->getRequestHandler()->processRequest();
128
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
129
130
    /**
131
     * Set the container provided by the integrated framework
132
     *
133
     * @param ContainerInterface $xContainer    The container implementation
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
134
     *
135
     * @return void
136
     */
137
    public function setContainer(ContainerInterface $xContainer)
138
    {
139
        $this->di()->setContainer($xContainer);
140
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
141
142
    /**
143
     * Add a view renderer with an id
144
     *
145
     * @param string $sRenderer    The renderer name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
146
     * @param string $sExtension    The extension to append to template names
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
147
     * @param Closure $xClosure    A closure to create the view instance
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
148
     *
149
     * @return void
150
     */
151
    public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure)
152
    {
153
        $this->di()->getViewRenderer()->setDefaultRenderer($sRenderer, $sExtension, $xClosure);
154
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
155
156
    /**
157
     * Set the logger.
158
     *
159
     * @param LoggerInterface $logger
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
160
     *
161
     * @return void
162
     */
163
    public function setLogger(LoggerInterface $logger)
164
    {
165
        $this->di()->setLogger($logger);
166
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
167
168
    /**
169
     * Set the session manager
170
     *
171
     * @param Closure $xClosure    A closure to create the session manager instance
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
172
     *
173
     * @return void
174
     */
175
    public function setSessionManager(Closure $xClosure)
176
    {
177
        $this->di()->setSessionManager($xClosure);
178
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
179
}
180