Completed
Push — master ( ca6e2c...137b9b )
by Pol
01:51
created

Subset   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 8
cbo 1
dl 0
loc 67
ccs 16
cts 22
cp 0.7272
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A addItem() 0 3 1
A getItems() 0 3 1
A setAlgo() 0 3 1
A getAlgo() 0 3 1
A getRawItems() 0 9 2
A getWeight() 0 9 2
1
<?php
2
3
namespace drupol\phpartition;
4
5
class Subset {
6
7
  /**
8
   * @var BasePartitionAlgorithm
9
   */
10
  protected $algo;
11
12
  /**
13
   * @var SubsetItem[]
14
   */
15
  protected $items;
16
17
  /**
18
   * @param \drupol\phpartition\SubsetItem $item
19
   */
20 4
  public function addItem(SubsetItem $item) {
21 4
    $this->items[] = $item;
22 4
  }
23
24
  /**
25
   * @return SubsetItem[]
26
   */
27 4
  public function getItems() {
28 4
    return (array) $this->items;
29
  }
30
31
  /**
32
   * @return array
33
   */
34 4
  public function getRawItems() {
35 4
    $data = array();
36
37 4
    foreach ($this->getItems() as $item) {
38 4
      $data[] = $item->getItem();
39 4
    }
40
41 4
    return $data;
42
  }
43
44
  /**
45
   * @return int
46
   */
47
  public function getWeight() {
48
    $sum = 0;
49
50
    foreach((array) $this->items as $item) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
51
      $sum += $item->getValue();
52
    }
53
54
    return $sum;
55
  }
56
57
  /**
58
   * @param \drupol\phpartition\BasePartitionAlgorithm $algo
59
   */
60 4
  public function setAlgo(BasePartitionAlgorithm $algo) {
61 4
    $this->algo = $algo;
62 4
  }
63
64
  /**
65
   * @return BasePartitionAlgorithm
66
   */
67 4
  public function getAlgo() {
68 4
    return $this->algo;
69
  }
70
71
}