Completed
Push — 4.0 ( 4d1c3b...6206cc )
by Marco
11:58
created

AbstractService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 20
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
rs 9.4285
cc 1
eloc 12
nc 1
nop 6
1
<?php namespace Comodojo\Dispatcher\Service;
2
3
use \Comodojo\Components\Model as DispatcherClassModel;
4
use \Comodojo\Dispatcher\Base\Configuration;
5
use \Comodojo\Dispatcher\Request\Model as Request;
6
use \Comodojo\Dispatcher\Router\Collector as Router;
7
use \Comodojo\Dispatcher\Response\Model as Response;
8
use \Comodojo\Dispatcher\Extra\Model as Extra;
9
use \Monolog\Logger;
10
11
/**
12
 * @package     Comodojo Dispatcher
13
 * @author      Marco Giovinazzi <[email protected]>
14
 * @author      Marco Castiello <[email protected]>
15
 * @license     GPL-3.0+
16
 *
17
 * LICENSE:
18
 *
19
 * This program is free software: you can redistribute it and/or modify
20
 * it under the terms of the GNU Affero General Public License as
21
 * published by the Free Software Foundation, either version 3 of the
22
 * License, or (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU Affero General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU Affero General Public License
30
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31
 */
32
33
abstract class AbstractService extends DispatcherClassModel {
34
35
    protected $request;
36
37
    protected $router;
38
39
    protected $response;
40
41
    protected $extra;
42
43 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method 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...
44
        Configuration $configuration,
45
        Logger $logger,
46
        Request $request,
47
        Router $router,
48
        Response $response,
49
        Extra $extra
50
    ) {
51
52
        parent::__construct($configuration, $logger);
53
54
        $this->request = $request;
55
56
        $this->router = $router;
57
58
        $this->response = $response;
59
60
        $this->extra = $extra;
61
62
    }
63
64
    final public function request() {
65
66
        return $this->request;
67
68
    }
69
70
    final public function router() {
71
72
        return $this->router;
73
74
    }
75
76
    final public function response() {
77
78
        return $this->response;
79
80
    }
81
82
    final public function extra() {
83
84
        return $this->extra;
85
86
    }
87
88
    /**
89
     * Get service-implemented HTTP methods
90
     *
91
     * @return  array   Headers array
92
     */
93
    final public function getImplementedMethods() {
94
95
        $supported_methods = $this->configuration()->get('dispatcher-supported-methods');
96
97
        if ( method_exists($this, 'any') ) {
98
99
            return $supported_methods;
100
101
        }
102
103
        $implemented_methods = array();
104
105
        foreach ( $supported_methods as $method ) {
106
107
            if ( method_exists($this, strtolower($method)) ) array_push($implemented_methods,$method);
108
109
        }
110
111
        return $implemented_methods;
112
113
    }
114
115
    /**
116
     * Return the callable class method that reflect the requested one
117
     *
118
     */
119
    final public function getMethod($method) {
120
121
        if ( method_exists($this, strtolower($method)) ) {
122
123
            return strtolower($method);
124
125
        } else if ( method_exists($this, strtolower('any')) ) {
126
127
            return 'any';
128
129
        } else {
130
131
            return "any";
132
133
        }
134
135
    }
136
137
}
138