Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
24 | class Client implements ClientInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var HttpClientInterface |
||
28 | */ |
||
29 | protected $httpClient; |
||
30 | |||
31 | /** |
||
32 | * @param HttpClientInterface $httpClient |
||
33 | */ |
||
34 | 10 | public function __construct(HttpClientInterface $httpClient) |
|
38 | |||
39 | /** |
||
40 | * @param string $url |
||
41 | * @param array $config |
||
42 | * @return Client |
||
43 | */ |
||
44 | 1 | public static function factory($url, array $config = []) |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | * |
||
64 | * @link http://www.jsonrpc.org/specification#notification |
||
65 | * @param string $method |
||
66 | * @param array $params |
||
|
|||
67 | * @return RequestInterface |
||
68 | */ |
||
69 | 2 | View Code Duplication | public function notification($method, array $params = null) |
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | * |
||
81 | * @link http://www.jsonrpc.org/specification#request_object |
||
82 | * @param mixed $id |
||
83 | * @param string $method |
||
84 | * @param array $params |
||
85 | * @return RequestInterface |
||
86 | */ |
||
87 | 4 | View Code Duplication | public function request($id, $method, array $params = null) |
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | * |
||
100 | * @param RequestInterface $request |
||
101 | * @return ResponseInterface|null |
||
102 | */ |
||
103 | 2 | public function send(RequestInterface $request) |
|
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | * |
||
113 | * @link http://www.jsonrpc.org/specification#batch |
||
114 | * @param RequestInterface[] $requests |
||
115 | * @return ResponseInterface[] |
||
116 | */ |
||
117 | 1 | public function sendAll(array $requests) |
|
126 | |||
127 | /** |
||
128 | * @return MessageFactoryInterface |
||
129 | */ |
||
130 | 1 | protected static function createMessageFactory() |
|
134 | |||
135 | /** |
||
136 | * @param string $method |
||
137 | * @param array $options |
||
138 | * @return RequestInterface |
||
139 | */ |
||
140 | 6 | protected function createRequest($method, array $options) |
|
146 | |||
147 | /** |
||
148 | * @return MessageFactoryInterface |
||
149 | */ |
||
150 | 1 | protected function getMessageFactory() |
|
159 | |||
160 | /** |
||
161 | * @param RequestInterface[] $requests |
||
162 | * @return array |
||
163 | */ |
||
164 | 1 | protected function getBatchRequestOptions(array $requests) |
|
170 | |||
171 | /** |
||
172 | * @param ResponseInterface $response |
||
173 | * @return ResponseInterface[] |
||
174 | */ |
||
175 | 1 | protected function getBatchResponses(ResponseInterface $response) |
|
188 | } |
||
189 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.