This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Behat\Context\Setup; |
||
15 | |||
16 | use Behat\Behat\Context\Context; |
||
17 | use Behat\Mink\Element\NodeElement; |
||
18 | use Doctrine\Common\Persistence\ObjectManager; |
||
19 | use Sylius\Component\Core\Formatter\StringInflector; |
||
20 | use Sylius\Component\Core\Model\ImageInterface; |
||
21 | use Sylius\Component\Core\Model\TaxonInterface; |
||
22 | use Sylius\Component\Core\Uploader\ImageUploaderInterface; |
||
23 | use Sylius\Component\Resource\Factory\FactoryInterface; |
||
24 | use Sylius\Component\Resource\Repository\RepositoryInterface; |
||
25 | use Sylius\Component\Taxonomy\Generator\TaxonSlugGeneratorInterface; |
||
26 | use Sylius\Component\Taxonomy\Model\TaxonTranslationInterface; |
||
27 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
||
28 | |||
29 | final class TaxonomyContext implements Context |
||
30 | { |
||
31 | /** |
||
32 | * @var RepositoryInterface |
||
33 | */ |
||
34 | private $taxonRepository; |
||
35 | |||
36 | /** |
||
37 | * @var FactoryInterface |
||
38 | */ |
||
39 | private $taxonFactory; |
||
40 | |||
41 | /** |
||
42 | * @var FactoryInterface |
||
43 | */ |
||
44 | private $taxonTranslationFactory; |
||
45 | |||
46 | /** |
||
47 | * @var FactoryInterface |
||
48 | */ |
||
49 | private $taxonImageFactory; |
||
50 | |||
51 | /** |
||
52 | * @var ObjectManager |
||
53 | */ |
||
54 | private $objectManager; |
||
55 | |||
56 | /** |
||
57 | * @var ImageUploaderInterface |
||
58 | */ |
||
59 | private $imageUploader; |
||
60 | |||
61 | /** |
||
62 | * @var TaxonSlugGeneratorInterface |
||
63 | */ |
||
64 | private $taxonSlugGenerator; |
||
65 | |||
66 | /** |
||
67 | * @var array |
||
68 | */ |
||
69 | private $minkParameters; |
||
70 | |||
71 | /** |
||
72 | * @param RepositoryInterface $taxonRepository |
||
73 | * @param FactoryInterface $taxonFactory |
||
74 | * @param FactoryInterface $taxonTranslationFactory |
||
75 | * @param FactoryInterface $taxonImageFactory |
||
76 | * @param ObjectManager $objectManager |
||
77 | * @param ImageUploaderInterface $imageUploader |
||
78 | * @param TaxonSlugGeneratorInterface $taxonSlugGenerator |
||
79 | * @param array $minkParameters |
||
80 | */ |
||
81 | public function __construct( |
||
82 | RepositoryInterface $taxonRepository, |
||
83 | FactoryInterface $taxonFactory, |
||
84 | FactoryInterface $taxonTranslationFactory, |
||
85 | FactoryInterface $taxonImageFactory, |
||
86 | ObjectManager $objectManager, |
||
87 | ImageUploaderInterface $imageUploader, |
||
88 | TaxonSlugGeneratorInterface $taxonSlugGenerator, |
||
89 | array $minkParameters |
||
90 | ) { |
||
91 | $this->taxonRepository = $taxonRepository; |
||
92 | $this->taxonFactory = $taxonFactory; |
||
93 | $this->taxonTranslationFactory = $taxonTranslationFactory; |
||
94 | $this->taxonImageFactory = $taxonImageFactory; |
||
95 | $this->objectManager = $objectManager; |
||
96 | $this->imageUploader = $imageUploader; |
||
97 | $this->taxonSlugGenerator = $taxonSlugGenerator; |
||
98 | $this->minkParameters = $minkParameters; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @Given the store has :firstTaxonName taxonomy |
||
103 | * @Given the store classifies its products as :firstTaxonName |
||
104 | * @Given the store classifies its products as :firstTaxonName and :secondTaxonName |
||
105 | * @Given the store classifies its products as :firstTaxonName, :secondTaxonName and :thirdTaxonName |
||
106 | * @Given the store classifies its products as :firstTaxonName, :secondTaxonName, :thirdTaxonName and :fourthTaxonName |
||
107 | */ |
||
108 | public function storeClassifiesItsProductsAs(...$taxonsNames) |
||
109 | { |
||
110 | foreach ($taxonsNames as $taxonName) { |
||
111 | $this->taxonRepository->add($this->createTaxon($taxonName)); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @Given /^the store has taxonomy named "([^"]+)" in ("[^"]+" locale) and "([^"]+)" in ("[^"]+" locale)$/ |
||
117 | */ |
||
118 | public function theStoreHasTaxonomyNamedInAndIn($firstName, $firstLocale, $secondName, $secondLocale) |
||
119 | { |
||
120 | $translationMap = [ |
||
121 | $firstLocale => $firstName, |
||
122 | $secondLocale => $secondName, |
||
123 | ]; |
||
124 | |||
125 | $this->taxonRepository->add($this->createTaxonInManyLanguages($translationMap)); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @Given /^the ("[^"]+" taxon)(?:| also) has an image "([^"]+)" with "([^"]+)" type$/ |
||
130 | */ |
||
131 | public function theTaxonHasAnImageWithType(TaxonInterface $taxon, $imagePath, $imageType) |
||
132 | { |
||
133 | $filesPath = $this->getParameter('files_path'); |
||
134 | |||
135 | /** @var ImageInterface $taxonImage */ |
||
136 | $taxonImage = $this->taxonImageFactory->createNew(); |
||
137 | $taxonImage->setFile(new UploadedFile($filesPath . $imagePath, basename($imagePath))); |
||
138 | $taxonImage->setType($imageType); |
||
139 | $this->imageUploader->upload($taxonImage); |
||
140 | |||
141 | $taxon->addImage($taxonImage); |
||
142 | |||
143 | $this->objectManager->persist($taxon); |
||
144 | $this->objectManager->flush(); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @Given /^the ("[^"]+" taxon) has children taxon "([^"]+)" and "([^"]+)"$/ |
||
149 | */ |
||
150 | public function theTaxonHasChildrenTaxonAnd(TaxonInterface $taxon, $firstTaxonName, $secondTaxonName) |
||
151 | { |
||
152 | $taxon->addChild($this->createTaxon($firstTaxonName)); |
||
0 ignored issues
–
show
|
|||
153 | $taxon->addChild($this->createTaxon($secondTaxonName)); |
||
0 ignored issues
–
show
$this->createTaxon($secondTaxonName) is of type object<Sylius\Component\...e\Model\TaxonInterface> , but the function expects a object<self> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
154 | |||
155 | $this->objectManager->persist($taxon); |
||
156 | $this->objectManager->flush(); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @param string $name |
||
161 | * |
||
162 | * @return TaxonInterface |
||
163 | */ |
||
164 | private function createTaxon($name) |
||
165 | { |
||
166 | /** @var TaxonInterface $taxon */ |
||
167 | $taxon = $this->taxonFactory->createNew(); |
||
168 | $taxon->setName($name); |
||
169 | $taxon->setCode(StringInflector::nameToCode($name)); |
||
170 | $taxon->setSlug($this->taxonSlugGenerator->generate($taxon)); |
||
171 | |||
172 | return $taxon; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @param array $names |
||
177 | * |
||
178 | * @return TaxonInterface |
||
179 | */ |
||
180 | private function createTaxonInManyLanguages(array $names) |
||
181 | { |
||
182 | /** @var TaxonInterface $taxon */ |
||
183 | $taxon = $this->taxonFactory->createNew(); |
||
184 | $taxon->setCode(StringInflector::nameToCode($names['en_US'])); |
||
185 | foreach ($names as $locale => $name) { |
||
186 | /** @var TaxonTranslationInterface $taxonTranslation */ |
||
187 | $taxonTranslation = $this->taxonTranslationFactory->createNew(); |
||
188 | $taxonTranslation->setLocale($locale); |
||
189 | $taxonTranslation->setName($name); |
||
190 | |||
191 | $taxon->addTranslation($taxonTranslation); |
||
192 | |||
193 | $taxonTranslation->setSlug($this->taxonSlugGenerator->generate($taxon, $locale)); |
||
194 | } |
||
195 | |||
196 | return $taxon; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @param string $name |
||
201 | * |
||
202 | * @return NodeElement |
||
203 | */ |
||
204 | private function getParameter($name) |
||
205 | { |
||
206 | return $this->minkParameters[$name] ?? null; |
||
207 | } |
||
208 | } |
||
209 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: