Passed
Push — master ( 44cbe3...1a2823 )
by Jason
01:49
created

OptionType   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 30 2
1
<?php
2
3
namespace Dynamic\Foxy\Model;
4
5
use Dynamic\Products\Page\Product;
0 ignored issues
show
Bug introduced by
The type Dynamic\Products\Page\Product was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\GridField\GridField;
8
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
9
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
10
use SilverStripe\ORM\DataObject;
11
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
0 ignored issues
show
Bug introduced by
The type Symbiote\GridFieldExtens...AddExistingSearchButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
0 ignored issues
show
Bug introduced by
The type Symbiote\GridFieldExtens...\GridFieldOrderableRows was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
class OptionType extends DataObject
15
{
16
    /**
17
     * @var array
18
     */
19
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
20
        'Title' => 'Varchar(255)',
21
        'SortOrder' => 'Int',
22
    ];
23
24
    /**
25
     * @var array
26
     */
27
    private static $many_many = [
0 ignored issues
show
introduced by
The private property $many_many is not used, and could be removed.
Loading history...
28
        'Options' => ProductOption::class,
29
    ];
30
31
    /**
32
     * @var array
33
     */
34
    private static $many_many_extraFields = [
0 ignored issues
show
introduced by
The private property $many_many_extraFields is not used, and could be removed.
Loading history...
35
        'Options' => [
36
            'WeightModifier' => 'Decimal',
37
            'CodeModifier' => 'Text',
38
            'PriceModifier' => 'Currency',
39
            'WeightModifierAction' => "Enum('Add,Subtract,Set', null)",
40
            'CodeModifierAction' => "Enum('Add,Subtract,Set', null)",
41
            'PriceModifierAction' => "Enum('Add,Subtract,Set', null)",
42
            'Available' => 'Boolean',
43
            'SortOrder' => 'Int',
44
        ],
45
    ];
46
47
    /**
48
     * @var string
49
     */
50
    private static $table_name = 'OptionType';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
51
52
    public function getCMSFields()
53
    {
54
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
55
            $fields->removeByName([
56
                'SortOrder',
57
                'ProductID',
58
                'Options',
59
            ]);
60
61
            if ($this->ID) {
62
                $config = GridFieldConfig_RelationEditor::create();
63
                $config
64
                    ->addComponents([
65
                        new GridFieldAddExistingSearchButton(),
66
                        new GridFieldOrderableRows('SortOrder'),
67
                    ])
68
                    ->removeComponentsByType([
69
                        GridFieldAddExistingAutocompleter::class,
70
                    ]);
71
                $options = GridField::create(
72
                    'Options',
73
                    'Options',
74
                    $this->owner->Options()->sort('SortOrder'),
0 ignored issues
show
Bug introduced by
The method Options() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
                    $this->owner->/** @scrutinizer ignore-call */ 
75
                                  Options()->sort('SortOrder'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property owner does not exist on Dynamic\Foxy\Model\OptionType. Since you implemented __get, consider adding a @property annotation.
Loading history...
75
                    $config
76
                );
77
                $fields->addFieldToTab('Root.Main', $options);
78
            }
79
        });
80
81
        return parent::getCMSFields();
82
    }
83
}
84