OrderStatusLog_SecurityCheck   F
last analyzed

Complexity

Total Complexity 115

Size/Duplication

Total Lines 669
Duplicated Lines 11.51 %

Coupling/Cohesion

Components 1
Dependencies 17

Importance

Changes 0
Metric Value
wmc 115
lcom 1
cbo 17
dl 77
loc 669
rs 1.931
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A i18n_singular_name() 0 4 1
A i18n_plural_name() 0 4 1
A canCreate() 0 4 1
A canEdit() 0 14 5
F getCMSFields() 0 201 22
F collateRisks() 77 226 50
A getSecurityCleared() 0 4 2
B pass() 0 22 7
B onAfterWrite() 0 38 11
A checkSecurityObject() 0 7 2
A memberIsWhitelisted() 0 9 3
A orderMember() 0 10 5
A blacklistCheck() 0 17 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like OrderStatusLog_SecurityCheck often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use OrderStatusLog_SecurityCheck, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
4
/**
5
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
6
 * @package: ecommerce
7
 * @sub-package: model
8
 * @inspiration: Silverstripe Ltd, Jeremy
9
 **/
10
class OrderStatusLog_SecurityCheck extends OrderStatusLog
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...
11
{
12
    private static $days_ago_to_check = 14;
0 ignored issues
show
Unused Code introduced by
The property $days_ago_to_check 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...
13
14
    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...
15
        'Bad' => 'Boolean',
16
        'Risks' => 'HTMLText',
17
        'SubTotal' => 'Currency',
18
        'Check1' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
19
        'Check2' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
20
        'Check3' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
21
        'Check4' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
22
        'Check5' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
23
        'Check6' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
24
        'Check7' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
25
        'Check8' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
26
        'Check9' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
27
        'Check10' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
28
        'Check11' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
29
        'Check12' => 'Enum("To do, Done, Whitelisted Customer", "To do" )',
30
    );
31
32
    private static $many_many = 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 $many_many 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...
33
        'BlacklistItems' => 'EcommerceSecurityBaseClass'
34
    );
35
36
    /**
37
     *  this array works as follows
38
     *      array(
39
     *          Check1 => array(
40
     *              "Title" => "Customer Has Paid",
41
     *              "MinSubTotal" => 10,
42
     *              "Explanation" => "Check Payment system for $$$ coming in"
43
     *          ),
44
     *          Check2 => array(
45
     *              "Title" => "Address Exists",
46
     *              "MinSubTotal" => 50,
47
     *              "Explanation" => "Check Payment system for $$$ coming in"
48
     *          )
49
     *
50
     * @var array
51
     */
52
    private static $checks_required = array();
0 ignored issues
show
Unused Code introduced by
The property $checks_required 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...
53
54
    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...
55
        'Type' => 'Type',
56
        'SubTotal' => 'SubTotal',
57
        'SecurityCleared' => 'Security Cleared'
58
    );
59
60
    private static $casting = 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 $casting 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...
61
        'SecurityCleared' => 'Boolean'
62
    );
63
64
    private static $defaults = 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 $defaults 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...
65
        'InternalUseOnly' => true
66
    );
67
68
    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...
69
        'Bad' => 'Fraudulent',
70
        'Title' => 'Value'
71
    );
72
73
    private static $singular_name = 'Security Check';
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...
74
    public function i18n_singular_name()
75
    {
76
        return self::$singular_name;
77
    }
78
79
    private static $plural_name = 'Security Checks';
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...
80
    public function i18n_plural_name()
81
    {
82
        return self::$plural_name;
83
    }
84
85
    public function canCreate($member = null)
86
    {
87
        return false;
88
    }
89
90
    public function canEdit($member = null)
91
    {
92
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_SecurityCheck>? 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...
93
        if ($order && $order->exists()) {
94
            $status = $order->MyStep();
95
            if ($status && $status->Code == 'SECURITY_CHECK') {
96
                return parent::canEdit($member);
97
            } else {
98
                return false;
99
            }
100
        } else {
101
            return parent::canEdit($member);
102
        }
103
    }
104
105
    /**
106
     * CMS Fields
107
     * @return FieldList
108
     */
109
    public function getCMSFields()
110
    {
111
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_SecurityCheck>? 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...
112
        if ($order) {
113
            $member = $this->orderMember();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $member is correct as $this->orderMember() (which targets OrderStatusLog_SecurityCheck::orderMember()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
114
            $fields = parent::getCMSFields();
115
            $securityIP = "";
116
            foreach ($this->BlacklistItems() as $item) {
0 ignored issues
show
Documentation Bug introduced by
The method BlacklistItems does not exist on object<OrderStatusLog_SecurityCheck>? 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...
117
                if (is_a($item, 'EcommerceSecurityIP')) {
118
                    $securityIP = $item->Title;
119
                    break;
120
                }
121
            }
122
            if ($securityIP) {
123
                $country = '';
124
                if (class_exists('GeoIP')) {
125
                    $country = GeoIP::ip2country($securityIP)['name'];
126
                }
127
                $fields->addFieldToTab(
128
                    'Root.Main',
129
                    HeaderField::create(
130
                        'BadHeading',
131
                        'IP Address Info: '
132
                    ),
133
                    'Bad'
134
                );
135
                if ($country) {
136
                    $country = '<em>Country:</em> '. $country . '</br>';
137
                }
138
                $fields->addFieldToTab(
139
                    'Root.Main',
140
                    LiteralField::create(
141
                        'IPAddressLink',
142
                        $country . '<em>Detailed Info: </em><a href="https://freegeoip.net/?q='.$securityIP.'" target="_blank">https://freegeoip.net/?q='.$securityIP.'</a>'
143
                    ),
144
                    'Bad'
145
                );
146
            }
147
148
            $fields->addFieldToTab(
149
                'Root.Main',
150
                HeaderField::create(
151
                    'BadHeading',
152
                    'Mark as Fraud'
153
                ),
154
                'Bad'
155
            );
156
157
158
            $fields->addFieldToTab(
159
                'Root.MoreDetails',
160
                HTMLEditorField::create(
161
                    'Note',
162
                    'Notes'
163
                )
164
            );
165
            $fields->addFieldToTab(
166
                'Root.Main',
167
                HeaderField::create(
168
                    'BadHeading',
169
                    'Risks'
170
                ),
171
                'Risks'
172
            );
173
            $riskField = $fields->dataFieldByName('Risks');
174
            $riskField->setTitle('');
175
176
            if ($member) {
177
                $previousOrders = Order::get()
178
                    ->filter(
179
                        array(
180
                            'MemberID' => $member->ID
181
                        )
182
                    )
183
                    ->exclude(
184
                        array('ID' => $order->ID)
185
                    );
186
                if ($previousOrders->count()) {
187
                    $fields->addFieldToTab(
188
                        "Root.PreviousOrders",
189
                        new GridField(
190
                            'PreviousOrdersList',
191
                            'Previous Orders',
192
                            $previousOrders
193
                        )
194
                    );
195
                } else {
196
                    $fields->addFieldToTab(
197
                        "Root.PreviousOrders",
198
                        HeaderField::create(
199
                            'NoPreviousOrders',
200
                            'This customer does not have any previous orders'
201
                        )
202
                    );
203
                }
204
            }
205
        }
206
        $allFields = array();
207
        for ($i = 1; $i < 13; $i++) {
208
            $allFields["Check".$i] = "Check".$i;
209
        }
210
        $checks = $this->Config()->get('checks_required');
211
        $fields->addFieldToTab(
0 ignored issues
show
Bug introduced by
The variable $fields does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
212
            "Root.Required",
213
            HeaderField::create('RequiredChecksHeader', 'Required Checks'),
214
            'Note'
215
        );
216
        $fields->addFieldToTab(
217
            "Root.NotRequired",
218
            HeaderField::create('UnrequiredChecksHeader', 'Optional Checks'),
219
            'Note'
220
        );
221
        $hasRequiredChecks = false;
222
        $hasUnrequiredChecks = false;
223
        $memberIsWhitelisted = $this->memberIsWhitelisted();
224
        foreach ($checks as $fieldName => $details) {
225
            unset($allFields[$fieldName]);
226
            if (floatval($this->SubTotal) > floatval($details['SubTotalMin'])) {
0 ignored issues
show
Documentation introduced by
The property SubTotal does not exist on object<OrderStatusLog_SecurityCheck>. 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...
227
                $hasRequiredChecks = true;
228
                $fields->addFieldToTab(
229
                    'Root.Required',
230
                    $myField = $fields->dataFieldByName($fieldName)
231
                );
232
            } else {
233
                $hasUnrequiredChecks = true;
234
                $fields->addFieldToTab(
235
                    'Root.NotRequired',
236
                    $myField = $fields->dataFieldByName($fieldName)
237
                );
238
            }
239
            $originalOptions = $myField->getSource();
240
            if ($memberIsWhitelisted) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
241
                //..
242
            } else {
243
                unset($originalOptions['Whitelisted Customer']);
244
            }
245
            if (! $this->$fieldName) {
246
                $this->$fieldName = 'To do';
247
            }
248
            $fields->replaceField(
249
                $myField->ID(),
0 ignored issues
show
Bug introduced by
It seems like $myField->ID() targeting FormField::ID() can also be of type array; however, FieldList::replaceField() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
250
                OptionsetField::create(
251
                    $myField->ID(),
252
                    $details['Title'],
253
                    $originalOptions
254
                )
255
            );
256
            if (! empty($details['Description'])) {
257
                $myField->setRighTitle($details['Description']);
0 ignored issues
show
Bug introduced by
The method setRighTitle() does not exist on FormField. Did you maybe mean setRightTitle()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
258
            }
259
        }
260
        foreach ($allFields as $fieldToRemove) {
261
            $fields->removeByName($fieldToRemove);
262
        }
263
        if (! $hasUnrequiredChecks) {
264
            $fields->addFieldToTab(
265
                "Root.NotRequired",
266
                HeaderField::create('UnrequiredChecksHeader', 'There are no optional checks for this order.'),
267
                'Note'
268
            );
269
        }
270
        if (! $hasRequiredChecks) {
271
            $fields->addFieldToTab(
272
                "Root.Required",
273
                HeaderField::create('RequiredChecksHeader', 'There are no required checks for this order.'),
274
                'Note'
275
            );
276
        }
277
        if ($order) {
278
            $implementers = ClassInfo::implementorsOf('EcommerceSecurityLogInterface');
279
            if ($implementers) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $implementers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
280
                foreach ($implementers as $implementer) {
281
                    $class = Injector::inst()->get($implementer);
282
                    $fields->addFieldsToTab(
283
                        "Root.Main",
284
                        [
285
                            $class->getSecurityHeader(),
286
                            $class->getSecuritySummary($order),
287
                        ]
288
                    );
289
290
                    if ($class->getSecurityLogTable($order)) {
291
                        $fields->addFieldsToTab(
292
                            "Root.".$class->getSecurityLogTableTabName(),
293
                            [
294
                                $class->getSecurityHeader(),
295
                                $class->getSecurityLogTable($order)
296
                            ]
297
                        );
298
                    }
299
                }
300
            }
301
        }
302
303
        $fields->removeFieldFromTab('Root.Main', 'AuthorID');
304
        $fields->removeFieldFromTab('Root.Main', 'Title');
305
        $fields->removeFieldFromTab('Root.Main', 'InternalUseOnly');
306
        $fields->makeFieldReadonly('Risks');
307
        $fields->makeFieldReadonly('SubTotal');
308
        return $fields;
309
    }
310
311
    protected $warningMessages = array();
312
313
    protected function collateRisks()
314
    {
315
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_SecurityCheck>? 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...
316
        $billingAddress = $order->BillingAddress();
317
        $shippingAddress = $order->ShippingAddress();
318
        $member = $this->orderMember();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $member is correct as $this->orderMember() (which targets OrderStatusLog_SecurityCheck::orderMember()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
319
        $payments = $order->Payments();
320
        $html = '';
321
322
        $similarArray = array();
323
324
        $daysAgo = $this->Config()->get('days_ago_to_check');
325
        $timeFilter = array('Created:GreaterThan' => date('Y-m-d', strtotime('-'.$daysAgo.' days')).' 00:00:00');
326
327
328
        //check emails from user
329
        $emailArray = array();
330
        if ($member) {
331
            if ($member->Email) {
332
                $emailArray[] = $member->Email;
333
                if (OrderStatusLog_WhitelistCustomer::member_is_security_risk($member)) {
334
                    $html .= '<p class="message bad">This customer has been marked as a security risk.</p>';
335
                } else {
336
                    if (OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member)) {
337
                        $html .= '<p class="warning good">This customer is whitelisted.</p>';
338
                    } else {
339
                        $html .= '<p class="message warning">This customer is NOT whitelisted.</p>';
340
                    }
341
                }
342
            }
343
        }
344
        //are there any orders with the same Member.email in the last seven days...
345
        $otherOrders = Order::get_datalist_of_orders_with_submit_record()
346
            ->filter(
347
                array_merge(
348
                    array('MemberID' => $member->ID),
349
                    $timeFilter
350
                )
351
            )
352
            ->exclude(array('ID' => $order->ID));
353 View Code Duplication
        foreach ($otherOrders as $otherOrder) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
354
            if (!isset($similarArray[$otherOrder->ID])) {
355
                $similarArray[$otherOrder->ID] = array();
356
            }
357
            $similarArray[$otherOrder->ID]["Email"] = $otherOrder;
358
        }
359
        //check emails from billing address
360
        $emailArray = array();
361
        if ($billingAddress) {
362
            if ($billingAddress->Email) {
363
                $emailArray[] = $billingAddress->Email;
364
            }
365
        }
366
        //are there any orders with the same Billing.Email in the last seven days...
367
        $otherBillingAddresses = BillingAddress::get()->filter(
368
            array('Email' => $emailArray) + $timeFilter
369
        )->exclude(array('OrderID' => $order->ID));
370 View Code Duplication
        foreach ($otherBillingAddresses as $address) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
371
            $otherOrder = $address->Order();
372
            if (!isset($similarArray[$otherOrder->ID])) {
373
                $similarArray[$otherOrder->ID] = array();
374
            }
375
            $similarArray[$otherOrder->ID]["Email"] = $otherOrder;
376
        }
377
        //adding all emails to security checks
378
        $this->blacklistCheck($emailArray, 'EcommerceSecurityEmail');
379
380
381
        //phones
382
        $phoneArray = array();
383
        if ($billingAddress) {
384
            if ($billingAddress->Phone) {
385
                $phoneArray[] = $billingAddress->Phone;
386
            }
387
        }
388
        if ($shippingAddress) {
389
            if ($shippingAddress->ShippingPhone) {
390
                $phoneArray[] = $shippingAddress->ShippingPhone;
391
            }
392
        }
393
        //are there any orders with the same phone in the last xxx days...
394
        $otherBillingAddresses = BillingAddress::get()->filter(
395
            array('Phone' => $phoneArray) + $timeFilter
396
        )->exclude(array('OrderID' => $order->ID));
397 View Code Duplication
        foreach ($otherBillingAddresses as $address) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
            $otherOrder = $address->Order();
399
            if ($otherOrder && $otherOrder->ID != $order->ID) {
400
                if (!isset($similarArray[$otherOrder->ID])) {
401
                    $similarArray[$otherOrder->ID] = array();
402
                }
403
                $similarArray[$otherOrder->ID]["Phone"] = $otherOrder;
404
            }
405
        }
406
        $otherShippingAddresses = ShippingAddress::get()->filter(
407
            array('ShippingPhone' => $phoneArray) + $timeFilter
408
        )->exclude(array('OrderID' => $order->ID));
