Completed
Push — master ( 4b431b...9ea9f1 )
by Restu
15:27
created

Application::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
namespace JayaCode\Framework\Core\Application;
3
4
use JayaCode\Framework\Core\Http\Request;
5
use JayaCode\Framework\Core\Http\Response;
6
use JayaCode\Framework\Core\Router\Router;
7
8
/**
9
 * Class Application
10
 * @package JayaCode\Framework\Core\Application
11
 */
12
class Application
13
{
14
    /**
15
     * @var Request
16
     */
17
    public $request;
18
19
    /**
20
     * @var Response
21
     */
22
    public $response;
23
24
    /**
25
     * @var Router
26
     */
27
    public $router;
28
29
    /**
30
     * Application constructor.
31
     */
32
    public function __construct()
33
    {
34
        $this->initialize();
35
    }
36
37
    /**
38
     * Create Application object from static function
39
     * @return Application
40
     */
41
    public static function create()
42
    {
43
        return new Application();
44
    }
45
46
    /**
47
     * initialize Application
48
     */
49
    public function initialize()
50
    {
51
        $this->request = Request::createFromGlobals();
52
        $this->response = Response::create();
53
        $this->router = Router::create($this->request, $this->response);
0 ignored issues
show
Documentation introduced by
$this->request is of type object<Symfony\Component\HttpFoundation\Request>, but the function expects a null|object<JayaCode\Framework\Core\Http\Request>.

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...
Documentation introduced by
$this->response is of type object<Symfony\Component\HttpFoundation\Response>, but the function expects a null|object<JayaCode\Fra...ork\Core\Http\Response>.

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...
54
55
        $this->setTimeZone();
56
    }
57
58
    public function setTimeZone($timezone = 'Asia/Jakarta')
59
    {
60
        return date_default_timezone_set($timezone);
61
    }
62
63
    /**
64
     * Run Application
65
     */
66
    public function run()
67
    {
68
        $this->router->handle();
69
        $this->response->send();
70
    }
71
72
    /**
73
     * @return mixed
74
     */
75
    public function getRequest()
76
    {
77
        return $this->request;
78
    }
79
80
    /**
81
     * @param mixed $request
82
     */
83
    public function setRequest($request)
84
    {
85
        $this->request = $request;
86
    }
87
88
    /**
89
     * @return mixed
90
     */
91
    public function getResponse()
92
    {
93
        return $this->response;
94
    }
95
96
    /**
97
     * @param mixed $response
98
     */
99
    public function setResponse($response)
100
    {
101
        $this->response = $response;
102
    }
103
}
104