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 | namespace Oro\Bundle\AddressBundle\Migrations\Data\ORM; |
||
4 | |||
5 | use Doctrine\Common\Persistence\ObjectManager; |
||
6 | use Doctrine\ORM\EntityRepository; |
||
7 | |||
8 | use Oro\Bundle\MigrationBundle\Fixture\VersionedFixtureInterface; |
||
9 | use Oro\Bundle\TranslationBundle\DataFixtures\AbstractTranslatableEntityFixture; |
||
10 | use Oro\Bundle\AddressBundle\Entity\Country; |
||
11 | use Oro\Bundle\AddressBundle\Entity\Region; |
||
12 | |||
13 | use Symfony\Component\Yaml\Yaml; |
||
14 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||
15 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
16 | |||
17 | class LoadCountryData extends AbstractTranslatableEntityFixture implements |
||
18 | VersionedFixtureInterface, |
||
19 | ContainerAwareInterface |
||
20 | { |
||
21 | const COUNTRY_PREFIX = 'country'; |
||
22 | const REGION_PREFIX = 'region'; |
||
23 | |||
24 | /** |
||
25 | * @var EntityRepository |
||
26 | */ |
||
27 | protected $countryRepository; |
||
28 | |||
29 | /** |
||
30 | * @var EntityRepository |
||
31 | */ |
||
32 | protected $regionRepository; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $structureFileName = '/data/countries.yml'; |
||
38 | |||
39 | /** |
||
40 | * @var ContainerInterface |
||
41 | */ |
||
42 | protected $container; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function setContainer(ContainerInterface $container = null) |
||
48 | { |
||
49 | $this->container = $container; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function getVersion() |
||
56 | { |
||
57 | return '1.0'; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | protected function loadEntities(ObjectManager $manager) |
||
64 | { |
||
65 | $fileName = $this->getFileName(); |
||
66 | $countries = $this->getDataFromFile($fileName); |
||
67 | $this->loadCountriesAndRegions($manager, $countries); |
||
0 ignored issues
–
show
|
|||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | protected function getFileName() |
||
74 | { |
||
75 | return $this->container |
||
76 | ->get('kernel') |
||
77 | ->locateResource('@OroAddressBundle/Migrations/Data/ORM' . $this->structureFileName); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param string $fileName |
||
82 | * @return bool |
||
83 | */ |
||
84 | protected function isFileAvailable($fileName) |
||
85 | { |
||
86 | return is_file($fileName) && is_readable($fileName); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param string $fileName |
||
91 | * @return array |
||
92 | * @throws \LogicException |
||
93 | */ |
||
94 | View Code Duplication | protected function getDataFromFile($fileName) |
|
95 | { |
||
96 | if (!$this->isFileAvailable($fileName)) { |
||
97 | throw new \LogicException('File ' . $fileName . 'is not available'); |
||
98 | } |
||
99 | |||
100 | $fileName = realpath($fileName); |
||
101 | |||
102 | return Yaml::parse(file_get_contents($fileName)); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param string $locale |
||
107 | * @param array $countryData |
||
108 | * @return null|Country |
||
109 | */ |
||
110 | View Code Duplication | protected function getCountry($locale, array $countryData) |
|
111 | { |
||
112 | if (empty($countryData['iso2Code']) || empty($countryData['iso3Code'])) { |
||
113 | return null; |
||
114 | } |
||
115 | |||
116 | /** @var $country Country */ |
||
117 | $country = $this->countryRepository->findOneBy(array('iso2Code' => $countryData['iso2Code'])); |
||
118 | if (!$country) { |
||
119 | $country = new Country($countryData['iso2Code']); |
||
120 | $country->setIso3Code($countryData['iso3Code']); |
||
121 | } |
||
122 | |||
123 | $countryName = $this->translate($countryData['iso2Code'], static::COUNTRY_PREFIX, $locale); |
||
124 | |||
125 | $country->setLocale($locale) |
||
126 | ->setName($countryName); |
||
127 | |||
128 | return $country; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @param string $locale |
||
133 | * @param Country $country |
||
134 | * @param array $regionData |
||
135 | * @return null|Region |
||
136 | */ |
||
137 | View Code Duplication | protected function getRegion($locale, Country $country, array $regionData) |
|
138 | { |
||
139 | if (empty($regionData['combinedCode']) || empty($regionData['code'])) { |
||
140 | return null; |
||
141 | } |
||
142 | |||
143 | /** @var $region Region */ |
||
144 | $region = $this->regionRepository->findOneBy(array('combinedCode' => $regionData['combinedCode'])); |
||
145 | if (!$region) { |
||
146 | $region = new Region($regionData['combinedCode']); |
||
147 | $region->setCode($regionData['code']) |
||
148 | ->setCountry($country); |
||
149 | } |
||
150 | |||
151 | $regionName = $this->translate($regionData['combinedCode'], static::REGION_PREFIX, $locale); |
||
152 | |||
153 | $region->setLocale($locale) |
||
154 | ->setName($regionName); |
||
155 | |||
156 | return $region; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Load countries and regions to DB |
||
161 | * |
||
162 | * @param ObjectManager $manager |
||
163 | * @param array $countries |
||
164 | */ |
||
165 | protected function loadCountriesAndRegions(ObjectManager $manager, array $countries) |
||
166 | { |
||
167 | $this->countryRepository = $manager->getRepository('OroAddressBundle:Country'); |
||
168 | $this->regionRepository = $manager->getRepository('OroAddressBundle:Region'); |
||
169 | |||
170 | $translationLocales = $this->getTranslationLocales(); |
||
171 | |||
172 | foreach ($translationLocales as $locale) { |
||
173 | foreach ($countries as $countryData) { |
||
174 | $country = $this->getCountry($locale, $countryData); |
||
0 ignored issues
–
show
Are you sure the assignment to
$country is correct as $this->getCountry($locale, $countryData) (which targets Oro\Bundle\AddressBundle...untryData::getCountry() ) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||
175 | if (!$country) { |
||
176 | continue; |
||
177 | } |
||
178 | |||
179 | $manager->persist($country); |
||
180 | |||
181 | if (!empty($countryData['regions'])) { |
||
182 | foreach ($countryData['regions'] as $regionData) { |
||
183 | $region = $this->getRegion($locale, $country, $regionData); |
||
0 ignored issues
–
show
Are you sure the assignment to
$region is correct as $this->getRegion($locale, $country, $regionData) (which targets Oro\Bundle\AddressBundle...ountryData::getRegion() ) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||
184 | if (!$region) { |
||
185 | continue; |
||
186 | } |
||
187 | |||
188 | $manager->persist($region); |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | |||
193 | $manager->flush(); |
||
194 | $manager->clear(); |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.