Conditions | 24 |
Paths | 24 |
Total Lines | 69 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
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 |
||
60 | public function replace(string $placeholder, object $part, array $options = []): ?string |
||
61 | { |
||
62 | if (!$part instanceof Part) { |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | if ('[[CATEGORY]]' === $placeholder) { |
||
67 | return $part->getCategory() ? $part->getCategory()->getName() : ''; |
||
68 | } |
||
69 | |||
70 | if ('[[CATEGORY_FULL]]' === $placeholder) { |
||
71 | return $part->getCategory() ? $part->getCategory()->getFullPath() : ''; |
||
72 | } |
||
73 | |||
74 | if ('[[MANUFACTURER]]' === $placeholder) { |
||
75 | return $part->getManufacturer() ? $part->getManufacturer()->getName() : ''; |
||
76 | } |
||
77 | |||
78 | if ('[[MANUFACTURER_FULL]]' === $placeholder) { |
||
79 | return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : ''; |
||
80 | } |
||
81 | |||
82 | if ('[[FOOTPRINT]]' === $placeholder) { |
||
83 | return $part->getFootprint() ? $part->getFootprint()->getName() : ''; |
||
84 | } |
||
85 | |||
86 | if ('[[FOOTPRINT_FULL]]' === $placeholder) { |
||
87 | return $part->getFootprint() ? $part->getFootprint()->getFullPath() : ''; |
||
88 | } |
||
89 | |||
90 | if ('[[MASS]]' === $placeholder) { |
||
91 | return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : ''; |
||
92 | } |
||
93 | |||
94 | if ('[[MPN]]' === $placeholder) { |
||
95 | return $part->getManufacturerProductNumber(); |
||
96 | } |
||
97 | |||
98 | if ('[[TAGS]]' === $placeholder) { |
||
99 | return $part->getTags(); |
||
100 | } |
||
101 | |||
102 | if ('[[M_STATUS]]' === $placeholder) { |
||
103 | if ('' === $part->getManufacturingStatus()) { |
||
104 | return ''; |
||
105 | } |
||
106 | |||
107 | return $this->translator->trans('m_status.'.$part->getManufacturingStatus()); |
||
108 | } |
||
109 | |||
110 | $parsedown = new Parsedown(); |
||
111 | |||
112 | if ('[[DESCRIPTION]]' === $placeholder) { |
||
113 | return $parsedown->line($part->getDescription()); |
||
114 | } |
||
115 | |||
116 | if ('[[DESCRIPTION_T]]' === $placeholder) { |
||
117 | return strip_tags($parsedown->line($part->getDescription())); |
||
118 | } |
||
119 | |||
120 | if ('[[COMMENT]]' === $placeholder) { |
||
121 | return $parsedown->line($part->getComment()); |
||
122 | } |
||
123 | |||
124 | if ('[[COMMENT_T]]' === $placeholder) { |
||
125 | return strip_tags($parsedown->line($part->getComment())); |
||
126 | } |
||
127 | |||
128 | return null; |
||
129 | } |
||
131 |