409 View Code Duplication
        foreach ($otherShippingAddresses as $address) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
410
            $otherOrder = $address->Order();
411
            if ($otherOrder && $otherOrder->ID != $order->ID) {
412
                if (!isset($similarArray[$otherOrder->ID])) {
413
                    $similarArray[$otherOrder->ID] = array();
414
                }
415
                $similarArray[$otherOrder->ID]["Phone"] = $otherOrder;
416
            }
417
        }
418
        //adding all emails to security checks
419
        $this->blacklistCheck($phoneArray, 'EcommerceSecurityPhone');
420
421
        //addresses
422
        $addressArray = array();
423
        if ($billingAddress) {
424
            if ($billingAddress->Address) {
425
                $addressArray[] = $billingAddress->Address;
426
            }
427
        }
428
        if ($shippingAddress) {
429
            if ($shippingAddress->ShippingAddress) {
430
                $addressArray[] = $shippingAddress->ShippingAddress;
431
            }
432
        }
433
        //are there any orders with the same address in the last xxx days...
434
        $otherBillingAddresses = BillingAddress::get()->filter(
435
            array('Address' => $addressArray) + $timeFilter
436
        )->exclude(array('OrderID' => $order->ID));
437 View Code Duplication
        foreach ($otherBillingAddresses as $address) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
438
            $otherOrder = $address->Order();
439
            if ($otherOrder && $otherOrder->ID != $order->ID) {
440
                if (!isset($similarArray[$otherOrder->ID])) {
441
                    $similarArray[$otherOrder->ID] = array();
442
                }
443
                $similarArray[$otherOrder->ID]["Address"] = $otherOrder;
444
            }
445
        }
446
        $otherShippingAddresses = ShippingAddress::get()
447
            ->filter(
448
                array('ShippingAddress' => $addressArray) + $timeFilter
449
            )
450
            ->exclude(array('OrderID' => $order->ID));
451 View Code Duplication
        foreach ($otherShippingAddresses as $address) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
452
            $otherOrder = $address->Order();
453
            if ($otherOrder && $otherOrder->ID != $order->ID) {
454
                if (!isset($similarArray[$otherOrder->ID])) {
455
                    $similarArray[$otherOrder->ID] = array();
456
                }
457
                $similarArray[$otherOrder->ID]["Address"] = $otherOrder;
458
            }
459
        }
460
        $this->blacklistCheck($addressArray, 'EcommerceSecurityAddress');
461
462
463
        //IP
464
        $ipArray = array();
465
        $ipProxyArray = array();
466
        if ($payments) {
467
            foreach ($payments as $payment) {
468
                if (strlen($payment->IP) > 10) {
469
                    $ipArray[] = $payment->IP;
470
                }
471
                if (strlen($payment->ProxyIP) > 10) {
472
                    $ipProxyArray[] = $payment->ProxyIP;
473
                }
474
            }
475
        }
476 View Code Duplication
        if (count($ipArray)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
477
            //are there any orders with the same IP in the xxx seven days...
478
            $otherPayments = EcommercePayment::get()->filter(
479
                array('IP' => $ipArray) + $timeFilter
480
            )->exclude(array('OrderID' => $order->ID));
481
            foreach ($otherPayments as $payment) {
482
                $otherOrder = $payment->Order();
483
                if (!isset($similarArray[$otherOrder->ID])) {
484
                    $similarArray[$otherOrder->ID] = array();
485
                }
486
                $similarArray[$otherOrder->ID]["IP"] = $otherOrder;
487
            }
488
            $this->blacklistCheck($ipArray, 'EcommerceSecurityIP');
489
        }
490 View Code Duplication
        if (count($ipProxyArray)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
491
            //are there any orders with the same Proxy in the xxx seven days...
492
            $otherPayments = EcommercePayment::get()->filter(
493
                array('ProxyIP' => $ipProxyArray) + $timeFilter
494
            )->exclude(array('OrderID' => $order->ID));
495
            foreach ($otherPayments as $payment) {
496
                $otherOrder = $payment->Order();
497
                if (!isset($similarArray[$otherOrder->ID])) {
498
                    $similarArray[$otherOrder->ID] = array();
499
                }
500
                $similarArray[$otherOrder->ID]["ProxyIP"] = $otherOrder;
501
            }
502
            $this->blacklistCheck($ipProxyArray, 'EcommerceSecurityProxyIP');
503
        }
504
505
506
        if (count($this->warningMessages)) {
507
            $html .= '
508
                <h4 style="color: red;">Blacklisted Details</h4>
509
                <ul class="SecurityCheckListOfRisks warnings" style="color: red;">';
510
            foreach ($this->warningMessages as $warningMessage) {
511
                $html .= $warningMessage;
512
            }
513
            $html .= '
514
                </ul>';
515
        } else {
516
            $html .= '<p class="message good">No Blacklisted Data Present</p>';
517
        }
518
        if (count($similarArray)) {
519
            $days = $this->Config()->get('days_ago_to_check');
520
            $html .= '
521
                <h4>Similar orders in the last '.$days.' days</h4>
522
                <ul class="SecurityCheckListOfRisks otherRisks">';
523
            foreach ($similarArray as $orderID => $fields) {
524
                //we just loop this so we can get the order ...
525
                foreach ($fields as $tempOrder) {
526
                    break;
527
                }
528
                $html .= '
529
                    <li><a href="'.$tempOrder->CMSEditLink().'">'.$tempOrder->getTitle().'</a>: with same '.implode(', and with same ', array_keys($fields)).'</li>';
0 ignored issues
show
Bug introduced by
The variable $tempOrder seems to be defined by a foreach iteration on line 525. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
530
            }
531
            $html .= '
532
                </ul>';
533
        } else {
534
            $html .= '<p class="message good">No similar orders in the last '.$daysAgo.' days</p>';
535
        }
536
537
        return $html;
538
    }
539
540
    public function getSecurityCleared()
541
    {
542
        return  DBField::create_field('Boolean', ($this->pass() ? true : false));
543
    }
544
545
    /**
546
     *
547
     *
548
     *
549
     * @param  Order $order
0 ignored issues
show
Bug introduced by
There is no parameter named $order. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
550
     * @return bool
551
     */
552
    public function pass()
553
    {
554
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_SecurityCheck>? 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...
555
        if (! $order) {
556
            return false;
557
        }
558
        $checks = $this->Config()->get('checks_required');
559
        $fieldsAvailable = $this->stat('db');
560
        foreach ($checks as $fieldName => $fieldDetails) {
561
            if (floatval($this->SubTotal) > floatval($fieldDetails['SubTotalMin'])) {
0 ignored issues
show
Documentation introduced by
The property SubTotal does not exist on object<OrderStatusLog_SecurityCheck>. 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...
562
                if (! isset($fieldsAvailable[$fieldName])) {
563
                    user_error('bad field  ....');
564
                }
565
                // there is a check that needs to be TRUE, but is not ...
566
                if ($this->$fieldName == 'Done' || $this->$fieldName == 'Whitelisted Customer') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
567
                } else {
568
                    return false;
569
                }
570
            }
571
        }
572
        return true;
573
    }
574
575
    private static $_saved_already = 0;
576
577
    public function onAfterWrite()
