Completed
Push — master ( 626e87...f67c15 )
by
unknown
01:26
created

OrderStepFeefo::doStep()   B

Complexity

Conditions 4
Paths 10

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 16
nc 10
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
    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...
9
        'FeedbackDelay' => 'Int'
10
    );
11
12
13
    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...
14
        'CustomerCanEdit' => 0,
15
        'CustomerCanCancel' => 0,
16
        'CustomerCanPay' => 0,
17
        'Name' => 'Send Order To Feefo',
18
        'Code' => 'FEEFO',
19
        "ShowAsInProcessOrder" => true,
20
        "HideStepFromCustomer" => true
21
    );
22
23
24
    public function getCMSFields()
25
    {
26
        $fields = parent::getCMSFields();
27
        $fields->removeByName('FeedbackDelay');
28
29
        $fields->addFieldToTab(
30
            'Root.Feefo',
31
            NumericField::create(
32
                'FeedbackDelay',
33
                'Feedback Delay'
34
            )
35
        );
36
37
        return $fields;
38
    }
39
40
    public function initStep(Order $order)
41
    {
42
        return true;
43
    }
44
45
    public function doStep(Order $order)
46
    {
47
48
        $api = Injector::inst()->get('EntersaleremotelyAPIConnector');
49
        try {
50
            $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...
51
            $result = $this->convertArrayToHTMLList($result);
52
53
            $className = $this->getRelevantLogEntryClassName();
54
55
            if (class_exists($className)) {
56
                $obj = $className::create();
57
                if (is_a($obj, Object::getCustomClass('OrderStatusLog'))) {
58
                    $obj->OrderID = $order->ID;
59
                    $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...
60
                    $obj->DetailedInfo = $result;
61
                    $obj->write();
62
                }
63
            }
64
65
        }
66
        catch (Exception $e) {
67
            $e->getMessage();
68
        }
69
70
        return true;
71
    }
72
73
    /**
74
     * can continue if emails has been sent or if there is no need to send a receipt.
75
     * @param DataObject $order Order
76
     * @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...
77
     **/
78
    public function nextStep(Order $order)
79
    {
80
        return parent::nextStep($order);
81
    }
82
83
    /**
84
     * For some ordersteps this returns true...
85
     * @return Boolean
86
     **/
87
    protected function hasCustomerMessage()
88
    {
89
        return false;
90
    }
91
92
    /**
93
     * Explains the current order step.
94
     * @return String
95
     */
96
    protected function myDescription()
97
    {
98
        return "The customer and order data is sent to Feefo via the Entersaleremotely API.";
99
    }
100
101
    public function convertArrayToHTMLList($array){
102
        $html = '<ul>';
103
        foreach($array as $arrayItem){
104
            $html .= '<li>' . $arrayItem . '</li>';
105
        }
106
        $html .= '</ul>';
107
        return $html;
108
    }
109
}
110