Issues (2884)

src/App/App.php (16 issues)

1
<?php
2
3
/**
4
 * App.php
5
 *
6
 * Jaxon application
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2019 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
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
14
15
namespace Jaxon\App;
16
17
use Jaxon\Di\Container;
18
use Jaxon\App\Traits\AjaxSendTrait;
19
use Jaxon\App\Traits\AppTrait;
20
use Jaxon\Exception\RequestException;
21
use Jaxon\Exception\SetupException;
22
23
use function file_exists;
24
use function http_response_code;
25
use function intval;
26
use function is_array;
27
28
class App implements AppInterface
0 ignored issues
show
Missing doc comment for class App
Loading history...
29
{
30
    use AppTrait;
31
    use AjaxSendTrait;
32
33
    /**
34
     * The class constructor
35
     *
36
     * @param Container $xContainer
0 ignored issues
show
Missing parameter comment
Loading history...
37
     */
38
    public function __construct(Container $xContainer)
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
39
    {
40
        $this->initApp($xContainer);
41
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
42
43
    /**
44
     * Read config options from a config file and set up the library
45
     *
46
     * @param string $sConfigFile    The full path to the config file
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
47
     *
48
     * @return void
49
     * @throws SetupException
50
     */
51
    public function setup(string $sConfigFile)
52
    {
53
        if(!file_exists($sConfigFile))
54
        {
55
            $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
56
            throw new SetupException($sMessage);
57
        }
58
59
        // Read the config options.
60
        $aOptions = $this->xConfigManager->read($sConfigFile);
0 ignored issues
show
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...
61
        $aLibOptions = $aOptions['lib'] ?? [];
62
        $aAppOptions = $aOptions['app'] ?? [];
63
        if(!is_array($aLibOptions) || !is_array($aAppOptions))
64
        {
65
            $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
66
            throw new SetupException($sMessage);
67
        }
68
        // The bootstrap set this to false. It needs to be changed.
69
        if(!isset($aLibOptions['core']['response']['send']))
70
        {
71
            $aLibOptions['core']['response']['send'] = true;
72
        }
73
74
        $this->bootstrap()
75
            ->lib($aLibOptions)
0 ignored issues
show
Space found before object operator
Loading history...
76
            ->app($aAppOptions)
0 ignored issues
show
Space found before object operator
Loading history...
77
            ->setup();
0 ignored issues
show
Space found before object operator
Loading history...
78
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
79
80
    /**
0 ignored issues
show
Parameter $sCode should have a doc-comment as per coding-style.
Loading history...
81
     * @inheritDoc
82
     * @throws RequestException
83
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
84
    public function httpResponse(string $sCode = '200')
85
    {
86
        // Set the HTTP response code
87
        http_response_code(intval($sCode));
88
89
        // Send the response
90
        $this->sendResponse();
91
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
92
}
93