Passed
Push — master ( 0692ec...4950c9 )
by Sebastian
02:38 queued 11s
created

Operations::countMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mistralys\WidthsCalculator\Calculator\Operations} class.
4
 *
5
 * @package WidthsCalculator
6
 * @see Mistralys\WidthsCalculator\Calculator\Operations
7
 */
8
9
declare (strict_types=1);
10
11
namespace Mistralys\WidthsCalculator\Calculator;
12
13
use Mistralys\WidthsCalculator\Calculator;
14
15
/**
16
 * Central source for shared calculation routines used
17
 * by all subclasses.
18
 *
19
 * @package WidthsCalculator
20
 * @author Sebastian Mordziol <[email protected]>
21
 */
22
class Operations
23
{
24
    /**
25
     * @var Calculator
26
     */
27
    private $calculator;
28
29
    /**
30
     * @var integer
31
     */
32
    private $amountCols = 0;
33
    
34
    /**
35
     * @var integer
36
     */
37
    private $missing = 0;
38
    
39
   /**
40
    * @var Column[]
41
    */
42
    private $columns = array();
43
    
44
    public function __construct(Calculator $calculator)
45
    {
46
        $this->calculator = $calculator;
47
        $this->columns = $calculator->getColumns();
48
        $this->amountCols = count($this->columns);
49
        
50
        foreach($this->columns as $col)
51
        {
52
            if($col->isMissing())
53
            {
54
                $this->missing++;
55
            }
56
        }
57
    }
58
59
    public function calcTotal() : float
60
    {
61
        $total = 0;
62
        
63
        foreach($this->columns as $col)
64
        {
65
            $total += $col->getValue();
66
        }
67
        
68
        return $total;
69
    }
70
    
71
    public function countColumns() : int
72
    {
73
        return $this->amountCols;
74
    }
75
    
76
    public function countMissing() : int
77
    {
78
        return $this->missing;
79
    }
80
    
81
    public function calcTotalNotMissing() : float
82
    {
83
        $total = 0;
84
        
85
        foreach($this->columns as $col)
86
        {
87
            if(!$col->isMissing())
88
            {
89
                $total += $col->getValue();
90
            }
91
        }
92
        
93
        return $total;
94
    }
95
    
96
}
97