1 | <?php |
||||
2 | /* |
||||
3 | * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
||||
4 | * |
||||
5 | * Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
||||
6 | * |
||||
7 | * This program is free software: you can redistribute it and/or modify |
||||
8 | * it under the terms of the GNU Affero General Public License as published |
||||
9 | * by the Free Software Foundation, either version 3 of the License, or |
||||
10 | * (at your option) any later version. |
||||
11 | * |
||||
12 | * This program is distributed in the hope that it will be useful, |
||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
15 | * GNU Affero General Public License for more details. |
||||
16 | * |
||||
17 | * You should have received a copy of the GNU Affero General Public License |
||||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
19 | */ |
||||
20 | |||||
21 | declare(strict_types=1); |
||||
22 | |||||
23 | /** |
||||
24 | * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
||||
25 | * |
||||
26 | * Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
||||
27 | * |
||||
28 | * This program is free software: you can redistribute it and/or modify |
||||
29 | * it under the terms of the GNU Affero General Public License as published |
||||
30 | * by the Free Software Foundation, either version 3 of the License, or |
||||
31 | * (at your option) any later version. |
||||
32 | * |
||||
33 | * This program is distributed in the hope that it will be useful, |
||||
34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
36 | * GNU Affero General Public License for more details. |
||||
37 | * |
||||
38 | * You should have received a copy of the GNU Affero General Public License |
||||
39 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
40 | */ |
||||
41 | |||||
42 | namespace App\DataFixtures; |
||||
43 | |||||
44 | use App\Entity\Attachments\AttachmentType; |
||||
45 | use App\Entity\Attachments\PartAttachment; |
||||
46 | use App\Entity\Parts\Category; |
||||
47 | use App\Entity\Parts\Footprint; |
||||
48 | use App\Entity\Parts\Manufacturer; |
||||
49 | use App\Entity\Parts\Part; |
||||
50 | use App\Entity\Parts\PartLot; |
||||
51 | use App\Entity\Parts\Storelocation; |
||||
52 | use App\Entity\Parts\Supplier; |
||||
53 | use App\Entity\PriceInformations\Orderdetail; |
||||
54 | use App\Entity\PriceInformations\Pricedetail; |
||||
55 | use Brick\Math\BigDecimal; |
||||
56 | use DateTime; |
||||
57 | use Doctrine\Bundle\FixturesBundle\Fixture; |
||||
58 | use Doctrine\ORM\EntityManagerInterface; |
||||
59 | use Doctrine\Persistence\ObjectManager; |
||||
60 | |||||
61 | class PartFixtures extends Fixture |
||||
62 | { |
||||
63 | protected EntityManagerInterface $em; |
||||
64 | |||||
65 | public function __construct(EntityManagerInterface $entityManager) |
||||
66 | { |
||||
67 | $this->em = $entityManager; |
||||
68 | } |
||||
69 | |||||
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)); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
110 | $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(BigDecimal::of('10.0'))); |
||||
0 ignored issues
–
show
It seems like
Brick\Math\BigDecimal::of('10.0') can also be of type Brick\Math\BigInteger and Brick\Math\BigRational ; however, parameter $new_price of App\Entity\PriceInformat...Pricedetail::setPrice() does only seem to accept Brick\Math\BigDecimal , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
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)); |
||||
0 ignored issues
–
show
It seems like
$manager->find(App\Entit...tachmentType::class, 1) can also be of type null ; however, parameter $attachement_type of App\Entity\Attachments\A...nt::setAttachmentType() does only seem to accept App\Entity\Attachments\AttachmentType , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
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 | } |
||||
138 | } |
||||
139 |