| Conditions | 11 |
| Paths | 21 |
| Total Lines | 39 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 39 | public function validate($value, Constraint $constraint) |
||
| 40 | { |
||
| 41 | if (!$constraint instanceof ValidProjectBuildRequest) { |
||
| 42 | throw new UnexpectedTypeException($constraint, ValidProjectBuildRequest::class); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (null === $value || '' === $value) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (!$value instanceof ProjectBuildRequest) { |
||
| 50 | throw new UnexpectedTypeException($value, ProjectBuildRequest::class); |
||
| 51 | } |
||
| 52 | |||
| 53 | foreach ($value->getPartBomEntries() as $bom_entry) { |
||
| 54 | $withdraw_sum = $value->getWithdrawAmountSum($bom_entry); |
||
| 55 | $needed_amount = $value->getNeededAmountForBOMEntry($bom_entry); |
||
| 56 | |||
| 57 | foreach ($value->getPartLotsForBOMEntry($bom_entry) as $lot) { |
||
| 58 | $withdraw_amount = $value->getLotWithdrawAmount($lot); |
||
| 59 | |||
| 60 | if ($withdraw_amount < 0) { |
||
| 61 | $this->buildViolationForLot($lot, 'validator.project_build.lot_must_not_smaller_0') |
||
| 62 | ->addViolation(); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($withdraw_amount > $lot->getAmount()) { |
||
| 66 | $this->buildViolationForLot($lot, 'validator.project_build.lot_must_not_bigger_than_stock') |
||
| 67 | ->addViolation(); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($withdraw_sum > $needed_amount) { |
||
| 71 | $this->buildViolationForLot($lot, 'validator.project_build.lot_bigger_than_needed') |
||
| 72 | ->addViolation(); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($withdraw_sum < $needed_amount) { |
||
| 76 | $this->buildViolationForLot($lot, 'validator.project_build.lot_smaller_than_needed') |
||
| 77 | ->addViolation(); |
||
| 78 | } |
||
| 82 | } |