Passed
Pull Request — master (#29)
by Jason
02:29
created

getNumberPurchasedUpdate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 2
nop 0
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Extension;
4
5
use Dynamic\Foxy\Orders\Model\OrderDetail;
6
use Dynamic\Foxy\Orders\Model\OrderVariation;
7
use SilverStripe\ORM\ArrayList;
8
use SilverStripe\ORM\DataList;
9
10
class ProductVariationInventoryManager extends ProductInventoryManager
11
{
12
    /**
13
     * @param $available
14
     */
15
    public function updateGetIsAvailable(&$available)
16
    {
17
        if ($this->getHasInventory()) {
18
            $available = $this->getIsProductAvailable();
19
        }
20
    }
21
22
    /**
23
     * @return int
24
     */
25
    public function getNumberPurchasedUpdate()
26
    {
27
        $ct = 0;
28
        if ($this->getOrders()) {
29
            foreach ($this->getOrders() as $order) {
30
                $ct += $order->Quantity;
31
            }
32
        }
33
        return $ct;
34
    }
35
36
    /**
37
     * @return DataList
38
     */
39
    public function getOrders()
40
    {
41
        if ($this->owner->ID) {
42
            $orderVariations = OrderVariation::get()->filter('VariationID', $this->owner->ID);
43
            if ($orderVariations) {
0 ignored issues
show
introduced by
$orderVariations is of type SilverStripe\ORM\DataList, thus it always evaluated to true.
Loading history...
44
                $orders = ArrayList::create();
45
                foreach ($orderVariations as $orderVariation) {
46
                    $orderDetail = OrderDetail::get()->byID($orderVariation->OrderDetailID);
47
                    $orders->push($orderDetail);
48
                }
49
            }
50
51
            return $orders;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $orders does not seem to be defined for all execution paths leading up to this point.
Loading history...
52
53
        }
54
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type SilverStripe\ORM\DataList.
Loading history...
55
    }
56
}
57