Passed
Push — master ( 6eb156...b34d93 )
by Thierry
04:25
created

App::translator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Config\ConfigManager;
17
use Jaxon\Utils\Translation\Translator;
18
use Jaxon\Exception\SetupException;
19
20
use function file_exists;
21
use function http_response_code;
22
use function intval;
23
use function is_array;
24
25
class App
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class App
Loading history...
26
{
27
    use AppTrait;
28
29
    /**
30
     * @var ConfigManager
31
     */
32
    private $xConfigManager;
33
34
    /**
35
     * @var Translator
36
     */
37
    private $xTranslator;
38
39
    /**
40
     * The class constructor
41
     *
42
     * @param Jaxon $jaxon
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
43
     * @param ConfigManager $xConfigManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
44
     * @param Translator $xTranslator
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
45
     */
46
    public function __construct(Jaxon $jaxon, ConfigManager $xConfigManager, Translator $xTranslator)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
47
    {
48
        $this->jaxon = $jaxon;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
49
        $this->xConfigManager = $xConfigManager;
50
        $this->xTranslator = $xTranslator;
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...
51
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
52
53
    /**
54
     * Set the javascript asset
55
     *
56
     * @param bool $bExport    Whether to export the js code in a file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
57
     * @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...
58
     * @param string $sUri    The URI to access the js file
59
     * @param string $sDir    The directory where to create the js file
60
     *
61
     * @return App
62
     */
63
    public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): App
64
    {
65
        $this->bootstrap()->asset($bExport, $bMinify, $sUri, $sDir);
66
        return $this;
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
68
69
    /**
70
     * Read config options from a config file and setup the library
71
     *
72
     * @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...
73
     *
74
     * @return void
75
     * @throws SetupException
76
     */
77
    public function setup(string $sConfigFile)
78
    {
79
        if(!file_exists($sConfigFile))
80
        {
81
            $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
82
            throw new SetupException($sMessage);
83
        }
84
85
        // Read the config options.
86
        $aOptions = $this->xConfigManager->read($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...
87
        $aLibOptions = $aOptions['lib'] ?? [];
88
        $aAppOptions = $aOptions['app'] ?? [];
89
        if(!is_array($aLibOptions) || !is_array($aAppOptions))
90
        {
91
            $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
92
            throw new SetupException($sMessage);
93
        }
94
        // The bootstrap set this to false. It needs to be changed.
95
        if(!isset($aLibOptions['core']['response']['send']))
96
        {
97
            $aLibOptions['core']['response']['send'] = true;
98
        }
99
100
        $this->bootstrap()
101
            ->lib($aLibOptions)
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
102
            ->app($aAppOptions)
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
103
            // ->asset(!$bIsDebug, !$bIsDebug, $sJsUrl, $sJsDir)
104
            ->setup();
0 ignored issues
show
Coding Style introduced by
Space found before object operator
Loading history...
105
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
106
107
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $sCode should have a doc-comment as per coding-style.
Loading history...
108
     * @inheritDoc
109
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
110
    public function httpResponse(string $sCode = '200')
111
    {
112
        // Set the HTTP response code
113
        http_response_code(intval($sCode));
114
        // Send the response
115
        $this->jaxon->sendResponse();
116
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
117
}
118