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 |
||
| 31 | class UsePointProcessor implements ItemHolderProcessor |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @var EntityManagerInterface |
||
| 35 | */ |
||
| 36 | protected $entityManager; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var BaseInfo |
||
| 40 | */ |
||
| 41 | protected $BaseInfo; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * UsePointProcessor constructor. |
||
| 45 | * |
||
| 46 | * @param EntityManagerInterface $entityManager |
||
| 47 | * @param BaseInfo $BaseInfo |
||
| 48 | */ |
||
| 49 | public function __construct(EntityManagerInterface $entityManager, BaseInfo $BaseInfo) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param ItemHolderInterface $itemHolder |
||
| 57 | * @param PurchaseContext $context |
||
| 58 | * |
||
| 59 | * @return ProcessResult |
||
| 60 | */ |
||
| 61 | public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * 明細追加処理 |
||
| 80 | * |
||
| 81 | * @param ItemHolderInterface $itemHolder |
||
| 82 | */ |
||
| 83 | protected function addPointDiscountItem(ItemHolderInterface $itemHolder) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * 既存のポイント明細を削除する. |
||
| 119 | * |
||
| 120 | * @param ItemHolderInterface $itemHolder |
||
| 121 | */ |
||
| 122 | View Code Duplication | protected function removePointDiscountItem(ItemHolderInterface $itemHolder) |
|
| 131 | |||
| 132 | /** |
||
| 133 | * 利用ポイントを単価に換算する. |
||
| 134 | * |
||
| 135 | * @param integer $usePoint 利用ポイント |
||
| 136 | * |
||
| 137 | * @return integer |
||
| 138 | */ |
||
| 139 | protected function usePointToPrice($usePoint) |
||
| 143 | } |
||
| 144 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: