CreateEcommerceVariations::remove()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
3
/**
4
 * this class helps to create/edit/delete variations
5
 *
6
 *
7
 */
8
9
class CreateEcommerceVariations extends Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        "jsonforform" => "ADMIN",
13
        "createvariations",
14
        "select",
15
        "rename",
16
        "add",
17
        "remove",
18
        "move",
19
        'cansavevariation'
20
    );
21
22
    /**
23
     * The selected Product (ID)
24
     * @var Int
25
     */
26
    protected $_productID = 0;
27
28
    /**
29
     * The select Product (Object)
30
     * @var Product
31
     */
32
    protected $_product = null;
33
34
    /**
35
     * type | value
36
     * @var String
37
     */
38
    protected $_typeorvalue = "type"; // or value!
39
40
    /**
41
     * ProductAttributeValue | ProductAttributeType
42
     * @var String
43
     */
44
    protected $_classname = "type"; // or value!
45
46
    /**
47
     * Name of the Name field
48
     * @var String
49
     */
50
    protected $_namefield = "Name";
51
52
    /**
53
     * Name of the Label field
54
     * only for ProductAttributeType
55
     * @var String
56
     */
57
    protected $_labelfield = "Label";
58
59
    /**
60
     * Id of the item being altered
61
     * or its parent...
62
     * @var Int
63
     */
64
    protected $_id = 0;
65
66
    /**
67
     * Value of the item being altered
68
     * @var String
69
     */
70
    protected $_value = "";
71
72
    /**
73
     * Position in the sorting order
74
     * use -1 to distinguish it from 0 (first in sorting order)
75
     * @var Int
76
     */
77
    protected $_position = -1;
78
79
    /**
80
     * Return message
81
     * @var String
82
     */
83
    protected $_message = "";
84
85
    /**
86
     * Type of message
87
     * good | bad | warning
88
     * @var String
89
     */
90
    protected $_messageclass = "good";
91
92
    /**
93
     * Type IDs that are selected in the PRODUCT
94
     * @var Array
95
     */
96
    protected $_selectedtypeid = array();
97
98
    /**
99
     * Value IDs that are selected in the PRODUCT
100
     * @var Array
101
     */
102
    protected $_selectedvalueid = array();
103
104
    /**
105
     * What is going to be sent back.
106
     * @var String
107
     */
108
    protected $output = "";
109
110
    /**
111
     * The name for the session varilable.
112
     * @var String
113
     */
114
    private static $session_name_for_selected_values = "SelectecedValues";
0 ignored issues
show
Unused Code introduced by
The property $session_name_for_selected_values is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
115
116
    /**
117
     *
118
     * @var String
119
     */
120
    private static $url_segment = "createecommercevariations";
0 ignored issues
show
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
121
122
    public function init()
0 ignored issues
show
Coding Style introduced by
init uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
123
    {
124
        parent::init();
125
        Versioned::set_reading_mode("Stage.Stage");
126
        $shopAdminCode = EcommerceConfig::get("EcommerceRole", "admin_permission_code");
127
        if (!Permission::check("CMS_ACCESS_CMSMain") && !Permission::check($shopAdminCode)) {
128
            return Security::permissionFailure($this, _t('Security.PERMFAILURE', ' This page is secured and you need CMS rights to access it. Enter your credentials below and we will send you right along.'));
129
        }
130
        if (isset($_GET["typeorvalue"])) {
131
            $this->_typeorvalue = $_GET["typeorvalue"];
132
        }
133
        if (isset($_GET["id"])) {
134
            $this->_id = intval($_GET["id"]);
135
        }
136
        if (isset($_GET["value"])) {
137
            $this->_value = urldecode($_GET["value"]);
138
        }
139
        if (isset($_GET["position"])) {
140
            $this->_position = intval($_GET["_position"]);
141
        }
142
        if ($this->_typeorvalue == "type") {
143
            $this->_classname = 'ProductAttributeType';
144
            $this->_namefield = 'Name';
145
        } else {
146
            $this->_classname = 'ProductAttributeValue';
147
            $this->_namefield = 'Value';
148
        }
149
150
        $this->_productID = $this->request->param("ProductID");
0 ignored issues
show
Documentation Bug introduced by
The property $_productID was declared of type integer, but $this->request->param('ProductID') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
151
        $this->_product = Product::get()->byID($this->_productID);
152
        if (!$this->_product) {
153
            user_error("could not find product for ID: ".$this->_productID, E_USER_WARNING);
154
        }
155
        $this->_selectedtypeid = $this->_product->getArrayOfLinkedProductAttributeTypeIDs();
156
        $this->_selectedvalueid = $this->_product->getArrayOfLinkedProductAttributeValueIDs();
157
    }
