DiscountCouponModifier::LiveName()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
/**
4
 * @author Nicolaas [at] sunnysideup.co.nz
5
 * @author Romain [at] sunnysideup.co.nz
6
 * @package: ecommerce
7
 * @sub-package: ecommerce_delivery
8
 * @description: Shipping calculation scheme based on SimpleShippingModifier.
9
 * It lets you set fixed shipping costs, or a fixed
10
 * cost for each region you're delivering to.
11
 */
12
class DiscountCouponModifier extends OrderModifier
13
{
14
    // ######################################## *** model defining static variables (e.g. $db, $has_one)
15
16
    /**
17
     * standard SS Variable
18
     * @var Array
19
     */
20
    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...
21
        'DebugString' => 'HTMLText',
22
        'SubTotalAmount' => 'Currency',
23
        'CouponCodeEntered' => 'Varchar(25)'
24
    );
25
26
    /**
27
     * standard SS Variable
28
     * @var Array
29
     */
30
    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...
31
        "DiscountCouponOption" => "DiscountCouponOption"
32
    );
33
34
    /**
35
     * Should the discount be worked out over the the sub-total or
36
     * the Total Total?
37
     * @var Boolean
38
     */
39
    private static $include_modifiers_in_subtotal = false;
40
41
    /**
42
     * If this method is present in the Buyable, the related order item will be excluded
43
     * @var Boolean
44
     */
45
    private static $exclude_buyable_method = 'ExcludeInDiscountCalculation';
46
47
    /**
48
     * Standard SS Variable
49
     * @var String
50
     */
51
    private static $singular_name = "Discount Coupon Entry";
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...
52
53
    public function i18n_singular_name()
54
    {
55
        return _t("DiscountCouponModifier.SINGULAR_NAME", "Discount Coupon Entry");
56
    }
57
58
    /**
59
     * Standard SS Variable
60
     * @var String
61
     */
62
    private static $plural_name = "Discount Coupon Entries";
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...
63
64
    public function i18n_plural_name()
65
    {
66
        return _t("DiscountCouponModifier.PLURAL_NAME", "Discount Coupon Entries");
67
    }
68
69
    // ######################################## *** cms variables + functions (e.g. getCMSFields, $searchableFields)
70
71
    /**
72
     * Standard SS Method
73
     * @return FieldList
74
     */
75
    public function getCMSFields()
76
    {
77
        $fields = parent::getCMSFields();
78
        $fields->removeByName("DebugString");
79
        $fields->removeByName("SubTotalAmount");
80
        $fields->removeByName("OrderCoupon");
81
        $fields->addFieldToTab(
82
                "Root.Debug",
83
            new ReadonlyField(
84
                "SubTotalAmountShown",
85
                    _t("DiscountCouponModifier.SUB_TOTAL_AMOUNT", "sub-total amount"),
86
                    $this->SubTotalAmount
0 ignored issues
show
Bug introduced by
The property SubTotalAmount does not seem to exist. Did you mean subtotal?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
87
                )
88
        );
89
        $fields->addFieldToTab(
90
                "Root.Debug",
91
            new ReadonlyField(
92
                "DebugStringShown",
93
                    _t("DiscountCouponModifier.DEBUG_STRING", "debug string"),
94
                    $this->DebugString
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
95
                )
96
        );
97
        return $fields;
98
    }
99
100
    // ######################################## *** other (non) static variables (e.g. private static $special_name_for_something, protected $order)
101
102
    /**
103
     * Used in calculations to work out how much we need.
104
     * @var Double | Null
105
     */
106
    protected $_actualDeductions = null;
107
108
    // ######################################## *** CRUD functions (e.g. canEdit)
109
    // ######################################## *** init and update functions
110
    /**
111
     * updates all database fields
112
     *
113
     * @param Bool $force - run it, even if it has run already
114
     */
115
    public function runUpdate($force = false)
116
    {
117
        if (!$this->IsRemoved()) {
118
            $this->checkField("SubTotalAmount");
119
            $this->checkField("CouponCodeEntered");
120
            $this->checkField("DiscountCouponOptionID");
121
        }
122
        parent::runUpdate($force);
123
    }
