Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 53 |
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 |
||
70 | public function load(ObjectManager $manager): void |
||
71 | { |
||
72 | |||
73 | /** Simple part */ |
||
74 | $part = new Part(); |
||
75 | $part->setName('Part 1'); |
||
76 | $part->setCategory($manager->find(Category::class, 1)); |
||
77 | $manager->persist($part); |
||
78 | |||
79 | /** More complex part */ |
||
80 | $part = new Part(); |
||
81 | $part->setName('Part 2'); |
||
82 | $part->setCategory($manager->find(Category::class, 1)); |
||
83 | $part->setFootprint($manager->find(Footprint::class, 1)); |
||
84 | $part->setManufacturer($manager->find(Manufacturer::class, 1)); |
||
85 | $part->setTags('test, Test, Part2'); |
||
86 | $part->setMass(100.2); |
||
87 | $part->setNeedsReview(true); |
||
88 | $part->setManufacturingStatus('active'); |
||
89 | $manager->persist($part); |
||
90 | |||
91 | /** Part with orderdetails, storelocations and Attachments */ |
||
92 | $part = new Part(); |
||
93 | $part->setFavorite(true); |
||
94 | $part->setName('Part 3'); |
||
95 | $part->setCategory($manager->find(Category::class, 1)); |
||
96 | $partLot1 = new PartLot(); |
||
97 | $partLot1->setAmount(1.0); |
||
98 | $partLot1->setStorageLocation($manager->find(Storelocation::class, 1)); |
||
99 | $part->addPartLot($partLot1); |
||
100 | |||
101 | $partLot2 = new PartLot(); |
||
102 | $partLot2->setExpirationDate(new DateTime()); |
||
103 | $partLot2->setComment('Test'); |
||
104 | $partLot2->setNeedsRefill(true); |
||
105 | $partLot2->setStorageLocation($manager->find(Storelocation::class, 3)); |
||
106 | $part->addPartLot($partLot2); |
||
107 | |||
108 | $orderdetail = new Orderdetail(); |
||
109 | $orderdetail->setSupplier($manager->find(Supplier::class, 1)); |
||
|
|||
110 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(BigDecimal::of('10.0'))); |
||
111 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(BigDecimal::of('15.0'))); |
||
112 | $part->addOrderdetail($orderdetail); |
||
113 | |||
114 | $orderdetail = new Orderdetail(); |
||
115 | $orderdetail->setSupplierpartnr('BC 547'); |
||
116 | $orderdetail->setObsolete(true); |
||
117 | $orderdetail->setSupplier($manager->find(Supplier::class, 1)); |
||
118 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(BigDecimal::of('10.0'))); |
||
119 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(BigDecimal::of('15.1'))); |
||
120 | $part->addOrderdetail($orderdetail); |
||
121 | |||
122 | $attachment = new PartAttachment(); |
||
123 | $attachment->setName('TestAttachment'); |
||
124 | $attachment->setURL('www.foo.bar'); |
||
125 | $attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); |
||
126 | $part->addAttachment($attachment); |
||
127 | |||
128 | $attachment = new PartAttachment(); |
||
129 | $attachment->setName('Test2'); |
||
130 | $attachment->setPath('invalid'); |
||
131 | $attachment->setShowInTable(true); |
||
132 | $attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); |
||
133 | $part->addAttachment($attachment); |
||
134 | |||
135 | $manager->persist($part); |
||
136 | $manager->flush(); |
||
137 | } |
||
139 |