Issues (244)

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.

src/Sylius/Behat/Context/Setup/TaxonomyContext.php (2 issues)

Severity

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
/*
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
$this->createTaxon($firstTaxonName) 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...
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