Completed
Push — master ( ddb442...ae6585 )
by Mathieu
04:01
created

ScriptRoute::set_app()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 5
loc 5
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Charcoal\App\Route;
4
5
// Dependencies from `PHP`
6
use \InvalidArgumentException;
7
8
// PSR-7 (http messaging) dependencies
9
use \Psr\Http\Message\RequestInterface;
10
use \Psr\Http\Message\ResponseInterface;
11
12
// From `charcoal-config`
13
use \Charcoal\Config\ConfigInterface;
14
use \Charcoal\Config\ConfigurableInterface;
15
use \Charcoal\Config\ConfigurableTrait;
16
17
// Intra-module (`charcoal-app`) dependencies
18
use \Charcoal\App\LoggerAwareInterface;
19
use \Charcoal\App\LoggerAwareTrait;
20
21
// Local namespace dependencies
22
use \Charcoal\App\Route\RouteInterface;
23
use \Charcoal\App\Route\ScriptRouteConfig;
24
25
/**
26
 *
27
 */
28 View Code Duplication
class ScriptRoute implements
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    ConfigurableInterface,
30
    LoggerAwareInterface,
31
    RouteInterface
32
{
33
    use ConfigurableTrait;
34
    use LoggerAwareTrait;
35
36
    /**
37
     * @var \Slim\App $app
38
     */
39
    private $app;
40
41
    /**
42
     * ## Required dependencies
43
     * - `config` ScriptRouteConfig
44
     * - `app` SlimApp
45
     *
46
     * ## Optional dependencies
47
     * - `logger`
48
     *
49
     * @param array $data Dependencies.
50
     */
51
    public function __construct(array $data)
52
    {
53
        $this->set_config($data['config']);
54
        $this->set_app($data['app']);
55
56
        // Reuse app logger, if it's not directly set in data dependencies
57
        $logger = isset($data['logger']) ? $data['logger'] : $this->app->logger;
58
        $this->set_logger($logger);
59
    }
60
61
    /**
62
     * Set the manager's reference to the Slim App.
63
     *
64
     * @param  SlimApp $app The Slim Application instance.
65
     * @return TemplateRoute Chainable
66
     */
67
    protected function set_app(SlimApp $app)
68
    {
69
        $this->app = $app;
0 ignored issues
show
Documentation Bug introduced by
It seems like $app of type object<Charcoal\App\Route\SlimApp> is incompatible with the declared type object<Slim\App> of property $app.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
70
        return $this;
71
    }
72
73
    /**
74
     * Get the manager's reference to the Slim App
75
     *
76
     * @return SlimApp
77
     */
78
    protected function app()
79
    {
80
        return $this->app;
81
    }
82
83
    /**
84
     * ConfigurableTrait > create_config()
85
     *
86
     * @param mixed|null $data Optional config data.
87
     * @return ConfigInterface
88
     */
89
    public function create_config($data = null)
90
    {
91
        return new ScriptRouteConfig($data);
92
    }
93
94
    /**
95
     * @param RequestInterface  $request  A PSR-7 compatible Request instance.
96
     * @param ResponseInterface $response A PSR-7 compatible Response instance.
97
     * @return ResponseInterface
98
     */
99
    public function __invoke(RequestInterface $request, ResponseInterface $response)
100
    {
101
        unset($request);
102
        return $response;
103
    }
104
}
105