Controller   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A init() 0 13 1
A getDefaultAction() 0 3 1
1
<?php
2
3
namespace Asymptix\app;
4
5
use Asymptix\core\Route;
6
7
/**
8
 * Abstract Controller class, parent for all controllers.
9
 *
10
 * @category Asymptix PHP Framework
11
 * @author Dmytro Zarezenko <[email protected]>
12
 * @copyright (c) 2015 - 2016, Dmytro Zarezenko
13
 *
14
 * @git https://github.com/Asymptix/Framework
15
 * @license http://opensource.org/licenses/MIT
16
 */
17
abstract class Controller {
18
19
    /**
20
     * @var Route
21
     */
22
    public $route = null;
23
24
    /**
25
     * Default controller action.
26
     *
27
     * @var string
28
     */
29
    protected $defaultAction = "";
30
31
    /**
32
     * @var View
33
     */
34
    public $view = null;
35
36
    public function __construct(Route $route = null) {
37
        $this->route = $route;
38
        $this->route->getAction('action', $this->defaultAction);
39
40
        $this->view = new View($this->route);
41
42
        $this->init();
43
    }
44
45
    protected function init() {
46
        $action = 'action' . ucfirst(
47
            preg_replace_callback(
48
                "#_([a-z])#",
49
                function ($matches) {
50
                    return strtoupper($matches[1]);
51
                },
52
                $this->route->action
53
            )
54
        );
55
56
        return $this->$action();
57
    }
58
59
    public function getDefaultAction() {
60
        return $this->defaultAction;
61
    }
62
63
}
64