Controller   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __get() 0 8 2
A __call() 0 10 2
A render() 0 4 1
1
<?php
2
/**
3
 * Implementation of controller for Slim Framework v3 (https://github.com/orx0r/slim3-controller)
4
 *
5
 * @link https://github.com/orx0r/slim3-controller
6
 * @license https://raw.githubusercontent.com/orx0r/slim3-controller/master/LICENSE
7
 */
8
namespace Orx0r\Slim\Controller;
9
10
use Interop\Container\ContainerInterface as Container;
11
use Psr\Http\Message\ResponseInterface as Response;
12
use Psr\Http\Message\ServerRequestInterface as Request;
13
14
/**
15
 * Class Controller
16
 * @package Orx0r\Slim\Controller
17
 */
18
class Controller
19
{
20
21
    /**
22
     * @var Container
23
     */
24
    protected $container;
25
26
    /**
27
     * @var Request
28
     */
29
    protected $request;
30
31
    /**
32
     * @var Response
33
     */
34
    protected $response;
35
36 5
    public function __construct(Container $container)
37
    {
38 5
        $this->container = $container;
39 5
    }
40
41 2
    public function __get($property)
42
    {
43 2
        if ($this->container->has($property)) {
44 1
            return $this->container->get($property);
45
        }
46
47 1
        throw new \RuntimeException(sprintf('Property %s does not exist', get_class($this) . "::$property"));
48
    }
49
50 3
    public function __call($name, $arguments)
51
    {
52 3
        $method = 'action' . ucfirst($name);
53 3
        if (method_exists($this, $method)) {
54 2
            list($this->request, $this->response, $params) = $arguments;
55 2
            return call_user_func_array([$this, $method], $params);
56
        }
57
58 1
        throw new \RuntimeException(sprintf('Method %s does not exist', get_class($this) . "::$name()"));
59
    }
60
61
    /**
62
     * Shorthand method for render templates
63
     *
64
     * @link http://www.slimframework.com/docs/features/templates.html
65
     *
66
     * @param string $template Template pathname relative to templates directory
67
     * @param array  $data     Associative array of template variables
68
     *
69
     * @return mixed
70
     */
71 1
    public function render($template, $data = [])
72
    {
73 1
        return $this->container->get('view')->render($this->response, $template, $data);
74
    }
75
}
76