Completed
Push — master ( 8c892e...6a431f )
by Pol
11:58
created

Subset::getWeight()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
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
  public function addItem(SubsetItem $item) {
21
    $this->items[] = $item;
22
  }
23
24
  /**
25
   * @return SubsetItem[]
26
   */
27
  public function getItems() {
28
    return (array) $this->items;
29
  }
30
31
  /**
32
   * @return array
33
   */
34
  public function getRawItems() {
35
    $data = array();
36
37
    foreach ($this->getItems() as $item) {
38
      $data[] = $item->getItem();
39
    }
40
41
    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
  public function setAlgo(BasePartitionAlgorithm $algo) {
61
    $this->algo = $algo;
62
  }
63
64
  /**
65
   * @return BasePartitionAlgorithm
66
   */
67
  public function getAlgo() {
68
    return $this->algo;
69
  }
70
71
}