CatalogCategory::getCMSFields()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 2
nop 0
dl 0
loc 22
rs 9.8333
c 0
b 0
f 0
ccs 14
cts 14
cp 1
crap 2
1
<?php
2
3
namespace Dynamic\ProductCatalog\Page;
4
5
use Dynamic\ProductCatalog\ORM\CatalogProduct;
6
use SilverStripe\Forms\GridField\GridField;
7
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
8
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
9
use SilverStripe\Forms\GridField\GridFieldPageCount;
10
use SilverStripe\Forms\GridField\GridFieldPaginator;
11
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;
12
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
13
14
class CatalogCategory extends \Page
15
{
16
    /**
17
     * @var array
18
     */
19
    private static $belongs_many_many = array(
0 ignored issues
show
introduced by
The private property $belongs_many_many is not used, and could be removed.
Loading history...
20
        'Products' => CatalogProduct::class,
21
    );
22
23
    /**
24
     * @var string
25
     */
26
    private static $table_name = 'CatalogCategory';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
27
28
    /**
29
     * @return \SilverStripe\Forms\FieldList
30
     */
31 1
    public function getCMSFields()
32
    {
33 1
        $fields = parent::getCMSFields();
34
35 1
        if ($this->ID) {
36
            // Products
37 1
            $config = GridFieldConfig_RelationEditor::create();
38 1
            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
39 1
            $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
40 1
            $config->addComponent(new GridFieldAddExistingSearchButton());
41 1
            $config->removeComponentsByType(GridFieldPaginator::class);
42 1
            $config->removeComponentsByType(GridFieldPageCount::class);
43
44 1
            $products = $this->Products()->sort('SortOrder');
0 ignored issues
show
Bug introduced by
The method Products() does not exist on Dynamic\ProductCatalog\Page\CatalogCategory. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

44
            $products = $this->/** @scrutinizer ignore-call */ Products()->sort('SortOrder');
Loading history...
45 1
            $productsField = GridField::create('Products', 'Products', $products, $config);
46
47 1
            $fields->addFieldsToTab('Root.Products', array(
48 1
                $productsField,
49
            ));
50
        }
51
52 1
        return $fields;
53
    }
54
55
    /**
56
     * @return DataList
0 ignored issues
show
Bug introduced by
The type Dynamic\ProductCatalog\Page\DataList 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...
57
     */
58 1
    public function getProductList()
59
    {
60 1
        return $this->Products()->sort('SortOrder');
61
    }
62
}
63