Issues (3887)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Migrations/Data/ORM/LoadCountryData.php (3 issues)

Upgrade to new PHP Analysis Engine

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
It seems like $countries defined by $this->getDataFromFile($fileName) on line 66 can also be of type string; however, Oro\Bundle\AddressBundle...adCountriesAndRegions() does only seem to accept array, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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 getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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 getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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