Conditions | 13 |
Paths | 648 |
Total Lines | 48 |
Code Lines | 26 |
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 |
||
58 | public function getPreviewAttachments(Part $part) : array |
||
59 | { |
||
60 | $list = []; |
||
61 | |||
62 | //Master attachment has top priority |
||
63 | $attachment = $part->getMasterPictureAttachment(); |
||
64 | if ($this->isAttachmentValidPicture($attachment)) { |
||
65 | $list[] = $attachment; |
||
66 | } |
||
67 | |||
68 | if ($part->getFootprint() !== null) { |
||
69 | $attachment = $part->getFootprint()->getMasterPictureAttachment(); |
||
70 | if ($this->isAttachmentValidPicture($attachment)) { |
||
71 | $list[] = $attachment; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | if ($part->getCategory() !== null) { |
||
76 | $attachment = $part->getCategory()->getMasterPictureAttachment(); |
||
77 | if ($this->isAttachmentValidPicture($attachment)) { |
||
78 | $list[] = $attachment; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | foreach ($part->getPartLots() as $lot) { |
||
83 | if ($lot->getStorageLocation() !== null) { |
||
84 | $attachment = $lot->getStorageLocation()->getMasterPictureAttachment(); |
||
85 | if ($this->isAttachmentValidPicture($attachment)) { |
||
86 | $list[] = $attachment; |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if ($part->getPartUnit() !== null) { |
||
92 | $attachment = $part->getPartUnit()->getMasterPictureAttachment(); |
||
93 | if ($this->isAttachmentValidPicture($attachment)) { |
||
94 | $list[] = $attachment; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | if ($part->getManufacturer() !== null) { |
||
99 | $attachment = $part->getManufacturer()->getMasterPictureAttachment(); |
||
100 | if ($this->isAttachmentValidPicture($attachment)) { |
||
101 | $list[] = $attachment; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | return $list; |
||
106 | } |
||
145 | } |