Completed
Push — master ( d9f7fe...0d6725 )
by Igor
02:53
created

BaseController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getResponse() 0 4 1
A setResponse() 0 4 1
A setView() 0 5 1
A setContent() 0 5 1
A setRedirect() 0 5 1
1
<?php
2
/**
3
 * @license MIT
4
 */
5
namespace Pivasic\Core;
6
7
use Pivasic\Bundle\Template\Native;
8
9
/**
10
 * Base functions to service request.
11
 *
12
 * Class BaseController
13
 * @package Pivasic\Core
14
 */
15
class BaseController
16
{
17
    /**
18
     * @param string $packageRoot
19
     * @param Request $request
20
     */
21
    public function __construct($packageRoot, Request $request)
22
    {
23
        $this->packageRoot = $packageRoot;
24
        $this->request = $request;
25
        $this->response = null;
26
    }
27
28
    /**
29
     * @return Response|null
30
     */
31
    public function getResponse()
32
    {
33
        return $this->response;
34
    }
35
36
    /**
37
     * @param Response $response
38
     */
39
    public function setResponse(Response $response)
40
    {
41
        $this->response = $response;
42
    }
43
44
    /**
45
     * Create Response from template.
46
     *
47
     * @param string $name
48
     * @param array $data
49
     */
50
    public function setView($name = '', array $data = [])
51
    {
52
        $this->response = new Response;
53
        $this->response->setContent((new Native($this->packageRoot, $this->request))->getContent($name, $data));
0 ignored issues
show
Unused Code introduced by
The call to Native::__construct() has too many arguments starting with $this->request.

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...
54
    }
55
56
    /**
57
     * Create Response from content.
58
     *
59
     * @param string $content
60
     */
61
    public function setContent($content)
62
    {
63
        $this->response = new Response();
64
        $this->response->setContent($content);
65
    }
66
67
    /**
68
     * Redirect to the URL with statusCode.
69
     *
70
     * @param null $url
71
     * @param int $statusCode
72
     */
73
    public function setRedirect($url = null, $statusCode = 303)
74
    {
75
        $this->response = new Response();
76
        $this->response->redirect($url, $statusCode);
77
    }
78
79
    private $packageRoot;
80
    private $request;
81
    private $response;
82
}