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 ( 633e45...f25ab9 )
by
unknown
01:30
created

SecondHandArchive::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 25
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
        'InternalItemID' => 'Varchar(50)',
9
        'SerialNumber' => 'VarChar(50)',
10
        'DateItemWasBought' => 'Date',
11
        'DateItemWasSold' => 'Date',
12
        'ProductQuality' => 'ENUM("1, 2, 3, 4, 5, 6, 7, 8, 9, 10","10")',
13
        'SoldOnBehalf' => 'Boolean',
14
        'PurchasePrice' => 'Currency',
15
        'Price' => 'Currency',
16
        'SoldPrice' => 'Currency',
17
        'IncludesBoxOrCase' => 'ENUM("No, Box, Case, Both","No")',
18
        'OriginalManual' => 'Boolean',
19
        'PageID' => 'Int',
20
        'Description' => 'VarChar(255)',
21
        'SellersName' =>  'VarChar(50)',
22
        'SellersPhone' =>  'VarChar(30)',
23
        'SellersEmail' =>  'VarChar(255)',
24
        'SellersAddress' =>  'VarChar(255)',
25
        'SellersAddress2' => 'Varchar(255)',
26
        'SellersCity' => 'Varchar(100)',
27
        'SellersPostalCode' => 'Varchar(50)',
28
        'SellersRegionCode' => 'Varchar(100)',
29
        'SellersCountry' => 'Varchar(50)',
30
        'SellersIDType' => 'ENUM(",Drivers Licence, Firearms Licence, Passport","")',
31
        'SellersIDNumber' => 'Varchar(50)',
32
        'SellersDateOfBirth' => 'Date',
33
        'SellersIDExpiryDate' => 'Date',
34
        'SellersIDPhotocopy' => 'Boolean'
35
    );
36
37
    public static function create_from_page($page)
38
    {
39
        if ($page->InternalItemID) {
40
            $filter = array(
41
                'InternalItemID' => $page->InternalItemID
42
            );
43
        } else {
44
            $filter = array(
45
                'PageID' => $page->ID
46
            );
47
        }
48
        $obj = SecondHandArchive::get()->filter($filter)->first();
49
        if (! $obj) {
50
            $obj = SecondHandArchive::create($filter);
51
        }
52
        $obj->Title = $page->Title;
53
        $obj->Price = $page->Price;
54
        $obj->InternalItemID = $page->InternalItemID;
55
        $obj->SerialNumber = $page->SerialNumber;
56
        $obj->DateItemWasBought = $page->DateItemWasBought;
57
        $obj->DateItemWasSold = $page->DateItemWasSold;
58
        $obj->ProductQuality = $page->ProductQuality;
59
        $obj->SoldOnBehalf = $page->SellingOnBehalf;
60
        $obj->PurchasePrice = $page->PurchasePrice;
61
        $obj->SoldPrice = $page->SoldPrice;
62
        $obj->IncludesBoxOrCase = $page->IncludesBoxOrCase;
63
        $obj->OriginalManual = $page->OriginalManual;
0 ignored issues
show
Bug introduced by
The property OriginalManual does not seem to exist. Did you mean original?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64
        $obj->PageID = $page->ID;
65
        $obj->Description = $page->ShortDescription;
66
67
        //sellers details
68
        $obj->SellersName = $page->SellersName;
69
        $obj->SellersPhone = $page->SellersPhone;
70
        $obj->SellersEmail = $page->SellersEmail;
71
        $obj->SellersAddress = $page->SellersAddress;
72
        $obj->SellersAddress2 = $page->SellersAddress2;
73
        $obj->SellersCity = $page->SellersCity;
74
        $obj->SellersPostalCode = $page->SellersPostalCode;
75
        $obj->SellersRegionCode = $page->SellersRegionCode;
76
        $obj->SellersCountry = $page->SellersCountry;
77
        $obj->SellersIDType = $page->SellersIDType;
78
        $obj->SellersIDNumber = $page->SellersIDNumber;
79
        $obj->SellersDateOfBirth = $page->SellersDateOfBirth;
80
        $obj->SellersIDExpiryDate = $page->SellersIDExpiryDate;
81
        $obj->SellersIDPhotocopy = $page->SellersIDPhotocopy;
82
83
        $obj->write();
84
        return $obj;
85
    }
86
87
88
    /**
89
     * stadard SS method
90
     * @return Boolean
91
     */
92
    public function canCreate($member = null)
93
    {
94
        return false;
95
    }
96
97
98
    /**
99
     * stadard SS method
100
     * @return Boolean
101
     */
102
    public function canEdit($member = null)
103
    {
104
        return false;
105
    }
106
107
    /**
108
     * stadard SS method
109
     * @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...
110
     */
111
    public function canView($member = null)
112
    {
113
        return Permission::check(
114
            EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_permission_code')
115
        );
116
    }
117
118
    /**
119
     * stadard SS method
120
     * @return Boolean
121
     */
122
    public function canDelete($member = null)
123
    {
124
        return false;
125
    }
126
127
128
    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...
129
130
    public function i18n_singular_name()
131
    {
132
        return self::$singular_name;
133
    }
134
135
    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...
136
137
    public function i18n_plural_name()
138
    {
139
        return self::$plural_name;
140
    }
141
142
    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...
143
        'PageID' => true,
144
        'InternalItemID' => true
145
    );
146
147
    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...
148
        'LastEdited' => 'DESC'
149
    );
150
151
    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...
152
        'Title' => 'Title',
153
        'InternalItemID' => 'Code',
154
        'SerialNumber' => 'Serial',
155
        'DateItemWasBought' => 'Date Entered',
156
        'DateItemWasSold' => 'Date Sold',
157
        'ProductQuality' => 'Quality',
158
        'SoldOnBehalf.Nice' => 'On Behalf',
159
        'PurchasePrice' => 'Purchase Price',
160
        'Price' => 'Sale/Ticket Price',
161
        'SoldPrice' => 'Sold Price',
162
    );
163
164
    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...
165
        'Title' => 'Title',
166
        'Price' => 'Sale Price',
167
        'InternalItemID' => 'Code',
168
        'PurchasePrice' => 'Purchase Price',
169
        'ProductQuality' => 'Quality',
170
        'IncludesBoxOrCase' => 'Includes',
171
        'OriginalManual' => 'Has Manual',
172
        'SerialNumber' => 'Serial Number'
173
    );
174
175
    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...
176
        'Title' => 'PartialMatchFilter',
177
        'Price' => 'ExactMatchFilter',
178
        'InternalItemID' => 'PartialMatchFilter',
179
        'PurchasePrice' => 'ExactMatchFilter',
180
        'ProductQuality' => 'ExactMatchFilter',
181
        'IncludesBoxOrCase' => 'ExactMatchFilter',
182
        'OriginalManual' => 'ExactMatchFilter',
183
        'SerialNumber' => 'PartialMatchFilter'
184
    );
185
186
    /**
187
     * stadard SS method
188
     * @return FieldList
189
     */
190
    public function getCMSFields()
191
    {
192
        $fields = parent::getCMSFields();
193
        $fields->addFieldsToTab(
194
            'Root.Main',
195
            [
196
                EcommerceCMSButtonField::create(
197
                    'RestoreButton',
198
                    '/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...
199
                    _t('SecondHandArchive.RESTORE_BUTTON', 'Restore Product')
200
                )
201
            ]
202
        );
203
        $fields->addFieldsToTab(
204
            'Root.SellersDetails',
205
            [
206
                $fields->dataFieldByName("SellersName"),
207
                $fields->dataFieldByName("SellersPhone"),
208
                $fields->dataFieldByName("SellersEmail"),
209
                $fields->dataFieldByName("SellersAddress"),
210
                $fields->dataFieldByName("SellersAddress2"),
211
                $fields->dataFieldByName("SellersCity"),
212
                $fields->dataFieldByName("SellersPostalCode"),
213
                $fields->dataFieldByName("SellersRegionCode"),
214
                $fields->dataFieldByName("SellersCountry"),
215
                $fields->dataFieldByName("SellersIDType"),
216
                $fields->dataFieldByName("SellersIDNumber"),
217
                $fields->dataFieldByName("SellersDateOfBirth"),
218
                $fields->dataFieldByName("SellersIDExpiryDate"),
219
                $fields->dataFieldByName("SellersIDPhotocopy")
220
            ]
221
        );
222
        return $fields;
223
    }
224
}
225