Completed
Push — master ( f42a52...0a9499 )
by Thierry
02:50 queued 01:16
created

App::setup()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 9
nop 1
dl 0
loc 29
rs 8.8337
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * App.php - Jaxon application
5
 *
6
 * @package jaxon-core
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
 */
12
13
namespace Jaxon\App;
14
15
use Jaxon\Utils\Session\Manager as SessionManager;
16
use Exception;
17
18
class App
19
{
20
    use \Jaxon\Features\App;
21
22
    /**
23
     * Read config options from a config file and setup the library
24
     *
25
     * @param string        $sConfigFile        The full path to the config file
26
     *
27
     * @return Jaxon
28
     */
29
    public function setup($sConfigFile)
30
    {
31
        if(!file_exists($sConfigFile))
32
        {
33
            throw new Exception("Unable to find config file at $sConfigFile");
34
        }
35
36
        // Read the config options.
37
        $aOptions = jaxon()->config()->read($sConfigFile);
38
        $aLibOptions = key_exists('lib', $aOptions) ? $aOptions['lib'] : [];
39
        $aAppOptions = key_exists('app', $aOptions) ? $aOptions['app'] : [];
40
41
        if(!is_array($aLibOptions) || !is_array($aAppOptions))
42
        {
43
            throw new Exception("Unexpected content in config file at $sConfigFile");
44
        }
45
46
        // Set the session manager
47
        jaxon()->di()->setSessionManager(function () {
0 ignored issues
show
Documentation introduced by
function () { return...ls\Session\Manager(); } is of type object<Closure>, but the function expects a object<Jaxon\Utils\DI\Closure>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
            return new SessionManager();
49
        });
50
51
        $this->bootstrap()
52
            ->lib($aLibOptions)
53
            ->app($aAppOptions)
54
            // ->uri($sUri)
55
            // ->js(!$isDebug, $sJsUrl, $sJsDir, !$isDebug)
56
            ->run(true);
0 ignored issues
show
Unused Code introduced by
The call to Bootstrap::run() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
57
    }
58
59
    /**
60
     * Process an incoming Jaxon request, and return the response.
61
     *
62
     * @return void
63
     */
64
    public function processRequest()
65
    {
66
        return jaxon()->processRequest();
67
    }
68
}
69