Passed
Pull Request — master (#9)
by Jason
01:52
created

DiscountTier::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 10
1
<?php
2
3
namespace Dynamic\Foxy\Discounts\Model;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\ORM\DataObject;
7
8
class DiscountTier extends DataObject
9
{
10
    /**
11
     * @var array
12
     */
13
    private static $db = [
1 ignored issue
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
14
        'Quantity' => 'Int',
15
        'Percentage' => 'Int',
16
    ];
17
18
    /**
19
     * @var array
20
     */
21
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
22
        'Discount' => Discount::class,
23
    ];
24
25
    /**
26
     * @var array
27
     */
28
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
29
        'Quantity' => 1,
30
    ];
31
32
    /**
33
     * @var array
34
     */
35
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
36
        'DiscountPercentage' => [
37
            'title' => 'Discount',
38
        ],
39
        'Quantity',
40
    ];
41
42
    /**
43
     * @var string
44
     */
45
    private static $table_name = 'FoxyDiscountTier';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
46
47
    /**
48
     * @var array
49
     */
50
    private static $default_sort = array(
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
51
        'Quantity'
52
    );
53
54
    /**
55
     * @return FieldList|void
56
     */
57
    public function getCMSFields()
58
    {
59
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
60
            $fields->removeByName([
61
                'DiscountID',
62
            ]);
63
64
            $quantity = $fields->dataFieldByName('Quantity');
65
            $quantity->setTitle('Quantity to trigger discount');
66
67
            $percentage = $fields->dataFieldByName('Percentage');
68
            $percentage->setTitle('Percent discount');
69
        });
70
71
        return parent::getCMSFields();
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getDiscountPercentage()
78
    {
79
        return "{$this->Percentage}%";
0 ignored issues
show
Bug Best Practice introduced by
The property Percentage does not exist on Dynamic\Foxy\Discounts\Model\DiscountTier. Since you implemented __get, consider adding a @property annotation.
Loading history...
80
    }
81
}
82