ShippingMethodAdmin   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getEditForm() 0 16 2
1
<?php
2
3
/**
4
 * @package silvershop-shipping
5
 */
6
class ShippingMethodAdmin extends ModelAdmin
7
{
8
    private static $url_segment = "shipping";
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...
9
10
    private static $menu_title = "Shipping";
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...
11
12
    private static $menu_priority = 3;
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...
13
14
    private static $menu_icon = 'silvershop-shipping/images/shipping.png';
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...
15
16
    private static $managed_models = 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...
17
        'ShippingMethod',
18
        'Warehouse'
19
    );
20
21
    public static $model_importers = array();
22
23
    public function getEditForm($id = null, $fields = null)
24
    {
25
        $form = parent::getEditForm($id, $fields);
26
        if ($this->modelClass === "ShippingMethod") {
27
            $gridfield = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
28
            $config = $gridfield->getConfig();
29
            $config->removeComponentsByType("GridFieldAddNewButton");
30
            $config->removeComponentsByType("GridFieldPrintButton");
31
            $config->removeComponentsByType("GridFieldExportButton");
32
            $config->addComponent($multiclass = new GridFieldAddNewMultiClass());
33
            $classes = ClassInfo::subclassesFor($this->modelClass);
34
            unset($classes[$this->modelClass]);
35
            $multiclass->setClasses($classes);
0 ignored issues
show
Bug introduced by
It seems like $classes defined by \ClassInfo::subclassesFor($this->modelClass) on line 33 can also be of type null; however, GridFieldAddNewMultiClass::setClasses() 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...
36
        }
37
        return $form;
38
    }
39
}
40