124
125
    // ######################################## *** form functions (e. g. showform and getform)
126
127
    /**
128
     * Show the form?
129
     * We always show it when there are items in the cart.
130
     * @return Boolean
131
     */
132
    public function ShowForm()
133
    {
134
        $items = $this->Order()->Items();
135
        if ($items) {
136
            //-- START HACK
137
            return true;
138
            //-- END HACK
139
            if (singleton('DiscountCouponOption')->hasExtension('DiscountCouponSiteTreeDOD')) {
0 ignored issues
show
Unused Code introduced by
if (singleton('DiscountC...sed' => 0))->count(); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
140
                foreach ($items as $item) {
141
                    //here we need to add foreach valid coupon
142
                    //for each item->Buyable
143
                    //check if the coupon
144
                    //can be applied to the buyable
145
                }
146
            } else {
147
                return DiscountCouponOption::get()->exclude(array("NumberOfTimesCouponCanBeUsed" => 0))->count();
148
            }
149
        } else {
150
            return false;
151
        }
152
    }
153
154
    /**
155
     * @param Controller $optionalController
0 ignored issues
show
Documentation introduced by
Should the type for parameter $optionalController not be null|Controller?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
156
     * @param Validator $optionalValidator
0 ignored issues
show
Documentation introduced by
Should the type for parameter $optionalValidator not be null|Validator?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
157
     * @return DiscountCouponModifier_Form
158
     */
159
    public function getModifierForm(Controller $optionalController = null, Validator $optionalValidator = null)
160
    {
161
        $fields = new FieldList(
162
            $this->headingField(),
163
            $this->descriptionField(),
164
            new TextField(
165
                'DiscountCouponCode',
166
                _t("DiscountCouponModifier.COUPON", 'Coupon'),
167
                $this->LiveCouponCodeEntered()
168
            )
169
        );
170
        $actions = new FieldList(
171
            new FormAction(
172
                'submit',
173
                _t("DiscountCouponModifier.APPLY", 'Apply Coupon')
174
            )
175
        );
176
        $form = new DiscountCouponModifier_Form(
177
            $optionalController,
178
            'DiscountCouponModifier',
179
            $fields,
180
            $actions,
181
            $optionalValidator
182
        );
183
        $fields->fieldByName("DiscountCouponCode")->setValue($this->CouponCodeEntered);
0 ignored issues
show
Documentation introduced by
The property CouponCodeEntered does not exist on object<DiscountCouponModifier>. 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...
184
        return $form;
185
    }
186
187
    /**
188
     * @param String $code - code that has been entered
189
     *
190
     * @return array
191
     * */
192
    public function updateCouponCodeEntered($code)
193
    {
194
        //set to new value ....
195
        $this->CouponCodeEntered = $code;
0 ignored issues
show
Documentation introduced by
The property CouponCodeEntered does not exist on object<DiscountCouponModifier>. 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...
196
        $coupon = DiscountCouponOption::get()
197
            ->filter(array("Code" => $code))->first();
198
        //apply valid discount coupong
199
        if ($coupon) {
200
            if ($coupon->IsValid() && $this->isValidAdditional($coupon)) {
0 ignored issues
show
Compatibility introduced by
$coupon of type object<DataObject> is not a sub-type of object<DiscountCouponOption>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
201
                $this->setCoupon($coupon);
0 ignored issues
show
Compatibility introduced by
$coupon of type object<DataObject> is not a sub-type of object<DiscountCouponOption>. It seems like you assume a child class of the class DataObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
202
                $messages = array(_t('DiscountCouponModifier.APPLIED', 'Coupon applied'), 'good');
203
            } else {
204
                $messages = array(_t('DiscountCouponModifier.NOT_VALID', 'Coupon is no longer available'), 'bad');
205
                $this->DiscountCouponOptionID = 0;
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
206
            }
207
        } elseif ($code) {
208
            $messages = array(_t('DiscountCouponModifier.NOTFOUND', 'Coupon could not be found'), 'bad');
209
            if ($this->DiscountCouponOptionID) {
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
210
                $this->DiscountCouponOptionID = 0;
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
211
                $messages = array(_t('DiscountCouponModifier.REMOVED', 'Existing coupon removed'), 'good');
212
            }
213
        } else {
214
            //to do: do we need to remove it again?
215
            $messages = array(_t('DiscountCouponModifier.NOT_ENTERED', 'No coupon was entered'), 'bad');
216
        }
217
        $this->write();
218
219
        return $messages;
220
    }
