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 |
||
19 | class MarketBook extends AbstractBetfair |
||
20 | { |
||
21 | const API_METHOD_NAME = "listMarketBook"; |
||
22 | |||
23 | private $marketIds = []; |
||
24 | private $priceProjection; |
||
25 | private $orderProjection; |
||
26 | private $matchProjection; |
||
27 | private $currencyCode; |
||
28 | private $locale; |
||
29 | |||
30 | /** |
||
31 | * @param BetfairClientInterface $betfairClient |
||
32 | * @param AdapterInterface $adapter |
||
33 | * @param ParamFactoryInterface $paramFactory |
||
34 | * @param MarketFilterFactoryInterface $marketFilterFactory |
||
35 | */ |
||
36 | public function __construct( |
||
44 | |||
45 | public function getResults() |
||
58 | |||
59 | View Code Duplication | public function getMarketBookFilterByMarketIds(array $marketIds) |
|
71 | |||
72 | View Code Duplication | public function getMarketBookFilterByMarketIdsWithPriceData(array $marketIds, array $priceData) |
|
85 | |||
86 | View Code Duplication | public function getMarketBookFilterByMarketIdsWithPriceProjection(array $marketIds, PriceProjection $priceProjection) |
|
98 | |||
99 | public function withMarketIds($marketIds) |
||
104 | |||
105 | public function withPriceProjection(PriceProjection $priceProjection) |
||
110 | |||
111 | public function withOrderProjection($orderProjection) |
||
116 | |||
117 | public function withMatchProjection($matchProjection) |
||
122 | |||
123 | public function withCurrencyCode($currencyCode) |
||
128 | |||
129 | public function withLocale($locale) |
||
133 | |||
134 | private function restoreDefaults() |
||
142 | } |
||
143 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: