OrderStatusLog_WhitelistCustomer   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 166
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 6
dl 0
loc 166
rs 10
c 0
b 0
f 0

10 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 4 1
A canDelete() 0 4 1
A getCMSFields() 0 21 1
A member_is_security_risk() 0 4 1
A member_is_whitelisted() 0 7 2
A onAfterWrite() 0 12 4
C assessCustomer() 0 58 12
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_WhitelistCustomer 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
    /**
13
     * @var int
14
     */
15
    private static $min_number_of_paid_orders_required = 1;
0 ignored issues
show
Unused Code introduced by
The property $min_number_of_paid_orders_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...
16
17
    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...
18
        'Whitelist' => 'Boolean'
19
    );
20
21
    private static $has_one = 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 $has_one 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
        'Member' => 'Member',
23
        'BasedOn' => 'OrderStatusLog_WhitelistCustomer'
24
    );
25
26
    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...
27
        'InternalUseOnly' => true
28
    );
29
30
    private static $singular_name = 'Whitelist Customer Record';
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...
31
    public function i18n_singular_name()
32
    {
33
        return self::$singular_name;
34
    }
35
36
    private static $plural_name = 'Whitelist Customer Records';
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...
37
    public function i18n_plural_name()
38
    {
39
        return self::$plural_name;
40
    }
41
42
    public function canCreate($member = null)
43
    {
44
        return false;
45
    }
46
47
    public function canEdit($member = null)
48
    {
49
        return parent::canEdit($member);
50
    }
51
52
    public function canDelete($member = null)
53
    {
54
        return false;
55
    }
56
57
    public function getCMSFields()
58
    {
59
        $fields = parent::getCMSFields();
60
        $fields->replaceField(
61
            'BasedOnID',
62
            CMSEditLinkField::create(
63
                'BasedOnID',
64
                _t('OrderStatusLog_WhitelistCustomer.BASED_ON', 'Based on'),
65
                $this->BasedOn()
0 ignored issues
show
Documentation Bug introduced by
The method BasedOn does not exist on object<OrderStatusLog_WhitelistCustomer>? 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...
66
            )
67
        );
68
        $fields->replaceField(
69
            'MemberID',
70
            CMSEditLinkField::create(
71
                'MemberID',
72
                _t('OrderStatusLog_WhitelistCustomer.CUSTOMER', 'Customer'),
73
                $this->Member()
0 ignored issues
show
Bug introduced by
The method Member() does not exist on OrderStatusLog_WhitelistCustomer. Did you maybe mean member_is_security_risk()?

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...
74
            )
75
        );
76
        return $fields;
77
    }
78
79
    /**
80
     *
81
     *
82
     * @param  Member  $member  the member to check
83
     * @return boolean          returns true of the member is a security risk
84
     */
85
    public static function member_is_security_risk(Member $member)
86
    {
87
        return $member->IsSecurityRisk;
88
    }
89
90
    /**
91
     *
92
     *
93
     * @param  Member  $member  the member to check
94
     * @return boolean          returns true of the member has been whitelisted before
95
     */
96
    public static function member_is_whitelisted(Member $member)
97
    {
98
        if ($member->IsSecurityRisk) {
99
            return false;
100
        }
101
        return $member->IsWhitelisted;
102
    }
103
104
    public function onAfterWrite()
105
    {
106
        parent::onAfterWrite();
107
        if ($this->Whitelist) {
0 ignored issues
show
Documentation introduced by
The property Whitelist does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
108
            if ($member = $this->Member()) {
0 ignored issues
show
Bug introduced by
The method Member() does not exist on OrderStatusLog_WhitelistCustomer. Did you maybe mean member_is_security_risk()?

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...
109
                if ($member->exists()) {
110
                    $member->IsWhitelisted = true;
111
                    $member->write();
112
                }
113
            }
114
        }
115
    }
116
117
    public function assessCustomer()
118
    {
119
        //already done ...
120
        if ($this->Whitelist) {
0 ignored issues
show
Documentation introduced by
The property Whitelist does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
121
            return true;
122
        }
123
        $order = $this->Order();
0 ignored issues
show
Documentation Bug introduced by
The method Order does not exist on object<OrderStatusLog_WhitelistCustomer>? 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...
124
        if ($order && $order->exists()) {
125
            if ($order->MemberID) {
126
                $this->MemberID = $order->MemberID;
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
127
                $this->Whitelist = false;
0 ignored issues
show
Documentation introduced by
The property Whitelist does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
128
                $member = $order->Member();
129
                if ($member && $member->exists()) {
130
                    //check if member has previouly been whitelisted
131
                    $previousOne = OrderStatusLog_WhitelistCustomer::get()
132
                        ->filter(
133
                            array(
134
                                'Whitelist' => 1,
135
                                'MemberID' => $member->ID
136
                            )
137
                        )
138
                        ->exclude(
139
                            array('OrderID' => $order->ID)
140
                        )->first();
141
                    if ($previousOne) {
142
                        $this->Whitelist = true;
0 ignored issues
show
Documentation introduced by
The property Whitelist does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
143
                        $this->BasedOnID = $previousOne->ID;
0 ignored issues
show
Documentation introduced by
The property BasedOnID does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
144
                    } else {
145
                        //member has placed orders before
146
                        $previousOrders = Order::get()
147
                            ->filter(
148
                                array(
149
                                    'MemberID' => $member->ID,
150
                                    'CancelledByID' => 0
151
                                )
152
                            )
153
                            ->exclude(
154
                                array(
155
                                    'ID' => $order->ID
156
                                )
157
                            );
158
                        $count = 0;
159
                        $minOrdersRequired = $this->Config()->get('min_number_of_paid_orders_required');
160
                        foreach ($previousOrders as $previousOrder) {
161
                            if ($previousOrder->IsPaid() && $previousOrder->IsArchived()) {
162
                                $count++;
163
                                if ($count >= $minOrdersRequired) {
164
                                    $this->Whitelist = true;
0 ignored issues
show
Documentation introduced by
The property Whitelist does not exist on object<OrderStatusLog_WhitelistCustomer>. 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...
165
                                    break;
166
                                }
167
                            }
168
                        }
169
                    }
170
                }
171
                $this->write();
172
            }
173
        }
174
    }
175
}
176