221
222
    /**
223
     * @param DiscountCouponOption $coupon
224
     */
225
    public function setCoupon($coupon)
226
    {
227
        $this->DiscountCouponOptionID = $coupon->ID;
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
228
        $this->write();
229
    }
230
231
    /**
232
     * @param int $couponID
233
     */
234
    public function setCouponByID($couponID)
235
    {
236
        $this->DiscountCouponOptionID = $couponID;
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
237
        $this->write();
238
    }
239
240
    // ######################################## *** template functions (e.g. ShowInTable, TableTitle, etc...) ... USES DB VALUES
241
242
    /**
243
     * @see self::HideInAjaxUpdate
244
     *
245
     * @return boolean
246
     */
247
    public function ShowInTable()
248
    {
249
        if ($this->DiscountCouponOptionID) {
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
250
            return true;
251
        } elseif ($this->Order()->IsSubmitted()) {
252
            return false;
253
        } else {
254
            //we hide it with ajax if needed
255
            return true;
256
        }
257
    }
258
259
    /**
260
     * @return boolean
261
     */
262
    public function CanRemove()
263
    {
264
        return false;
265
    }
266
267
    /**
268
     * @return float
269
     */
270
    public function CartValue()
271
    {
272
        return $this->getCartValue();
273
    }
274
275
    public function getCartValue()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
276
    {
277
        return $this->TableValue;
0 ignored issues
show
Documentation introduced by
The property TableValue does not exist on object<DiscountCouponModifier>. 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...
278
    }
279
280
    // ######################################## ***  inner calculations.... USES CALCULATED VALUES
281
282
    /**
283
     * Checks for extensions to make sure it is valid...
284
     * @param DiscountCouponOption $coupon
285
     * @return bool returns true if the coupon is valid
286
     */
287
    protected function isValidAdditional($coupon)
288
    {
289
        $exclusions = $this->extend('checkForExclusions', $coupon);
290
        if (is_array($exclusions) && count($exclusions)) {
291
            foreach ($exclusions as $exclusion) {
292
                if ($exclusion === true) {
293
                    return false;
294
                }
295
            }
296
        }
297
        return true;
298
    }
299
300
    /**
301
     * returns the discount coupon, if any ...
302
     *
303
     * @return DiscountCouponOption | null
0 ignored issues
show
Documentation introduced by
Should the return type not be DiscountCouponOption|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...
304
     */
305
    protected function myDiscountCouponOption()
306
    {
307
        $coupon = null;
0 ignored issues
show
Unused Code introduced by
$coupon is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
308
        if ($id = $this->LiveDiscountCouponOptionID()) {
309
            $coupon = DiscountCouponOption::get()->byID($id);
310
            if ($coupon) {
311
                if ($coupon->ApplyPercentageToApplicableProducts) {
312
                    $arrayOfOrderItemsToWhichThisCouponApplies = $this->applicableProductsArray($coupon);
313
                    if (count($arrayOfOrderItemsToWhichThisCouponApplies)) {
314
                        return $coupon;
315
                    }
316
                } else {
317
                    return $coupon;
318
                }
319
            }
320
        }
321
        return null;
322
    }
323
324
    private static $_applicable_products_array = null;
325
326
    /**
327
     * returns an Array of OrderItem IDs
328
     * to which the coupon applies
329
     * @param DiscountCouponOption
330
     * @return Array
331
     */
332
    protected function applicableProductsArray($coupon)
333
    {
334
        if (self::$_applicable_products_array === null) {
335
            self::$_applicable_products_array = array();
336
            $finalArray = array();
337
            $order = $this->Order();
338
            if ($order) {
339
                $items = $order->Items();
340
                if ($items && $items->count()) {
341
                    //get a list of all the products in the cart
342
                    $arrayOfProductsInOrder = array();
343
                    foreach ($items as $item) {
344
                        $buyable = $item->Buyable();
345
                        if ($buyable instanceof ProductVaration) {
0 ignored issues
show
Bug introduced by
The class ProductVaration does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
346
                            $buyable = $buyable->Product();
347
                        }
348
                        $arrayOfProductsInOrder[$item->ID] = $buyable->ID;
349
                    }
350
                    //if no products / product groups are specified then
351
                    //it applies
352
                    //get a list of all the products to which the coupon applies
353
                    $productsArray = $coupon->Products()->map("ID", "ID")->toArray();
354
                    if (count($productsArray)) {
355
                        $matches = array_intersect($productsArray, $arrayOfProductsInOrder);
356
                        foreach ($matches as $buyableID) {
357
                            foreach ($arrayOfProductsInOrder as $itemID => $innerBuyableID) {
358
                                if ($buyableID == $innerBuyableID) {
359
                                    $finalArray[$itemID] = $itemID;
360
                                }
361
                            }
362
                        }
363
                    } else {
364
                        foreach ($arrayOfProductsInOrder as $itemID => $buyableID) {
365
                            $finalArray[$itemID] = $itemID;
366
                        }
367
                    }
368
                }
369
            }
370
            self::$_applicable_products_array = $finalArray;
371
        }
372
        return self::$_applicable_products_array;
373
    }
374
375
    // ######################################## *** calculate database fields: protected function Live[field name]  ... USES CALCULATED VALUES
376
377
    /**
378
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

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...
379
     * */
380
    protected function LiveName()
381
    {
382
        $code = $this->LiveCouponCodeEntered();
383
        $coupon = $this->myDiscountCouponOption();
384
        if ($coupon) {
385
            return _t("DiscountCouponModifier.COUPON", "Coupon") . " '" . $code . "' " . _t("DiscountCouponModifier.APPLIED", "applied.");
386
        } elseif ($code) {
387
            return _t("DiscountCouponModifier.COUPON", "Coupon") . " '" . $code . "' " . _t("DiscountCouponModifier.COULDNOTBEAPPLIED", "could not be applied.");
388
        }
389
        return _t("DiscountCouponModifier.NOCOUPONENTERED", "No (valid) coupon entered") . $code;
390
    }
391
392
    private static $subtotal = 0;
393
394
    /**
395
     * @return float
396
     * */
397
    protected function LiveSubTotalAmount()
398
    {
399
        if (!self::$subtotal) {
400
            $order = $this->Order();
401
            $items = $order->Items();
402
            $coupon = $this->myDiscountCouponOption();
403
            if ($coupon && $coupon->ApplyPercentageToApplicableProducts) {
0 ignored issues
show
Documentation introduced by
The property ApplyPercentageToApplicableProducts does not exist on object<DiscountCouponOption>. 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...
404
                $array = $this->applicableProductsArray($coupon);
405
                $subTotal = 0;
406
                if (count($array)) {
407
                    if ($items) {
408
                        $itemCount = 0;
0 ignored issues
show
Unused Code introduced by
$itemCount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
409
                        foreach ($items as $item) {
410
                            if (in_array($item->ID, $array)) {
411
                                $subTotal += $item->Total();
412
                            }
413
                        }
414
                    }
415
                }
416
            } else {
417
                $subTotal = $order->SubTotal();
418
                $function = $this->Config()->get("exclude_buyable_method");
419
                if ($items) {
420
                    foreach ($items as $item) {
421
                        $buyable = $item->Buyable();
422
                        if ($buyable && $buyable->hasMethod($function) && $buyable->$function($this)) {
423
                            $subTotal -= $item->Total();
424
                        }
425
                    }
426
                }
427
                if ($this->Config()->get("include_modifiers_in_subtotal")) {
428
                    $subTotal += $order->ModifiersSubTotal(array(get_class($this)));
429
                }
430
            }
431
432
            self::$subtotal = $subTotal;
433
        }
434
        return self::$subtotal;
435
    }
436
437
    protected $_calculatedTotal = null;
438
439
    /**
440
     * @return float
441
     * */
