ShippableProduct::fieldLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Dynamic\Foxy\Page;
4
5
use Dynamic\Foxy\Controller\ShippableProductController;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\NumericField;
8
use SilverStripe\Forms\RequiredFields;
9
10
class ShippableProduct extends Product
11
{
12
    /**
13
     * @var string
14
     */
15
    private static $table_name = 'ShippableProduct';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
16
17
    /**
18
     * @var array
19
     */
20
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
21
        'Weight' => 'Decimal(9,3)',
22
    ];
23
24
    /**
25
     * @var array
26
     */
27
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
28
        'Weight' => '1.0',
29
    ];
30
31
    /**
32
     * @param bool $includerelations
33
     * @return array
34
     */
35
    public function fieldLabels($includerelations = true)
36
    {
37
        $labels = parent::fieldLabels($includerelations);
38
39
        $labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Product Name');
40
        $labels['Weight'] = _t(__CLASS__ . '.WeightLabel', 'Weight');
41
        $labels['Image.CMSThumbnail'] = _t(__CLASS__ . '.ImageThumbnailLabel', 'Image');
42
        $labels['Price.Nice'] = _t(__CLASS__ . '.PriceLabel', 'Price');
43
44
        return $labels;
45
    }
46
47
    /**
48
     * @return FieldList
49
     */
50
    public function getCMSFields()
51
    {
52
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
53
            $fields->addFieldsToTab(
54
                'Root.Ecommerce',
55
                [
56
                    NumericField::create('Weight')
57
                        ->setTitle($this->owner->fieldLabel('Weight'))
0 ignored issues
show
Bug introduced by
The method fieldLabel() 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

57
                        ->setTitle($this->owner->/** @scrutinizer ignore-call */ fieldLabel('Weight'))

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\Page\ShippableProduct. Since you implemented __get, consider adding a @property annotation.
Loading history...
58
                        ->setDescription(_t(
59
                            __CLASS__ . '.WeightDescription',
60
                            'Base weight for this product in lbs. Can be modified using Product Options. Only supports up to 3 decimal places'
61
                        ))
62
                        ->setScale(3),
63
                ],
64
                'FoxyCategoryID'
65
            );
66
        });
67
68
        return parent::getCMSFields();
69
    }
70
71
    /**
72
     * @return RequiredFields
73
     */
74
    public function getCMSValidator()
75
    {
76
        $validator = parent::getCMSValidator();
77
78
        $validator->appendRequiredFields(
79
            new RequiredFields([
80
                'Weight',
81
            ])
82
        );
83
84
        return $validator;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getControllerName()
91
    {
92
        return ShippableProductController::class;
93
    }
94
}
95