Product   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 2 Features 2
Metric Value
wmc 20
lcom 1
cbo 1
dl 0
loc 94
ccs 0
cts 74
cp 0
rs 10
c 4
b 2
f 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A uomStr() 0 4 1
A itemNumbers() 0 16 4
A getProductUomService() 0 4 1
A uomString() 0 18 3
C allUomsString() 0 22 7
A uomName() 0 7 2
A setProductUomService() 0 5 1
1
<?php
2
3
namespace SpeckCatalog\View\Helper;
4
5
use Zend\View\Helper\AbstractHelper;
6
7
class Product extends AbstractHelper
8
{
9
    protected $productUomService;
10
11
    public function __invoke()
12
    {
13
        return $this;
14
    }
15
16
    public function uomString($product)
17
    {
18
        if ($product->has('uoms')) {
19
            $svc = $this->getProductUomService();
20
            $uom = $svc->cheapestUom($product->getUoms());
21
            $svc->populate($uom);
22
            $moreThan1 = ($uom->getQuantity() > 1);
23
24
            $string = $uom->getUom()->getName();
25
            if ($moreThan1) {
26
                $string .= ' of ' . $uom->getQuantity();
27
            }
28
            return $string;
29
        }
30
        // @TODO: if there are builders, get the uomString from the one we are
31
        //displaying the price from
32
        return 'Starting At';
33
    }
34
35
36
37
    public function allUomsString($product, $string = true)
38
    {
39
        $uomStrings = array();
40
41
        if ($product->type() === 'product') {
42
            foreach ($uoms as $uom) {
0 ignored issues
show
Bug introduced by
The variable $uoms 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...
43
                $uomStrings[$this->uomStr($uom)] = $this->uomName($uom);
44
            }
45
        } elseif ($product->type() === 'shell') {
46
            foreach ($product->getBuilders() as $builder) {
47
                foreach ($builder->getProduct()->getUoms() as $uom) {
48
                    $uomStrings[$this->uomStr($uom)] = $this->uomName($uom);
49
                }
50
            }
51
        }
52
53
        if ($string) {
54
            return implode(',', $uomStrings);
55
        }
56
57
        return $uomStrings;
58
    }
59
60
    public function uomStr($uom)
61
    {
62
        return $uom->getUomCode() . $uom->getQuantity();
63
    }
64
65
    public function uomName($uom)
66
    {
67
        if ($uom->getQuantity() === 1) {
68
            return $uom->getUom()->getName();
69
        }
70
        return "{$uom->getUom()->getName()} of {$uom->getQuantity()}";
71
    }
72
73
    public function itemNumbers($product, $implode = false)
74
    {
75
        $numbers = array();
76
        if ($product->getProductTypeId() == 2) {
77
            $numbers[$product->getItemNumber()] = $product->getItemNumber();
78
        } else {
79
            foreach ($product->getBuilders() as $builder) {
80
                $bp = $builder->getProduct();
81
                $numbers[$bp->getItemNumber()] = $bp->getItemNumber();
82
            }
83
        }
84
        if ($implode) {
85
            return implode($implode, $numbers);
86
        }
87
        return $numbers;
88
    }
89
90
    public function getProductUomService()
91
    {
92
        return $this->productUomService;
93
    }
94
95
    public function setProductUomService($productUomService)
96
    {
97
        $this->productUomService = $productUomService;
98
        return $this;
99
    }
100
}
101