OrderStep_WhitelistCustomer::HideFromEveryone()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
class OrderStep_WhitelistCustomer extends OrderStep implements OrderStepInterface
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...
4
{
5
    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...
6
        'CustomerCanEdit' => 0,
7
        'CustomerCanCancel' => 0,
8
        'CustomerCanPay' => 0,
9
        'Name' => 'Whitelist Customer',
10
        'Code' => 'WHITELIST_CUSTOMER',
11
        'ShowAsInProcessOrder' => 1,
12
        'HideStepFromCustomer' => 1
13
    );
14
15
    /**
16
     * The OrderStatusLog that is relevant to the particular step.
17
     *
18
     * @var string
19
     */
20
    protected $relevantLogEntryClassName = 'OrderStatusLog_WhitelistCustomer';
21
22
    public function getCMSFields()
23
    {
24
        $fields = parent::getCMSFields();
25
26
        return $fields;
27
    }
28
29
    /**
30
     * initStep:
31
     * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt).
32
     * should be able to run this function many times to check if the step is ready.
33
     *
34
     * @see Order::doNextStatus
35
     *
36
     * @param Order object
37
     *
38
     * @return bool - true if the current step is ready to be run...
39
     **/
40
    public function initStep(Order $order)
41
    {
42
        return true;
43
    }
44
45
    /**
46
     *
47
     *
48
     * @var null | bool
49
     */
50
    private $_completed = null;
51
52
    /**
53
     * doStep:
54
     * should only be able to run this function once
55
     * (init stops you from running it twice - in theory....)
56
     * runs the actual step.
57
     *
58
     * @see Order::doNextStatus
59
     *
60
     * @param Order object
61
     *
62
     * @return bool - true if run correctly.
0 ignored issues
show
Documentation introduced by
Should the return type not be null|boolean?

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...
63
     **/
64
    public function doStep(Order $order)
65
    {
66
        if ($this->_completed !== null) {
67
            return $this->_completed;
68
        }
69
        $entry = $this->RelevantLogEntry($order);
70 View Code Duplication
        if (! $entry) {
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...
71
            $className = $this->relevantLogEntryClassName;
72
            $entry = $className::create();
73
            $entry->OrderID = $order->ID;
74
            $entry->write();
75
        }
76
        $entry->assessCustomer();
77
        $this->_completed = true;
0 ignored issues
show
Documentation Bug introduced by
It seems like true of type boolean is incompatible with the declared type null of property $_completed.

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...
78
79
        return $this->_completed;
80
    }
81
82
    /**
83
     *nextStep:
84
     * returns the next step (after it checks if everything is in place for the next step to run...).
85
     *
86
     * @see Order::doNextStatus
87
     *
88
     * @param Order $order
89
     *
90
     * @return OrderStep | Null (next step OrderStep object)
0 ignored issues
show
Documentation introduced by
Should the return type not be OrderStep|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...
91
     **/
92
    public function nextStep(Order $order)
93
    {
94
        if ($this->doStep($order)) {
95
            return parent::nextStep($order);
96
        }
97
98
        return;
99
    }
100
101
    /**
102
     * For some ordersteps this returns true...
103
     *
104
     * @return bool
105
     **/
106
    protected function hasCustomerMessage()
107
    {
108
        return false;
109
    }
110
111
    /**
112
     * Explains the current order step.
113
     *
114
     * @return string
115
     */
116
    protected function myDescription()
117
    {
118
        return 'Whitelist a customer if they qualify for this.';
119
    }
120
121
    public function HideFromEveryone()
122
    {
123
        return true;
124
    }
125
}
126