Issues (116)

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.

Form/Admin/ShippingMethodFormBuilder.php (1 issue)

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
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
namespace WellCommerce\Bundle\OrderBundle\Form\Admin;
13
14
use Doctrine\Common\Collections\Collection;
15
use WellCommerce\Bundle\CoreBundle\Form\AbstractFormBuilder;
16
use WellCommerce\Bundle\OrderBundle\Calculator\ShippingCalculatorInterface;
17
use WellCommerce\Component\Form\Elements\FormInterface;
18
19
/**
20
 * Class ShippingMethodFormBuilder
21
 *
22
 * @author  Adam Piotrowski <[email protected]>
23
 */
24
class ShippingMethodFormBuilder extends AbstractFormBuilder
25
{
26
    protected $calculators;
27
    
28
    public function getAlias(): string
29
    {
30
        return 'admin.shipping_method';
31
    }
32
    
33
    public function buildForm(FormInterface $form)
34
    {
35
        $calculatorOptions = [];
36
        $calculators       = $this->getCalculators();
37
        
38
        $calculators->map(function (ShippingCalculatorInterface $calculator) use (&$calculatorOptions) {
39
            $calculatorOptions[$calculator->getAlias()] = $calculator->getAlias();
40
        });
41
    
42
        $currencies = $this->get('currency.dataset.admin')->getResult('select', ['order_by' => 'code'], [
43
            'label_column' => 'code',
44
            'value_column' => 'id',
45
        ]);
46
        
47
        $requiredData = $form->addChild($this->getElement('nested_fieldset', [
48
            'name'  => 'required_data',
49
            'label' => 'common.fieldset.general'
50
        ]));
51
        
52
        $languageData = $requiredData->addChild($this->getElement('language_fieldset', [
53
            'name'        => 'translations',
54
            'label'       => 'common.fieldset.translations',
55
            'transformer' => $this->getRepositoryTransformer('translation', $this->get('shipping_method.repository'))
56
        ]));
57
        
58
        $languageData->addChild($this->getElement('text_field', [
59
            'name'  => 'name',
60
            'label' => 'common.label.name',
61
            'rules' => [
62
                $this->getRule('required')
63
            ],
64
        ]));
65
        
66
        $requiredData->addChild($this->getElement('checkbox', [
67
            'name'  => 'enabled',
68
            'label' => 'common.label.enabled',
69
        ]));
70
        
71
        $requiredData->addChild($this->getElement('text_field', [
72
            'name'  => 'hierarchy',
73
            'label' => 'common.label.hierarchy',
74
            'rules' => [
75
                $this->getRule('required')
76
            ],
77
        ]));
78
        
79
        $requiredData->addChild($this->getElement('select', [
80
            'name'    => 'optionsProvider',
81
            'label'   => 'shipping_method.label.options_provider',
82
            'options' => $this->getOptionProviders()
83
        ]));
84
    
85
        $clientGroupData = $form->addChild($this->getElement('nested_fieldset', [
86
            'name'  => 'client_group_data',
87
            'label' => 'shipping_method.fieldset.client_groups'
88
        ]));
89
    
90
        $clientGroupData->addChild($this->getElement('tip', [
91
            'tip' => 'shipping_method.tip.client_groups',
92
        ]));
93
        
94
        $clientGroupData->addChild($this->getElement('multi_select', [
95
            'name'        => 'clientGroups',
96
            'label'       => 'shipping_method.label.client_groups',
97
            'options'     => $this->get('client_group.dataset.admin')->getResult('select'),
98
            'transformer' => $this->getRepositoryTransformer('collection', $this->get('client_group.repository')),
99
        ]));
100
        
101
        $costsData = $form->addChild($this->getElement('nested_fieldset', [
102
            'name'  => 'costs_data',
103
            'label' => 'shipping_method.fieldset.costs'
104
        ]));
105
        
106
        $costsData->addChild($this->getElement('select', [
107
            'name'    => 'calculator',
108
            'label'   => 'shipping_method.label.calculator',
109
            'options' => $calculatorOptions
110
        ]));
111
        
112
        $costsData->addChild($this->getElement('select', [
113
            'name'        => 'currency',
114
            'label'       => 'common.label.currency',
115
            'options'     => $currencies,
116
            'transformer' => $this->getRepositoryTransformer('entity', $this->get('currency.repository'))
117
        ]));
118
        
119
        $tax = $costsData->addChild($this->getElement('select', [
120
            'name'        => 'tax',
121
            'label'       => 'common.label.tax',
122
            'options'     => $this->get('tax.dataset.admin')->getResult('select'),
123
            'transformer' => $this->getRepositoryTransformer('entity', $this->get('tax.repository'))
124
        ]));
125
        
126
        $costsData->addChild($this->getElement('range_editor', [
127
            'name'            => 'costs',
128
            'label'           => 'shipping_method.label.costs',
129
            'vat_field'       => $tax,
130
            'range_precision' => 2,
131
            'transformer'     => $this->getRepositoryTransformer('shipping_cost_collection', $this->get('shipping_method_cost.repository'))
132
        ]));
133
        
134
        $countriesData = $form->addChild($this->getElement('nested_fieldset', [
135
            'name'  => 'countries_data',
136
            'label' => 'shipping_method.fieldset.countries'
137
        ]));
138
        
139
        $countriesData->addChild($this->getElement('multi_select', [
140
            'name'    => 'countries',
141
            'label'   => 'address.label.country',
142
            'options' => $this->get('country.repository')->all(),
143
        ]));
144
    
145
        $dimensionData = $form->addChild($this->getElement('nested_fieldset', [
146
            'name'  => 'box_dimension',
147
            'label' => 'shipping_method.fieldset.box_dimension',
148
        ]));
149
    
150
        $dimensionData->addChild($this->getElement('text_field', [
151
            'name'    => 'boxDimension.width',
152
            'label'   => 'common.label.dimension.width',
153
            'filters' => [
154
                $this->getFilter('comma_to_dot_changer'),
155
            ],
156
        ]));
157
    
158
        $dimensionData->addChild($this->getElement('text_field', [
159
            'name'    => 'boxDimension.height',
160
            'label'   => 'common.label.dimension.height',
161
            'filters' => [
162
                $this->getFilter('comma_to_dot_changer'),
163
            ],
164
        ]));
165
    
166
        $dimensionData->addChild($this->getElement('text_field', [
167
            'name'    => 'boxDimension.depth',
168
            'label'   => 'common.label.dimension.depth',
169
            'filters' => [
170
                $this->getFilter('comma_to_dot_changer'),
171
            ],
172
        ]));
173
        
174
        $this->addShopsFieldset($form);
175
        
176
        $form->addFilter($this->getFilter('no_code'));
177
        $form->addFilter($this->getFilter('trim'));
178
        $form->addFilter($this->getFilter('secure'));
179
    }
180
    
181
    private function getCalculators() : Collection
182
    {
183
        return $this->get('shipping_method.calculator.collection');
184
    }
185
    
186
    private function getOptionProviders() : array
187
    {
188
        $providers           = $this->get('shipping_method.options_provider.collection');
189
        $optionProviders[''] = 'common.label.none';
0 ignored issues
show
Coding Style Comprehensibility introduced by Adam Piotrowski
$optionProviders was never initialized. Although not strictly required by PHP, it is generally a good practice to add $optionProviders = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
190
        
191
        foreach ($providers->getKeys() as $alias) {
192
            $optionProviders[$alias] = $alias;
193
        }
194
        
195
        return $optionProviders;
196
    }
197
}
198