GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 296583...4f1ba4 )
by
unknown
02:28
created

SecondHandArchive::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
4
class SecondHandArchive extends DataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
7
        'Title' => 'Varchar(255)',
8
        'Price' => 'Currency',
9
        'InternalItemID' => 'Varchar(50)',
10
        'PurchasePrice' => 'Currency',
11
        'ProductQuality' => 'ENUM("1, 2, 3, 4, 5, 6, 7, 8, 9, 10","10")',
12
        'IncludesBoxOrCase' => 'ENUM("No, Box, Case, Both","No")',
13
        'OriginalManual' => 'Boolean',
14
        'SerialNumber' => 'VarChar(50)',
15
        'PageID' => 'Int'
16
    );
17
18
    public static function create_from_page($page)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
19
    {
20
        if ($page->InternalItemID) {
21
            $filter = array(
22
                'InternalItemID' => $page->InternalItemID
23
            );
24
        } else {
25
            $filter = array(
26
                'PageID' => $page->ID
27
            );
28
        }
29
        $obj = SecondHandArchive::get()->filter($filter)->first();
30
        if (! $obj) {
31
            $obj = SecondHandArchive::create($filter);
32
        }
33
        $obj->Title = $page->Title;
34
        $obj->Price = $page->Price;
35
        $obj->InternalItemID = $page->InternalItemID;
36
        $obj->PageID = $page->ID;
37
        $obj->PurchasePrice = $page->PurchasePrice;
38
        $obj->ProductQuality = $page->ProductQuality;
39
        $obj->IncludesBoxOrCase = $page->IncludesBoxOrCase;
40
        $obj->OriginalManual = $page->OriginalManual;
41
        $obj->SerialNumber = $page->SerialNumber;
42
        $obj->write();
43
        return $obj;
44
    }
45
46
47
    /**
48
     * stadard SS method
49
     * @return Boolean
50
     */
51
    public function canCreate($member = null)
52
    {
53
        return false;
54
    }
55
56
57
    /**
58
     * stadard SS method
59
     * @return Boolean
60
     */
61
    public function canEdit($member = null)
62
    {
63
        return false;
64
    }
65
66
    /**
67
     * stadard SS method
68
     * @return Boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
69
     */
70
    public function canView($member = null)
71
    {
72
        return Permission::check(
73
            EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_permission_code')
74
        );
75
    }
76
77
    /**
78
     * stadard SS method
79
     * @return Boolean
80
     */
81
    public function canDelete($member = null)
82
    {
83
        return false;
84
    }
85
86
87
    private static $singular_name = 'Archived Second Hand Product';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
88
89
    public function i18n_singular_name()
90
    {
91
        return self::$singular_name;
92
    }
93
94
    private static $plural_name = 'Archived Second Hand Products';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
95
96
    public function i18n_plural_name()
97
    {
98
        return self::$plural_name;
99
    }
100
101
    private static $indexes = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $indexes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
102
        'PageID' => true,
103
        'InternalItemID' => true
104
    );
105
106
    private static $default_sort = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $default_sort is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
107
        'Title' => 'ASC'
108
    );
109
110
    private static $summary_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
111
        'Title' => 'Title',
112
        'Price' => 'Sale Price',
113
        'InternalItemID' => 'Code',
114
        'PurchasePrice' => 'Purchase Price',
115
        'ProductQuality' => 'Quality',
116
        'IncludesBoxOrCase' => 'Includes',
117
        'OriginalManual.Nice' => 'Has Manual',
118
        'SerialNumber' => 'Serial Number'
119
    );
120
121
    private static $field_labels = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $field_labels is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
122
        'Title' => 'Title',
123
        'Price' => 'Sale Price',
124
        'InternalItemID' => 'Code',
125
        'PurchasePrice' => 'Purchase Price',
126
        'ProductQuality' => 'Quality',
127
        'IncludesBoxOrCase' => 'Includes',
128
        'OriginalManual' => 'Has Manual',
129
        'SerialNumber' => 'Serial Number'
130
    );
131
132
    private static $searchable_fields = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $searchable_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
133
        'Title' => 'PartialMatchFilter',
134
        'Price' => 'ExactMatchFilter',
135
        'InternalItemID' => 'PartialMatchFilter',
136
        'PurchasePrice' => 'ExactMatchFilter',
137
        'ProductQuality' => 'ExactMatchFilter',
138
        'IncludesBoxOrCase' => 'ExactMatchFilter',
139
        'OriginalManual' => 'ExactMatchFilter',
140
        'SerialNumber' => 'PartialMatchFilter'
141
    );
142
143
    /**
144
     * stadard SS method
145
     * @return FieldList
146
     */
147
    public function getCMSFields()
148
    {
149
        $fields = parent::getCMSFields();
150
        $fields->addFieldsToTab(
151
            'Root.Main',
152
            array(
153
                EcommerceCMSButtonField::create(
154
                    'RestoreButton',
155
                    '/admin/secondhandproducts/SecondHandProduct/restore/?productid=' . $this->PageID,
0 ignored issues
show
Documentation introduced by
The property PageID does not exist on object<SecondHandArchive>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
156
                    _t('SecondHandArchive.RESTORE_BUTTON', 'Restore Product')
157
                )
158
            )
159
        );
160
        return $fields;
161
    }
162
}
163