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