Passed
Push — master ( 023bbd...40fcac )
by Thierry
02:15
created

AppTrait::addViewRenderer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
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 Psr\Container\ContainerInterface;
26
27
use Closure;
28
29
trait AppTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AppTrait
Loading history...
30
{
31
    use AjaxTrait {
32
        AjaxTrait::getResponse as public ajaxResponse;
33
    }
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 AppInterface
81
     */
82
    public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): AppInterface
83
    {
84
        $this->bootstrap()->asset($bExport, $bMinify, $sUri, $sDir);
85
        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...
86
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
87
88
    /**
89
     * Get the HTTP response
90
     *
91
     * @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...
92
     *
93
     * @return mixed
94
     */
95
    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...
96
97
    /**
98
     * Process an incoming Jaxon request, and return the response.
99
     *
100
     * @return mixed
101
     * @throws RequestException
102
     */
103
    public function processRequest()
104
    {
105
        // Process the jaxon request
106
        $this->di()->getRequestHandler()->processRequest();
107
108
        // Return the response to the request
109
        return $this->httpResponse();
110
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
111
112
    /**
113
     * Set the container provided by the integrated framework
114
     *
115
     * @param ContainerInterface $xContainer    The container implementation
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
116
     *
117
     * @return void
118
     */
119
    public function setContainer(ContainerInterface $xContainer)
120
    {
121
        $this->di()->setContainer($xContainer);
122
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
123
124
    /**
125
     * Add a view renderer with an id
126
     *
127
     * @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...
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...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
129
     * @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...
130
     *
131
     * @return void
132
     */
133
    public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure)
134
    {
135
        $xViewRenderer = $this->di->getViewRenderer();
136
        $xViewRenderer->addNamespace('default', '', $sExtension, $sRenderer);
137
        $xViewRenderer->addRenderer($sRenderer, $xClosure);
138
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
139
140
    /**
141
     * Set the session manager
142
     *
143
     * @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...
144
     *
145
     * @return void
146
     */
147
    public function setSessionManager(Closure $xClosure)
148
    {
149
        $this->di()->setSessionManager($xClosure);
150
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
151
}
152