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 |
||
| 27 | class AddPointProcessor extends ItemHolderPostValidator |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var BaseInfo |
||
| 31 | */ |
||
| 32 | protected $BaseInfo; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * AddPointProcessor constructor. |
||
| 36 | * |
||
| 37 | * @param BaseInfoRepository $baseInfoRepository |
||
| 38 | */ |
||
| 39 | public function __construct(BaseInfoRepository $baseInfoRepository) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param ItemHolderInterface $itemHolder |
||
| 46 | * @param PurchaseContext $context |
||
| 47 | */ |
||
| 48 | public function validate(ItemHolderInterface $itemHolder, PurchaseContext $context) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * 付与ポイントを計算. |
||
| 61 | * |
||
| 62 | * @param ItemHolderInterface $itemHolder |
||
| 63 | * |
||
| 64 | * @return int |
||
| 65 | */ |
||
| 66 | private function calculateAddPoint(ItemHolderInterface $itemHolder) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Processorが実行出来るかどうかを返す. |
||
| 96 | * |
||
| 97 | * 以下を満たす場合に実行できる. |
||
| 98 | * |
||
| 99 | * - ポイント設定が有効であること. |
||
| 100 | * - $itemHolderがOrderエンティティであること. |
||
| 101 | * - 会員のOrderであること. |
||
| 102 | * |
||
| 103 | * @param ItemHolderInterface $itemHolder |
||
| 104 | * |
||
| 105 | * @return bool |
||
| 106 | */ |
||
| 107 | View Code Duplication | private function supports(ItemHolderInterface $itemHolder) |
|
| 123 | } |
||
| 124 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.