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 |
||
| 21 | class StockMultipleValidator extends ItemHolderValidator |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var ProductClassRepository |
||
| 25 | */ |
||
| 26 | protected $productClassRepository; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * StockProcessor constructor. |
||
| 30 | * |
||
| 31 | * @param ProductClassRepository $productClassRepository |
||
| 32 | */ |
||
| 33 | 64 | public function __construct(ProductClassRepository $productClassRepository) |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @param ItemHolderInterface $itemHolder |
||
| 40 | * @param PurchaseContext $context |
||
| 41 | * |
||
| 42 | * @throws \Eccube\Service\PurchaseFlow\InvalidItemException |
||
| 43 | */ |
||
| 44 | 55 | public function validate(ItemHolderInterface $itemHolder, PurchaseContext $context) |
|
| 72 | } |
||
| 73 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.