Test Failed
Push — main ( fc8ba5...9083af )
by Bingo
05:27
created

DeploymentMappings   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 19
c 1
b 0
f 0
dl 0
loc 41
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOverallIdCount() 0 3 1
A get() 0 6 2
A of() 0 5 1
A remove() 0 8 2
A add() 0 5 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Batch;
4
5
class DeploymentMappings extends \ArrayObject
6
{
7
    protected $overallIdCount;
8
9
    public static function of(DeploymentMapping $mapping): DeploymentMappings
10
    {
11
        $mappings = new DeploymentMappings();
12
        $mappings->add($mapping);
13
        return $mappings;
14
    }
15
16
    public function add(DeploymentMapping $mapping): bool
17
    {
18
        $this->overallIdCount += $mapping->getCount();
19
        $this[] = $mapping;
20
        return true;
21
    }
22
23
    public function get(int $mappingIndex)
0 ignored issues
show
Unused Code introduced by
The parameter $mappingIndex is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function get(/** @scrutinizer ignore-unused */ int $mappingIndex)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        if (isset($this[$index])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $index seems to be never defined.
Loading history...
26
            return $this[$index];
27
        } else {
28
            throw new \Exception(sprintf("Undefined array key %d", $index));
29
        }
30
    }
31
32
    public function remove(int $mappingIndex): bool
33
    {
34
        if (isset($this[$mappingIndex])) {
35
            $this->overallIdCount -= $this[$mappingIndex]->getCount();
36
            unset($this[$mappingIndex]);
37
            return true;
38
        } else {
39
            return false;
40
        }
41
    }
42
43
    public function getOverallIdCount(): int
44
    {
45
        return $this->overallIdCount;
46
    }
47
}
48