158
159
160
    public function Link($action = null)
161
    {
162
        return Controller::join_links(
163
            Director::baseURL(),
164
            $this->Config()->get("url_segment"),
165
            $action
166
        );
167
    }
168
169
    public function index()
170
    {
171
        return 10;
172
    }
173
174
    public function Output()
175
    {
176
        return $this->output;
177
    }
178
179
    /**
180
     *
181
     * checks the selected types and values and
182
     * makes variations from it...
183
     */
184
    public function createvariations()
0 ignored issues
show
Coding Style introduced by
createvariations uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
185
    {
186
        //lazy array
187
        $missingTypesID = array(-1 => -1);
188
        $missingTypes = array();
0 ignored issues
show
Unused Code introduced by
$missingTypes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
189
        foreach ($this->_selectedtypeid as $typeID) {
190
            if (! isset($_GET[$typeID])) {
191
                $missingTypesID[$typeID] = $typeID;
192
            }
193
        }
194
        $types = ProductAttributeType::get()->exclude(array("ID" => $missingTypesID));
195
        if ($types->count()) {
196
            $allTypesAndValues = array();
197
            foreach ($types as $type) {
198
                if (isset($_GET[$type->ID])) {
199
                    $oldValuesArray = explode(',', $_GET[$type->ID]);
200
                    $newValuesArray = array();
201
                    foreach ($oldValuesArray as $oldValuesArray_Key => $oldValuesArray_Value) {
202
                        $newValuesArray[$oldValuesArray_Value] = $oldValuesArray_Value;
203
                    }
204
                    $allTypesAndValues[$type->ID] = $newValuesArray;
205
                }
206
            }
207
            $cpt = 0;
208
            if (count($allTypesAndValues) > 0) {
209
                //create the variations...
210
                $cpt = $this->_product->generateVariationsFromAttributeValues($allTypesAndValues);
211
                //reset values in this class ...
212
                $this->_selectedtypeid = $this->_product->getArrayOfLinkedProductAttributeTypeIDs();
213
                $this->_selectedvalueid = $this->_product->getArrayOfLinkedProductAttributeValueIDs();
214
            }
215
            if ($cpt > 0) {
216
                $this->_message = ($cpt == 1 ? '1 new variation has' : "$cpt new variations have") . ' been created successfully';
217
            } else {
218
                $this->_message = 'No new variations created';
219
            }
220
        } else {
221
            $this->_message = 'No attribute types';
222
        }
223
        $this->output = $this->jsonforform();
224
        return $this->output;
225
    }
226
227
228
    /**
229
     *
230
     * @return String
231
     */
232
    public function jsonforform()
233
    {
234
        if (! $this->_message) {
235
            $this->_message = _t("CreateEcommerceVariations.STARTEDITING", "Start editing the list below to create variations.");
236
        }
237
        $result['Message'] = $this->_message;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = 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...
238
        $result['MessageClass'] = $this->_messageclass;
239
        $types = ProductAttributeType::get();
240
        if ($types->count()) {
241
            foreach ($types as $type) {
242
                $resultType = array(
243
                    'ID' => $type->ID,
244
                    'Name' => $type->Name,
245
                    'EditLink' => $type->CMSEditLink(),
246
                    'Checked' => isset($this->_selectedtypeid[$type->ID]),
247
                    'Disabled' => ! $this->_product->canRemoveAttributeType($type),
248
                    'CanDelete' => $type->canDelete()
249
                );
250
                $values = $type->Values();
251
                if ($values) {
252
                    foreach ($values as $value) {
253
                        $resultType['Values'][] = array(
254
                            'ID' => $value->ID,
255
                            'Name' => $value->Value,
256
                            'EditLink' => $value->CMSEditLink(),
257
                            'Checked' => isset($this->_selectedvalueid[$value->ID]),
258
                            'CanDelete' => $value->canDelete()
259
                        );
260
                    }
261
                }
262
                $result['Types'][] = $resultType;
263
            }
264
        }
265
        $this->output =  Convert::array2json($result);
266
        return $this->output;
267
    }
