Passed
Push — master ( ddad46...023bbd )
by Thierry
02:38
created

AppTrait::setSessionManager()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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 Closure;
18
use Jaxon\App\AppInterface;
19
use Jaxon\App\Bootstrap;
20
use Jaxon\App\Config\ConfigManager;
21
use Jaxon\App\I18n\Translator;
22
use Jaxon\Di\Container;
23
use Jaxon\Exception\RequestException;
24
use Jaxon\Plugin\Manager\PluginManager;
25
use Jaxon\Response\Manager\ResponseManager;
26
use Psr\Container\ContainerInterface;
27
28
trait AppTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AppTrait
Loading history...
29
{
30
    use AjaxTrait {
31
        getResponse as protected ajaxResponse;
32
    }
33
34
    /**
35
     * @param Container $xContainer
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
36
     *
37
     * @return void
38
     */
39
    private function initApp(Container $xContainer)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
40
    {
41
        $this->xContainer = $xContainer;
42
        // Set the attributes from the container
43
        $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...
44
        $this->xResponseManager = $xContainer->g(ResponseManager::class);
45
        $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...
46
        $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...
47
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
48
49
    /**
50
     * Get the Jaxon application bootstrapper.
51
     *
52
     * @return Bootstrap
53
     */
54
    protected function bootstrap(): Bootstrap
55
    {
56
        return $this->di()->getBootstrap();
57
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
58
59
    /**
60
     * Set the ajax endpoint URI
61
     *
62
     * @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...
63
     *
64
     * @return void
65
     */
66
    public function uri(string $sUri)
67
    {
68
        $this->setOption('core.request.uri', $sUri);
69
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
70
71
    /**
72
     * Set the javascript asset
73
     *
74
     * @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...
75
     * @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...
76
     * @param string $sUri    The URI to access the js file
77
     * @param string $sDir    The directory where to create the js file
78
     *
79
     * @return AppInterface
80
     */
81
    public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): AppInterface
82
    {
83
        $this->bootstrap()->asset($bExport, $bMinify, $sUri, $sDir);
84
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\App\Traits\AppTrait which is incompatible with the type-hinted return Jaxon\App\AppInterface.
Loading history...
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
86
87
    /**
88
     * Get the HTTP response
89
     *
90
     * @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...
91
     *
92
     * @return mixed
93
     */
94
    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...
95
96
    /**
97
     * Process an incoming Jaxon request, and return the response.
98
     *
99
     * @return mixed
100
     * @throws RequestException
101
     */
102
    public function processRequest()
103
    {
104
        // Process the jaxon request
105
        $this->di()->getRequestHandler()->processRequest();
106
107
        // Return the response to the request
108
        return $this->httpResponse();
109
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
110
111
    /**
112
     * Set the container provided by the integrated framework
113
     *
114
     * @param ContainerInterface $xContainer    The container implementation
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
115
     *
116
     * @return void
117
     */
118
    public function setContainer(ContainerInterface $xContainer)
119
    {
120
        $this->di()->setContainer($xContainer);
121
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
122
123
    /**
124
     * Add a view namespace, and set the corresponding renderer.
125
     *
126
     * @param string $sNamespace    The namespace name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
127
     * @param string $sDirectory    The namespace directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
128
     * @param string $sExtension    The extension to append to template names
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
129
     * @param string $sRenderer    The corresponding renderer name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
130
     *
131
     * @return void
132
     */
133
    public function addViewNamespace(string $sNamespace, string $sDirectory, string $sExtension, string $sRenderer)
134
    {
135
        $this->di()->getViewRenderer()->addNamespace($sNamespace, $sDirectory, $sExtension, $sRenderer);
136
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
137
138
    /**
139
     * Add a view renderer with an id
140
     *
141
     * @param string $sId    The unique identifier of the view renderer
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 4 found
Loading history...
142
     * @param Closure $xClosure    A closure to create the view instance
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
143
     *
144
     * @return void
145
     */
146
    public function addViewRenderer(string $sId, Closure $xClosure)
147
    {
148
        $this->di()->getViewRenderer()->addRenderer($sId, $xClosure);
149
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
150
151
    /**
152
     * Set the session manager
153
     *
154
     * @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...
155
     *
156
     * @return void
157
     */
158
    public function setSessionManager(Closure $xClosure)
159
    {
160
        $this->di()->setSessionManager($xClosure);
161
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
162
}
163