Completed
Pull Request — master (#309)
by Jason
05:20
created

OrderDetail   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
dl 0
loc 120
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 16 2
A canEdit() 0 3 1
A canView() 0 3 1
A canCreate() 0 3 1
A canDelete() 0 3 1
1
<?php
2
3
namespace Dynamic\FoxyStripe\Model;
4
5
use Dynamic\FoxyStripe\Page\ProductPage;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\GridField\GridField;
8
use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\Security\Permission;
11
12
class OrderDetail extends DataObject
13
{
14
    /**
15
     * @var string
16
     */
17
    private static $singular_name = 'Order Detail';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
18
19
    /**
20
     * @var string
21
     */
22
    private static $plural_name = 'Order Details';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @var string
26
     */
27
    private static $description = '';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
28
29
    /**
30
     * @var array
31
     */
32
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
33
        'Quantity' => 'Int',
34
        'Price' => 'Currency',
35
        'ProductName' => 'Varchar(255)',
36
        'ProductCode' => 'Varchar(100)',
37
        'ProductImage' => 'Text',
38
        'ProductCategory' => 'Varchar(100)',
39
    );
40
41
    /**
42
     * @var array
43
     */
44
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
45
        'Product' => ProductPage::class,
46
        'Order' => Order::class,
47
    );
48
49
    /**
50
     * @var array
51
     */
52
    private static $has_many = array(
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
53
        'OrderOptions' => OrderOption::class,
54
    );
55
56
    /**
57
     * @var array
58
     */
59
    private static $many_many = [
0 ignored issues
show
introduced by
The private property $many_many is not used, and could be removed.
Loading history...
60
        'OptionItems' => OptionItem::class,
61
    ];
62
63
    /**
64
     * @var array
65
     */
66
    private static $summary_fields = array(
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
67
        'Product.Title',
68
        'Quantity',
69
        'Price.Nice',
70
    );
71
72
    /**
73
     * @var string
74
     */
75
    private static $table_name = 'FS_OrderDetail';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
76
77
    /**
78
     * @return FieldList
79
     */
80 1
    public function getCMSFields()
81
    {
82 1
        $fields = parent::getCMSFields();
83
84 1
        if ($this->ID) {
85 1
            $fields->addFieldsToTab('Root.Options', array(
86 1
                GridField::create(
87 1
                    'Options',
0 ignored issues
show
Bug introduced by
'Options' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

87
                    /** @scrutinizer ignore-type */ 'Options',
Loading history...
88 1
                    'Product Options',
89 1
                    $this->OrderOptions(),
0 ignored issues
show
Bug introduced by
The method OrderOptions() does not exist on Dynamic\FoxyStripe\Model\OrderDetail. 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

89
                    $this->/** @scrutinizer ignore-call */ 
90
                           OrderOptions(),
Loading history...
90 1
                    GridFieldConfig_RecordViewer::create()
91
                ),
92
            ));
93
        }
94
95 1
        return $fields;
96
    }
97
98
    /**
99
     * @param bool $member
100
     *
101
     * @return bool|int
102
     */
103 49
    public function canView($member = false)
104
    {
105 49
        return Permission::check('Product_ORDERS', 'any', $member);
0 ignored issues
show
Bug introduced by
$member of type boolean is incompatible with the type SilverStripe\Security\Member|integer expected by parameter $member of SilverStripe\Security\Permission::check(). ( Ignorable by Annotation )

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

105
        return Permission::check('Product_ORDERS', 'any', /** @scrutinizer ignore-type */ $member);
Loading history...
106
    }
107
108
    /**
109
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
110
     *
111
     * @return bool
112
     */
113 1
    public function canEdit($member = null)
114
    {
115 1
        return false;
116
    }
117
118
    /**
119
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
120
     *
121
     * @return bool
122
     */
123 1
    public function canCreate($member = null, $context = [])
124
    {
125 1
        return false;
126
        //return Permission::check('Product_ORDERS');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
127
    }
128
129 1
    public function canDelete($member = null)
130
    {
131 1
        return Permission::check('Product_ORDERS', 'any', $member);
132
    }
133
}
134