Conditions | 1 |
Paths | 1 |
Total Lines | 69 |
Code Lines | 55 |
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 |
||
53 | public function load(ObjectManager $manager) |
||
54 | { |
||
55 | $table_name = $this->em->getClassMetadata(Part::class)->getTableName(); |
||
|
|||
56 | $this->em->getConnection()->exec("ALTER TABLE `${table_name}` AUTO_INCREMENT = 1;"); |
||
57 | |||
58 | /** Simple part */ |
||
59 | $part = new Part(); |
||
60 | $part->setName('Part 1'); |
||
61 | $part->setCategory($manager->find(Category::class, 1)); |
||
62 | $manager->persist($part); |
||
63 | |||
64 | /** More complex part */ |
||
65 | $part = new Part(); |
||
66 | $part->setName('Part 2'); |
||
67 | $part->setCategory($manager->find(Category::class, 1)); |
||
68 | $part->setFootprint($manager->find(Footprint::class, 1)); |
||
69 | $part->setManufacturer($manager->find(Manufacturer::class, 1)); |
||
70 | $part->setTags('test, Test, Part2'); |
||
71 | $part->setMass(100.2); |
||
72 | $part->setNeedsReview(true); |
||
73 | $part->setManufacturingStatus('active'); |
||
74 | $manager->persist($part); |
||
75 | |||
76 | /** Part with orderdetails, storelocations and Attachments */ |
||
77 | $part = new Part(); |
||
78 | $part->setFavorite(true); |
||
79 | $part->setName('Part 2'); |
||
80 | $part->setCategory($manager->find(Category::class, 1)); |
||
81 | $partLot1 = new PartLot(); |
||
82 | $partLot1->setAmount(1.0); |
||
83 | $partLot1->setStorageLocation($manager->find(Storelocation::class, 1)); |
||
84 | $part->addPartLot($partLot1); |
||
85 | |||
86 | $partLot2 = new PartLot(); |
||
87 | $partLot2->setExpirationDate(new \DateTime()); |
||
88 | $partLot2->setComment('Test'); |
||
89 | $partLot2->setNeedsRefill(true); |
||
90 | $partLot2->setStorageLocation($manager->find(Storelocation::class, 3)); |
||
91 | $part->addPartLot($partLot2); |
||
92 | |||
93 | $orderdetail = new Orderdetail(); |
||
94 | $orderdetail->setSupplier($manager->find(Supplier::class, 1)); |
||
95 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(10)); |
||
96 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(15)); |
||
97 | $part->addOrderdetail($orderdetail); |
||
98 | |||
99 | $orderdetail = new Orderdetail(); |
||
100 | $orderdetail->setSupplierpartnr('BC 547'); |
||
101 | $orderdetail->setObsolete(true); |
||
102 | $orderdetail->setSupplier($manager->find(Supplier::class, 1)); |
||
103 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(10)); |
||
104 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(15)); |
||
105 | $part->addOrderdetail($orderdetail); |
||
106 | |||
107 | $attachment = new PartAttachment(); |
||
108 | $attachment->setName('TestAttachment'); |
||
109 | $attachment->setURL('www.foo.bar'); |
||
110 | $attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); |
||
111 | $part->addAttachment($attachment); |
||
112 | |||
113 | $attachment = new PartAttachment(); |
||
114 | $attachment->setName('Test2'); |
||
115 | $attachment->setPath('invalid'); |
||
116 | $attachment->setShowInTable(true); |
||
117 | $attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); |
||
118 | $part->addAttachment($attachment); |
||
119 | |||
120 | $manager->persist($part); |
||
121 | $manager->flush(); |
||
122 | } |
||
123 | } |