OrderStepFeefo::initStep()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
5
class OrderStepFeefo extends OrderStep
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...
6
{
7
8
    /**
9
     * The OrderStatusLog that is relevant to the particular step.
10
     *
11
     * @var string
12
     */
13
    protected $relevantLogEntryClassName = 'OrderStatusLog_FeefoLog';
14
15
    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...
16
        'SendData' => 'Boolean',
17
        'FeedbackDelay' => 'Int'
18
    );
19
20
21
    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...
22
        'CustomerCanEdit' => 0,
23
        'CustomerCanCancel' => 0,
24
        'CustomerCanPay' => 0,
25
        'Name' => 'Send Order To Feefo',
26
        'Code' => 'FEEFO',
27
        "ShowAsInProcessOrder" => true,
28
        "HideStepFromCustomer" => true
29
    );
30
31
32
    public function getCMSFields()
33
    {
34
        $fields = parent::getCMSFields();
35
        $fields->removeByName('FeedbackDelay');
36
37
        $fields->addFieldsToTab(
38
            'Root.Feefo',
39
            [
40
                CheckboxField::create(
41
                    'SendData',
42
                    'Send Data'
43
                )->setDescription('If checked then the order data will be sent to Feefo, once this order step is reached.'),
44
                NumericField::create(
45
                    'FeedbackDelay',
46
                    'Feedback Delay'
47
                )->setRightTitle('The amount of after the order has been sent before Feefo should send the feedback request email.')
48
            ]
49
        );
50
51
52
        return $fields;
53
    }
54
55
    public function initStep(Order $order)
56
    {
57
        return true;
58
    }
59
60
    public function doStep(Order $order)
61
    {
62
        if ($this->SendData && $order->IsPaid()) {
0 ignored issues
show
Documentation introduced by
The property SendData does not exist on object<OrderStepFeefo>. 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...
63
            $api = Injector::inst()->get('EntersaleremotelyAPIConnector');
64
65
            $result = $api->sendOrderDataToFeefo($order, $this->FeedbackDelay);
0 ignored issues
show
Documentation introduced by
The property FeedbackDelay does not exist on object<OrderStepFeefo>. 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...
66
            $result = $this->convertArrayToHTMLList($result);
67
68
69
70
            $className = $this->getRelevantLogEntryClassName();
71
72
            if (class_exists($className)) {
73
                $obj = $className::create();
74
                if (is_a($obj, Object::getCustomClass('OrderStatusLog'))) {
75
                    $obj->OrderID = $order->ID;
76
                    $obj->Title = $this->Name;
0 ignored issues
show
Documentation introduced by
The property Name does not exist on object<OrderStepFeefo>. 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...
77
                    $obj->DetailedInfo = $result;
78
                    $obj->write();
79
                }
80
            }
81
        }
82
83
        return true;
84
    }
85
86
    /**
87
     * can continue if emails has been sent or if there is no need to send a receipt.
88
     * @param DataObject $order Order
89
     * @return DataObject | Null - DataObject = next OrderStep
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...
90
     **/
91
    public function nextStep(Order $order)
92
    {
93
        return parent::nextStep($order);
94
    }
95
96
    /**
97
     * For some ordersteps this returns true...
98
     * @return Boolean
99
     **/
100
    protected function hasCustomerMessage()
101
    {
102
        return false;
103
    }
104
105
    /**
106
     * Explains the current order step.
107
     * @return String
108
     */
109
    protected function myDescription()
110
    {
111
        return "The customer and order data is sent to Feefo via the Entersaleremotely API.";
112
    }
113
114
    public function convertArrayToHTMLList($array)
115
    {
116
        $html = '<ul>';
117
        foreach ($array as $arrayItem) {
118
            $html .= '<li>' . $arrayItem . '</li>';
119
        }
120
        $html .= '</ul>';
121
        return $html;
122
    }
123
}
124