Completed
Pull Request — master (#287)
by Nic
07:49
created

OrderDetail::getCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
class OrderDetail extends DataObject
4
{
5
    /**
6
     * @var string
7
     */
8
    private static $singular_name = 'Order Detail';
9
10
    /**
11
     * @var string
12
     */
13
    private static $plural_name = 'Order Details';
14
15
    /**
16
     * @var string
17
     */
18
    private static $description = '';
19
20
    /**
21
     * @var array
22
     */
23
    private static $db = array(
24
        'Quantity' => 'Int',
25
        'Price' => 'Currency'
26
    );
27
28
	private static $has_one = array(
29
        'Product' => 'FoxyStripeProduct',
30
        'Order' => 'Order'
31
    );
32
33
    /**
34
     * @var array
35
     */
36
    private static $many_many = array(
37
        'Options' => 'OptionItem'
38
    );
39
40
    /**
41
     * @var array
42
     */
43
    private static $summary_fields = array(
44
        'Product.Title',
45
        'Quantity',
46
        'Price.Nice'
47
    );
48
49
    /**
50
     * @return FieldList
51
     */
52 1
    public function getCMSFields()
53
    {
54 1
        $fields = parent::getCMSFields();
55
56 1
        if ($this->ID) {
57 1
            $fields->addFieldsToTab('Root.Options', array(
58 1
                GridField::create('Options', 'Product Options', $this->Options(), GridFieldConfig_RecordViewer::create())
0 ignored issues
show
Documentation Bug introduced by
The method Options does not exist on object<OrderDetail>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59 1
            ));
60 1
        }
61
62 1
        return $fields;
63
    }
64
65
    /**
66
     * @param bool $member
67
     * @return bool|int
68
     */
69 1
    public function canView($member = false)
70
    {
71 1
        return Permission::check('Product_ORDERS');
72
    }
73
74
    /**
75
     * @param null $member
76
     * @return bool
77
     */
78 1
    public function canEdit($member = null)
79
    {
80 1
        return false;
81
    }
82
83
    /**
84
     * @param null $member
85
     * @return bool|int
86
     */
87 1
    public function canDelete($member = null)
88
    {
89 1
        return false;
90
    }
91
92
    /**
93
     * @param null $member
94
     * @return bool
95
     */
96 1
    public function canCreate($member = null)
97
    {
98 1
        return false;
99
    }
100
}
101