Passed
Push — enhancement/more-config-option... ( e4871a...997483 )
by Matthew
03:47 queued 42s
created

LocationAdmin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 37
c 0
b 0
f 0
dl 0
loc 81
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getExportFields() 0 30 3
A getEditForm() 0 10 2
1
<?php
2
3
namespace Dynamic\Locator;
4
5
use SilverStripe\Admin\ModelAdmin;
6
use SilverStripe\Dev\CsvBulkLoader;
7
use SilverStripe\Forms\Form;
8
9
/**
10
 * Class LocationAdmin
11
 */
12
class LocationAdmin extends ModelAdmin
13
{
14
15
    /**
16
     * @var array
17
     */
18
    private static $managed_models = array(
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
19
        Location::class,
20
        LocationCategory::class,
21
    );
22
23
    /**
24
     * @var array
25
     */
26
    private static $model_importers = array(
0 ignored issues
show
introduced by
The private property $model_importers is not used, and could be removed.
Loading history...
27
        Location::class => LocationCsvBulkLoader::class,
28
        LocationCategory::class => CsvBulkLoader::class,
29
    );
30
31
    /**
32
     * @var string
33
     */
34
    private static $menu_title = 'Locator';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
35
    /**
36
     * @var string
37
     */
38
    private static $url_segment = 'locator';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
39
40
    /**
41
     * @return array
42
     */
43
    public function getExportFields()
44
    {
45
        if ($this->modelClass == Location::class) {
46
            $fields = [
47
                'Title' => 'Name',
48
                'Address' => 'Address',
49
                'Address2' => 'Address2',
50
                'City' => 'City',
51
                'State' => 'State',
52
                'PostalCode' => 'PostalCode',
53
                'CountryCode' => 'Country',
54
                'Phone' => 'Phone',
55
                'Fax' => 'Fax',
56
                'Email' => 'Email',
57
                'Website' => 'Website',
58
                'Featured' => 'Featured',
59
                'CategoryList' => 'Categories',
60
                'Lat' => 'Lat',
61
                'Lng' => 'Lng',
62
                'Import_ID' => 'Import_ID',
63
            ];
64
        }
65
66
        if (!isset($fields)) {
67
            $fields = parent::getExportFields();
68
        }
69
70
        $this->extend('updateGetExportFields', $fields);
71
72
        return $fields;
73
    }
74
75
    /**
76
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
77
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
78
     * @return $this|Form
79
     */
80
    public function getEditForm($id = null, $fields = null)
81
    {
82
        $form = parent::getEditForm($id, $fields);
83
        $class = $this->sanitiseClassName($this->modelClass);
84
        if ($class == Location::class) {
85
            $gridField = $form->Fields()->fieldByName($class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $gridField is correct as $form->Fields()->fieldByName($class) 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 assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
86
            $config = $gridField->getConfig();
87
            $config->removeComponentsByType('GridFieldDeleteAction');
88
        }
89
        return $form;
90
    }
91
}
92