Passed
Push — master ( dc0218...f79a4b )
by Thierry
02:43
created

App::processRequest()   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
 * App.php - Jaxon application
5
 *
6
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2019 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
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...
12
13
namespace Jaxon\App;
14
15
use Jaxon\Jaxon;
16
use Jaxon\Exception\SetupException;
17
use Jaxon\Response\Manager as ResponseManager;
18
use Jaxon\Utils\Config\Reader as ConfigReader;
19
use Jaxon\Utils\Translation\Translator;
20
21
use function intval;
22
use function file_exists;
23
use function is_array;
24
use function http_response_code;
25
26
class App
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class App
Loading history...
27
{
28
    use \Jaxon\Features\App;
29
30
    /**
31
     * @var ResponseManager
32
     */
33
    private $xResponseManager;
34
35
    /**
36
     * @var ConfigReader
37
     */
38
    private $xConfigReader;
39
40
    /**
41
     * @var Translator
42
     */
43
    private $xTranslator;
44
45
    /**
46
     * The class constructor
47
     *
48
     * @param Jaxon $jaxon
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
49
     * @param ResponseManager $xResponseManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
50
     * @param ConfigReader $xConfigReader
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
51
     * @param Translator $xTranslator
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
52
     */
53
    public function __construct(Jaxon $jaxon, ResponseManager $xResponseManager,
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
54
        ConfigReader $xConfigReader, Translator $xTranslator)
55
    {
56
        $this->jaxon = $jaxon;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
57
        $this->xResponseManager = $xResponseManager;
58
        $this->xConfigReader = $xConfigReader;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
59
        $this->xTranslator = $xTranslator;
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...
60
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
61
62
    /**
63
     * @return Translator
64
     */
65
    protected function translator(): Translator
66
    {
67
        return $this->xTranslator;
68
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
69
70
    /**
71
     * Read config options from a config file and setup the library
72
     *
73
     * @param string $sConfigFile    The full path to the config file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
74
     *
75
     * @return void
76
     * @throws SetupException
77
     */
78
    public function setup(string $sConfigFile)
79
    {
80
        if(!file_exists($sConfigFile))
81
        {
82
            $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
83
            throw new SetupException($sMessage);
84
        }
85
86
        // Read the config options.
87
        $aOptions = $this->jaxon->readConfig($sConfigFile);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
88
        $aLibOptions = $aOptions['lib'] ?? [];
89
        $aAppOptions = $aOptions['app'] ?? [];
90
        if(!is_array($aLibOptions) || !is_array($aAppOptions))
91
        {
92
            $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
93
            throw new SetupException($sMessage);
94
        }
95
96
        $this->bootstrap()
97
            ->lib($aLibOptions)
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
98
            ->app($aAppOptions)
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
99
            // ->uri($sUri)
100
            // ->js(!$bIsDebug, $sJsUrl, $sJsDir, !$bIsDebug)
101
            ->setup();
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
102
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
103
104
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $sCode should have a doc-comment as per coding-style.
Loading history...
105
     * @inheritDoc
106
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
107
    public function httpResponse(string $sCode = '200')
108
    {
109
        // Set the HTTP response code
110
        http_response_code(intval($sCode));
111
        // Send the response
112
        $this->xResponseManager->sendOutput();
113
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
114
}
115