OrdersAdmin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 33
c 4
b 1
f 0
dl 0
loc 67
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEditForm() 0 31 3
A getList() 0 11 2
1
<?php
2
3
namespace SilverShop\Admin;
4
5
use SilverShop\Forms\GridField\OrderGridFieldDetailForm_ItemRequest;
6
use SilverShop\Model\Order;
7
use SilverShop\Model\OrderStatusLog;
8
use SilverStripe\Admin\ModelAdmin;
9
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
10
use SilverStripe\Forms\GridField\GridFieldDetailForm;
11
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
12
use SilverStripe\ORM\DataObject;
13
14
/**
15
 * Order administration interface, based on ModelAdmin
16
 *
17
 * @package SilverShop\Admin
18
 */
19
class OrdersAdmin extends ModelAdmin
20
{
21
    private static $url_segment = 'orders';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
22
23
    private static $menu_title = 'Orders';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
24
25
    private static $menu_priority = 1;
0 ignored issues
show
introduced by
The private property $menu_priority is not used, and could be removed.
Loading history...
26
27
    private static $menu_icon_class = 'silvershop-icon-cart';
0 ignored issues
show
introduced by
The private property $menu_icon_class is not used, and could be removed.
Loading history...
28
29
    private static $managed_models = [
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
30
        Order::class,
31
        OrderStatusLog::class
32
    ];
33
34
    private static $model_importers = [];
0 ignored issues
show
introduced by
The private property $model_importers is not used, and could be removed.
Loading history...
35
36
    /**
37
     * Restrict list to non-hidden statuses
38
     */
39
    public function getList()
40
    {
41
        $list = parent::getList();
42
43
        if ($this->modelClass == Order::class) {
44
            // Exclude hidden statuses
45
            $list = $list->exclude('Status', Order::config()->hidden_status);
46
            $this->extend('updateList', $list);
47
        }
48
49
        return $list;
50
    }
51
52
    /**
53
     * Replace gridfield detail form to include print functionality
54
     */
55
    public function getEditForm($id = null, $fields = null)
56
    {
57
        $form = parent::getEditForm($id, $fields);
58
        if ($this->modelClass == Order::class) {
59
            /** @var GridFieldConfig $config */
60
            $config = $form
0 ignored issues
show
Bug introduced by
Are you sure the usage of $form->Fields()->fieldBy...ame($this->modelClass)) targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
61
                ->Fields()
62
                ->fieldByName($this->sanitiseClassName($this->modelClass))
63
                ->getConfig();
64
65
            $config
66
                ->getComponentByType(GridFieldSortableHeader::class)
67
                ->setFieldSorting([ 'StatusI18N' => 'Status' ]);
68
69
            $config
70
                ->getComponentByType(GridFieldDetailForm::class)
71
                ->setItemRequestClass(OrderGridFieldDetailForm_ItemRequest::class); //see below
72
        }
73
74
        if ($this->modelClass == OrderStatusLog::class) {
75
            /** @var GridFieldConfig $config */
76
            $config = $form
0 ignored issues
show
Bug introduced by
Are you sure the usage of $form->Fields()->fieldBy...ame($this->modelClass)) targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
77
                ->Fields()
78
                ->fieldByName($this->sanitiseClassName($this->modelClass))
79
                ->getConfig();
80
81
            // Remove add new button
82
            $config->removeComponentsByType($config->getComponentByType(GridFieldAddNewButton::class));
83
        }
84
85
        return $form;
86
    }
87
}
88