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 |
||
14 | class JsonLocation extends AbstractLocation |
||
15 | { |
||
16 | /** @var string Whether or not to add a Content-Type header when JSON is found */ |
||
17 | private $jsonContentType; |
||
18 | |||
19 | /** @var array */ |
||
20 | private $jsonData; |
||
21 | |||
22 | /** |
||
23 | * @param string $locationName Name of the location |
||
24 | * @param string $contentType Content-Type header to add to the request if |
||
25 | * JSON is added to the body. Pass an empty string to omit. |
||
26 | */ |
||
27 | 3 | public function __construct($locationName = 'json', $contentType = 'application/json') |
|
32 | |||
33 | /** |
||
34 | * @param CommandInterface $command |
||
35 | * @param RequestInterface $request |
||
36 | * @param Parameter $param |
||
37 | * |
||
38 | * @return RequestInterface |
||
39 | */ |
||
40 | 3 | public function visit( |
|
52 | |||
53 | /** |
||
54 | * @param CommandInterface $command |
||
55 | * @param RequestInterface $request |
||
56 | * @param Operation $operation |
||
57 | * |
||
58 | * @return MessageInterface |
||
59 | */ |
||
60 | 3 | public function after( |
|
85 | } |
||
86 |