442
    protected function LiveCalculatedTotal()
443
    {
444
        if ($this->_calculatedTotal === null) {
445
            $this->_calculatedTotal = 0;
446
            $this->_actualDeductions = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $_actualDeductions was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
447
            $this->DebugString = "";
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
448
            $subTotal = $this->LiveSubTotalAmount();
449
            $coupon = $this->myDiscountCouponOption();
450
            if ($coupon && $this->isValidAdditional($coupon)) {
451
                if ($coupon->MinimumOrderSubTotalValue > 0 && $subTotal < $coupon->MinimumOrderSubTotalValue) {
0 ignored issues
show
Documentation introduced by
The property MinimumOrderSubTotalValue does not exist on object<DiscountCouponOption>. 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...
452
                    $this->_actualDeductions = 0;
453
                    $this->DebugString .= "<hr />sub-total is too low to offer any discount: " . $this->_actualDeductions;
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
454
                } else {
455
                    if ($coupon->DiscountAbsolute > 0) {
0 ignored issues
show
Documentation introduced by
The property DiscountAbsolute does not exist on object<DiscountCouponOption>. 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...
456
                        $this->_actualDeductions += $coupon->DiscountAbsolute;
0 ignored issues
show
Documentation introduced by
The property DiscountAbsolute does not exist on object<DiscountCouponOption>. 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...
457
                        $this->DebugString .= "<hr />using absolutes for coupon discount: " . $this->_actualDeductions;
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
458
                    }
459
                    if ($coupon->DiscountPercentage > 0) {
0 ignored issues
show
Documentation introduced by
The property DiscountPercentage does not exist on object<DiscountCouponOption>. 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...
460
                        $this->_actualDeductions += ($coupon->DiscountPercentage / 100) * $subTotal;
0 ignored issues
show
Documentation introduced by
The property DiscountPercentage does not exist on object<DiscountCouponOption>. 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...
461
                        $this->DebugString .= "<hr />using percentages for coupon discount: " . $this->_actualDeductions;
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
462
                    }
463
                }
464
                if ($coupon->MaximumDiscount > 0) {
0 ignored issues
show
Documentation introduced by
The property MaximumDiscount does not exist on object<DiscountCouponOption>. 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...
465
                    if ($this->_actualDeductions > $coupon->MaximumDiscount) {
0 ignored issues
show
Documentation introduced by
The property MaximumDiscount does not exist on object<DiscountCouponOption>. 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...
466
                        $this->DebugString .= "<hr />actual deductions (" . $this->_actualDeductions . ") are greater than maximum discount (" . $coupon->MaximumDiscount . "): ";
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
Documentation introduced by
The property MaximumDiscount does not exist on object<DiscountCouponOption>. 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...
467
                        $this->_actualDeductions = $coupon->MaximumDiscount;
0 ignored issues
show
Documentation introduced by
The property MaximumDiscount does not exist on object<DiscountCouponOption>. 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...
468
                    }
469
                }
470
            }
471
            if ($subTotal < $this->_actualDeductions) {
472
                $this->_actualDeductions = $subTotal;
473
            }
474
            $this->DebugString .= "<hr />final score: " . $this->_actualDeductions;
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
475
            $this->_actualDeductions = -1 * $this->_actualDeductions;
0 ignored issues
show
Documentation Bug introduced by
It seems like -1 * $this->_actualDeductions can also be of type integer. However, the property $_actualDeductions is declared as type double. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
476
477
            $this->_calculatedTotal = $this->_actualDeductions;
478
        }
479
        return $this->_calculatedTotal;
480
    }
481
482
    /**
483
     * @return float
484
     * */
485
    public function LiveTableValue()
486
    {
487
        return $this->LiveCalculatedTotal();
488
    }
489
490
    /**
491
     * @return String
492
     * */
493
    protected function LiveDebugString()
494
    {
495
        return $this->DebugString;
0 ignored issues
show
Documentation introduced by
The property DebugString does not exist on object<DiscountCouponModifier>. 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...
496
    }
497
498
    /**
499
     * @return String
500
     * */
501
    protected function LiveCouponCodeEntered()
502
    {
503
        return $this->CouponCodeEntered;
0 ignored issues
show
Documentation introduced by
The property CouponCodeEntered does not exist on object<DiscountCouponModifier>. 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...
504
    }
505
506
    /**
507
     * @return int
508
     * */
509
    protected function LiveDiscountCouponOptionID()
510
    {
511
        return $this->DiscountCouponOptionID;
0 ignored issues
show
Documentation introduced by
The property DiscountCouponOptionID does not exist on object<DiscountCouponModifier>. 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...
512
    }
513
514
    // ######################################## *** Type Functions (IsChargeable, IsDeductable, IsNoChange, IsRemoved)
515
516
    /**
517
     * @return Boolean
518
     * */
519
    public function IsDeductable()
520
    {
521
        return true;
522
    }
523
524
    // ######################################## *** standard database related functions (e.g. onBeforeWrite, onAfterWrite, etc...)
525
    // ######################################## *** AJAX related functions
526
    /**
527
     * some modifiers can be hidden after an ajax update (e.g. if someone enters a discount coupon and it does not exist).
528
     * There might be instances where ShowInTable (the starting point) is TRUE and HideInAjaxUpdate return false.
529
     * @return Boolean
530
     * */
531
    public function HideInAjaxUpdate()
532
    {
533
        //we check if the parent wants to hide it...
534
        //we need to do this first in case it is being removed.
535
        if (parent::HideInAjaxUpdate()) {
536
            return true;
537
        }
538
        // we do NOT hide it if values have been entered
539
        if ($this->CouponCodeEntered) {
0 ignored issues
show
Documentation introduced by
The property CouponCodeEntered does not exist on object<DiscountCouponModifier>. 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 !$this->CouponCodeEntered;.
Loading history...
540
            return false;
541
        }
542
        return true;
543
    }
544
545
    // ######################################## *** debug functions
546
}
547
548
class DiscountCouponModifier_Form extends OrderModifierForm
549
{
550
551
    /**
552
     * @var Array
553
     *
554
     */
555
    private static $custom_javascript_files = array(
556
        "ecommerce_discount_coupon/javascript/DiscountCouponModifier.js"
557
    );
558
559
    public static function get_custom_javascript_files()
560
    {
561
        $jsFiles = $this->Config()->get("custom_javascript_files");
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
562
        if (is_array($jsFiles) && count($jsFiles)) {
563
            return $jsFiles;
564
        }
565
        return null;
566
    }
567
568
    public function __construct($optionalController = null, $name, FieldList $fields, FieldList $actions, $optionalValidator = null)
569
    {
570
        parent::__construct($optionalController, $name, $fields, $actions, $optionalValidator);
571
        Requirements::themedCSS("DiscountCouponModifier", "ecommerce_discount_coupon");
572
        Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
573
        Requirements::javascript(THIRDPARTY_DIR . "/jquery-form/jquery.form.js");
574
        //Requirements::block(THIRDPARTY_DIR."/jquery/jquery.js");
575
        //Requirements::javascript(Director::protocol()."ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
576
        if ($jsRequirements = $this->Config()->get("custom_javascript_files")) {
577
            foreach ($jsRequirements as $js) {
578
                Requirements::javascript($js);
579
            }
580
        }
581
    }
582
583
    public function submit(array $data, Form $form, $message = "Order updated", $status = "good")
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
584
    {
585
        if (isset($data['DiscountCouponCode'])) {
586
            $order = ShoppingCart::current_order();
587
            if ($order) {
588
                $modifiers = $order->Modifiers('DiscountCouponModifier');
589
                $modifier = $modifiers->First();
590
                if ($modifier) {
591
                    list($message, $type) = $modifier->updateCouponCodeEntered(Convert::raw2sql($data['DiscountCouponCode']));
592
                    $form->addErrorMessage("DiscountCouponCode", $message, $type);
593
                    return ShoppingCart::singleton()->setMessageAndReturn($message, $type);
594
                }
595
            }
596
        }
597
        return ShoppingCart::singleton()->setMessageAndReturn(_t("DiscountCouponModifier.NOTAPPLIED", "Coupon could not be found.", "bad"));
598
    }
599
}
600