| Conditions | 12 |
| Paths | 1 |
| Total Lines | 18 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 12 |
| Changes | 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 |
||
| 29 | 1 | private static function parse(array $product, Currency $currency): Product |
|
| 30 | { |
||
| 31 | 1 | extract($product); |
|
| 32 | |||
| 33 | 1 | return new Product( |
|
| 34 | 1 | isset($productUuid) ? Uuid::fromString($productUuid) : null, |
|
| 35 | 1 | isset($variantUuid) ? Uuid::fromString($variantUuid) : null, |
|
| 36 | 1 | isset($name) ? $name : null, |
|
| 37 | 1 | isset($variantName) ? $variantName : null, |
|
| 38 | 1 | isset($quantity) ? (int) $quantity : null, |
|
| 39 | 1 | isset($unitPrice) ? new Money($unitPrice, $currency) : null, |
|
|
|
|||
| 40 | 1 | isset($vatPercentage) ? $vatPercentage : null, |
|
| 41 | 1 | isset($rowTaxableAmount) ? new Money($rowTaxableAmount, $currency) : null, |
|
| 42 | 1 | isset($imageLookupKey) ? new Image($imageLookupKey) : null, |
|
| 43 | 1 | isset($autoGenerated) ? $autoGenerated : false, |
|
| 44 | 1 | isset($libraryProduct) ? $libraryProduct : false |
|
| 45 | ); |
||
| 46 | } |
||
| 47 | } |
||
| 48 |
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: