Operations   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A calcTotalNotMissing() 0 13 3
A __construct() 0 10 3
A countColumns() 0 3 1
A calcTotal() 0 10 2
A countMissing() 0 3 1
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
    private int $amountCols;
25
    private int $missing = 0;
26
    
27
   /**
28
    * @var Column[]
29
    */
30
    private array $columns;
31
    
32
    public function __construct(Calculator $calculator)
33
    {
34
        $this->columns = $calculator->getColumns();
35
        $this->amountCols = count($this->columns);
36
        
37
        foreach($this->columns as $col)
38
        {
39
            if($col->isMissing())
40
            {
41
                $this->missing++;
42
            }
43
        }
44
    }
45
46
    public function calcTotal() : float
47
    {
48
        $total = 0;
49
        
50
        foreach($this->columns as $col)
51
        {
52
            $total += $col->getValue();
53
        }
54
        
55
        return $total;
56
    }
57
    
58
    public function countColumns() : int
59
    {
60
        return $this->amountCols;
61
    }
62
    
63
    public function countMissing() : int
64
    {
65
        return $this->missing;
66
    }
67
    
68
    public function calcTotalNotMissing() : float
69
    {
70
        $total = 0;
71
        
72
        foreach($this->columns as $col)
73
        {
74
            if(!$col->isMissing())
75
            {
76
                $total += $col->getValue();
77
            }
78
        }
79
        
80
        return $total;
81
    }
82
}
83