578
    {
579
        parent::onAfterWrite();
580
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_SecurityCheck>? 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...
581
        if (self::$_saved_already < 3) {
582
            self::$_saved_already++;
583
            if ($order && $order->exists()) {
584
                $this->SubTotal = $order->getSubTotal();
0 ignored issues
show
Documentation introduced by
The property SubTotal does not exist on object<OrderStatusLog_SecurityCheck>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
585
                $this->Risks = $this->collateRisks();
0 ignored issues
show
Documentation introduced by
The property Risks does not exist on object<OrderStatusLog_SecurityCheck>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
586
                $this->write();
587
            } else {
588
                $this->SubTotal = 9999;
0 ignored issues
show
Documentation introduced by
The property SubTotal does not exist on object<OrderStatusLog_SecurityCheck>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
589
                $this->Risks = "Error";
0 ignored issues
show
Documentation introduced by
The property Risks does not exist on object<OrderStatusLog_SecurityCheck>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
590
                $this->write();
591
            }
592
            if ($this->memberIsWhitelisted()) {
593
                for ($i = 1; $i < 13; $i++) {
594
                    $field = "Check".$i;
595
                    $this->$field = 'Whitelisted Customer';
596
                }
597
                $this->write();
598
            }
599
        }
600
        if ($this->Bad) {
0 ignored issues
show
Documentation introduced by
The property Bad does not exist on object<OrderStatusLog_SecurityCheck>. 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...
601
            foreach ($this->BlacklistItems() as $blacklistItem) {
0 ignored issues
show
Documentation Bug introduced by
The method BlacklistItems does not exist on object<OrderStatusLog_SecurityCheck>? 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...
602
                $blacklistItem->Status = 'Bad';
603
                $blacklistItem->write();
604
            }
605
            if ($order && $order->exists()) {
606
                $order->Archive(true);
607
            }
608
            if ($member = $this->orderMember()) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $member is correct as $this->orderMember() (which targets OrderStatusLog_SecurityCheck::orderMember()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
609
                $member->IsWhitelisted = false;
610
                $member->IsSecurityRisk = true;
611
                $member->write();
612
            }
613
        }
614
    }
615
616
    /**
617
     *
618
     * @param  EcommerceSecurityBaseClass $obj
619
     * @return bool                             return true if the status of the object is `Bad`
620
     */
621
    protected function checkSecurityObject($obj)
622
    {
623
        if ($obj->Status == 'Bad') {
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<EcommerceSecurityBaseClass>. 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...
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($obj->Status == 'Bad');.
Loading history...
624
            return false;
625
        }
626
        return true;
627
    }
628
629
    /**
630
     * caching variable only...
631
     *
632
     * @var null | bool
633
     */
634
    private $_memberIsWhitelisted = null;
635
636
    protected function memberIsWhitelisted()
637
    {
638
        if ($this->_memberIsWhitelisted  === null) {
639
            if ($member = $this->orderMember()) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $member is correct as $this->orderMember() (which targets OrderStatusLog_SecurityCheck::orderMember()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
640
                $this->_memberIsWhitelisted = OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member);
0 ignored issues
show
Documentation Bug introduced by
It seems like \OrderStatusLog_Whitelis...is_whitelisted($member) of type boolean is incompatible with the declared type null of property $_memberIsWhitelisted.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
641
            }
642
        }
643
        return $this->_memberIsWhitelisted;
644
    }
645
646
    /**
647
     *
648
     * @return null | Member
649
     */
650
    protected function orderMember()
651
    {
652
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_SecurityCheck>? 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...
653
        if ($order && $order->exists()) {
654
            $member = $order->Member();
655
            if ($member && $member->exists()) {
656
                return $member;
657
            }
658
        }
659
    }
660
661
    protected function blacklistCheck($arrayOfValues, $securityClass)
662
    {
663
        //adding all emails to security checks
664
        foreach ($arrayOfValues as $value) {
665
            if ($value) {
666
                $obj = $securityClass::find_or_create(array("Title" => $value));
667
                if ($obj->exists()) {
668
                    $this->BlacklistItems()->add($obj);
0 ignored issues
show
Documentation Bug introduced by
The method BlacklistItems does not exist on object<OrderStatusLog_SecurityCheck>? 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...
669
                    if ($obj->hasRisks()) {
670
                        $title = $obj->i18n_singular_name();
671
                        $message = '<li><strong>'.$title.':</strong> '.$value.'<li>';
672
                        $this->warningMessages[$message] = $message;
673
                    }
674
                }
675
            }
676
        }
677
    }
678
}
679