| Conditions | 13 |
| Paths | 13 |
| Total Lines | 49 |
| Code Lines | 25 |
| 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 |
||
| 41 | public function replace(string $placeholder, object $label_target, array $options = []): ?string |
||
| 42 | { |
||
| 43 | if ($label_target instanceof PartLot) { |
||
| 44 | if ($placeholder === '[[LOT_ID]]') { |
||
| 45 | return $label_target->getID() ?? 'unknown'; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($placeholder === '[[LOT_NAME]]') { |
||
| 49 | return $label_target->getName(); |
||
| 50 | } |
||
| 51 | |||
| 52 | if ($placeholder === '[[LOT_COMMENT]]') { |
||
| 53 | return $label_target->getComment(); |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($placeholder === '[[EXPIRATION_DATE]]') { |
||
| 57 | if ($label_target->getExpirationDate() === null) { |
||
| 58 | return ''; |
||
| 59 | } |
||
| 60 | $formatter = IntlDateFormatter::create( |
||
| 61 | Locale::getDefault(), |
||
| 62 | IntlDateFormatter::SHORT, |
||
| 63 | IntlDateFormatter::NONE |
||
| 64 | //$label_target->getExpirationDate()->getTimezone() |
||
| 65 | ); |
||
| 66 | |||
| 67 | return $formatter->format($label_target->getExpirationDate()); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($placeholder === '[[AMOUNT]]') { |
||
| 71 | if ($label_target->isInstockUnknown()) { |
||
| 72 | return '?'; |
||
| 73 | } |
||
| 74 | return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit()); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($placeholder === '[[LOCATION]]') { |
||
| 78 | return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : ''; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($placeholder === '[[LOCATION_FULL]]') { |
||
| 82 | return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : ''; |
||
| 83 | } |
||
| 84 | |||
| 85 | |||
| 86 | return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart()); |
||
| 87 | } |
||
| 88 | |||
| 89 | return null; |
||
| 90 | } |
||
| 91 | } |