| Conditions | 24 |
| Paths | 24 |
| Total Lines | 68 |
| Code Lines | 34 |
| 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 |
||
| 43 | public function replace(string $placeholder, object $part, array $options = []): ?string |
||
| 44 | { |
||
| 45 | if (!$part instanceof Part) { |
||
| 46 | return null; |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($placeholder === '[[CATEGORY]]') { |
||
| 50 | return $part->getCategory() ? $part->getCategory()->getName() : ''; |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($placeholder === '[[CATEGORY_FULL]]') { |
||
| 54 | return $part->getCategory() ? $part->getCategory()->getFullPath() : ''; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ($placeholder === '[[MANUFACTURER]]') { |
||
| 58 | return $part->getManufacturer() ? $part->getManufacturer()->getName() : ''; |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($placeholder === '[[MANUFACTURER_FULL]]') { |
||
| 62 | return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : ''; |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($placeholder === '[[FOOTPRINT]]') { |
||
| 66 | return $part->getFootprint() ? $part->getFootprint()->getName() : ''; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($placeholder === '[[FOOTPRINT_FULL]]') { |
||
| 70 | return $part->getFootprint() ? $part->getFootprint()->getFullPath() : ''; |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($placeholder === '[[MASS]]') { |
||
| 74 | return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : ''; |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($placeholder === '[[MPN]]') { |
||
| 78 | return $part->getManufacturerProductNumber(); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($placeholder === '[[TAGS]]') { |
||
| 82 | return $part->getTags(); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($placeholder === '[[M_STATUS]]') { |
||
| 86 | if ($part->getManufacturingStatus() === '') { |
||
| 87 | return ''; |
||
| 88 | } |
||
| 89 | return $this->translator->trans('m_status.' . $part->getManufacturingStatus()); |
||
| 90 | } |
||
| 91 | |||
| 92 | $parsedown = new \Parsedown(); |
||
| 93 | |||
| 94 | if ($placeholder === '[[DESCRIPTION]]') { |
||
| 95 | return $parsedown->line($part->getDescription()); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($placeholder === '[[DESCRIPTION_T]]') { |
||
| 99 | return strip_tags($parsedown->line($part->getDescription())); |
||
| 100 | } |
||
| 101 | |||
| 102 | if ($placeholder === '[[COMMENT]]') { |
||
| 103 | return $parsedown->line($part->getComment()); |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($placeholder === '[[COMMENT_T]]') { |
||
| 107 | return strip_tags($parsedown->line($part->getComment())); |
||
| 108 | } |
||
| 109 | |||
| 110 | return null; |
||
| 111 | } |
||
| 112 | } |