268
269
    public function select()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
270
    {
271
        // is it type of Value?
272
        // if type is value -> create / delete Product Variation (if allowed)
273
        // elseif type is type - > add / remove selection...
274
        $this->_product->addAttributeType($obj);
0 ignored issues
show
Bug introduced by
The variable $obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
275
        $this->_product->removeAttributeType($obj);
276
        die("not completed yet");
0 ignored issues
show
Coding Style Compatibility introduced by
The method select() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
277
        $this->output =  $this->jsonforform();
0 ignored issues
show
Unused Code introduced by
$this->output = $this->jsonforform(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
278
        return $this->output;
279
    }
280
281
    public function rename()
282
    {
283
        //is it Type or Value?
284
        $className = $this->_classname;
285
        $obj = $className::get()->byID($this->_id);
286
        if ($obj) {
287
            $name = $obj->{$this->_namefield};
288
            if ($obj instanceof ProductAttributeType) {
289
                $obj->{$this->_labelfield} = $this->_value;
290
                $name .= " (".$obj->{$this->_labelfield}.")";
291
            }
292
            $obj->{$this->_namefield} = $this->_value;
293
            $obj->write();
294
            $this->_message = _t("CreateEcommerceVariations.HASBEENRENAMED", "$name has been renamed to ".$this->_value, ".");
295
        } else {
296
            $this->_message = _t("CreateEcommerceVariations.CANNOTBEFOUND", "Entry can not be found.");
297
            $this->_messageclass = "bad";
298
        }
299
        $this->output =  $this->jsonforform();
300
        return $this->output;
301
    }
302
303
    /**
304
     * add a Type or a Value
305
     */
306
    public function add()
307
    {
308
        //is it Type or Value?
309
        $obj = new $this->_classname();
310
        $obj->{$this->_namefield} = $this->_value;
311
        if ($this->_id) {
312
            $obj->TypeID = $this->_id;
313
            $obj->write();
314
        } else {
315
            $obj->write();
316
            if ($obj instanceof ProductAttributeType) {
317
                $this->_product->addAttributeType($obj);
318
            }
319
        }
320
        $this->_selectedtypeid = $this->_product->getArrayOfLinkedProductAttributeTypeIDs();
321
        $this->_selectedvalueid = $this->_product->getArrayOfLinkedProductAttributeValueIDs();
322
        $this->_message = $this->_value.' '._t("CreateEcommerceVariations.HASBEENADDED", 'has been added.');
323
        $this->output =  $this->jsonforform();
324
        return $this->output;
325
    }
326
327
    /**
328
     * remove a Type or a Value
329
     */
330
    public function remove()
331
    {
332
        //is it Type or Value?
333
        $className = $this->_classname;
334
        $obj = $className::get()->byID($this->_id);
335
        if ($obj) {
336
            $name = $obj->{$this->_namefield};
337
            if ($obj->canDelete()) {
338
                if ($this->_typeorvalue == "type") {
339
                    $this->_product->removeAttributeType($obj);
340
                }
341
                $obj->delete();
342
                $obj->destroy();
343
                $this->_selectedtypeid = $this->_product->getArrayOfLinkedProductAttributeTypeIDs();
344
                $this->_selectedvalueid = $this->_product->getArrayOfLinkedProductAttributeValueIDs();
345
                $this->_message = _t("CreateEcommerceVariations.HASBEENDELETED", "$name has been deleted.");
346
            } else {
347
                $this->_message = _t("CreateEcommerceVariations.CANNOTBEDELETED", "$name can not be deleted (it is probably used in a sale).");
348
                $this->_messageclass = "bad";
349
            }
350
        } else {
351
            $this->_message = _t("CreateEcommerceVariations.CANNOTBEFOUND", "Entry can not be found.");
352
            $this->_messageclass = "bad";
353
        }
354
        $this->output =  $this->jsonforform();
355
        return $this->output;
356
    }
357
358
    public function move()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
359
    {
360
        //is it Type or Value?
361
        //move Item
362
        die("not completed yet");
0 ignored issues
show
Coding Style Compatibility introduced by
The method move() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
363
        $this->output =  "ok";
0 ignored issues
show
Unused Code introduced by
$this->output = 'ok'; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
364
        return $this->output;
365
    }
366
367
    /**
368
     *
369
     *
370
     * @return Boolean
371
     */
372
    public function cansavevariation()
0 ignored issues
show
Coding Style introduced by
cansavevariation uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
373
    {
374
        $variation = null;
375
        if (isset($_GET['variation'])) {
376
            $obj = ProductVariation::get()->byID(intval($_GET['variation']));
0 ignored issues
show
Unused Code introduced by
$obj is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
377
        }
378
        foreach ($this->_selectedtypeid as $typeID) {
379
            if (isset($_GET[$typeID])) {
380
                $value = $_GET[$typeID];
381
                if (! $variation && ! $value) {
382
                    $this->output =  false;
0 ignored issues
show
Documentation Bug introduced by
The property $output was declared of type string, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
383
                    return $this->output;
384
                }
385
                if ($value) {
386
                    $values[$typeID] = $value;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $values = 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...
387
                }
388
            } else {
389
                $this->output =  false;
390
                return $this->output;
391
            }
392
        }
393
        $variations = $this->_product->getComponents('Variations', $variation ? "\"ProductVariation\".\"ID\" != '$variation->ID'" : '');
394
        foreach ($variations as $otherVariation) {
395
            $otherValues = DB::query(
396
                "
397
                SELECT \"TypeID\", \"ProductAttributeValueID\"
398
                FROM \"ProductVariation_AttributeValues\"
399
                    INNER JOIN \"ProductAttributeValue\" ON \"ProductAttributeValue\".\"ID\" = \"ProductAttributeValueID\"
400
                WHERE \"ProductVariationID\" = '$otherVariation->ID' ORDER BY \"TypeID\""
401
            )->map()->toArray();
402
            if ($otherValues == $values) {
0 ignored issues
show
Bug introduced by
The variable $values does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
403
                $this->output =  false;
404
                return $this->output;
405
            }
406
        }
407
        $this->output =  true;
0 ignored issues
show
Documentation Bug introduced by
The property $output was declared of type string, but true is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
408
        return $this->output;
409
    }
410
}
411
412
413
class CreateEcommerceVariations_Field extends LiteralField
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
414
{
415
    public function __construct($name, $additionalContent = '', $productID)
0 ignored issues
show
Unused Code introduced by
The parameter $productID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
416
    {
417
        Requirements::themedCSS("CreateEcommerceVariationsField", "ecommerce_product_variation");
418
        $additionalContent .= $this->renderWith("CreateEcommerceVariations_Field");
419
        parent::__construct($name, $additionalContent);
420
    }
421
422
    public function ProductVariationGetPluralName()
423
    {
424
        return Convert::raw2att(singleton("ProductVariation")->plural_name());
425
    }
426
427
    public function ProductAttributeTypeGetPluralName()
428
    {
429
        return Convert::raw2att(singleton("ProductAttributeType")->plural_name());
430
    }
431
    public function ProductAttributeValueGetPluralName()
432
    {
433
        return Convert::raw2att(singleton("ProductAttributeValue")->plural_name());
434
    }
435
436
    public function CheckboxField($name, $title)
437
    {
438
        return new CheckboxField($name, $title);
439
    }
440
    public function TextField($name, $title)
441
    {
442
        return new TextField($name, $title);
443
    }
444
445 View Code Duplication
    public function AttributeSorterLink()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
446
    {
447
        $singleton = singleton("ProductAttributeType");
448
        if (class_exists("DataObjectSorterController") && $singleton->hasExtension("DataObjectSorterDOD")) {
449
            return DataObjectSorterController::popup_link($className = "ProductAttributeType", $filterField = "", $filterValue = "", $linkText = "Sort Types");
450
        }
451
    }
452 View Code Duplication
    public function ValueSorterLink()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
453
    {
454
        $singleton = singleton("ProductAttributeValue");
455
        if (class_exists("DataObjectSorterController") && $singleton->hasExtension("DataObjectSorterDOD")) {
456
            return DataObjectSorterController::popup_link($className = "ProductAttributeValue", $filterField = "TypeChangeToId", $filterValue = "ID", $linkText = "Sort Values");
457
        }
458
    }
459
}
460