Completed
Push — master ( 137b9b...8d97a2 )
by Pol
03:29
created

Subset::addItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 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 6
  public function addItem(SubsetItem $item) {
21 6
    $this->items[] = $item;
22 6
  }
23
24
  /**
25
   * @param SubsetItem[] $items
26
   */
27 2
  public function addItems(array $items = array()) {
28 2
    foreach ($items as $item) {
29 2
      $this->addItem($item);
30 2
    }
31 2
  }
32
33
  /**
34
   * @return SubsetItem[]
35
   */
36 6
  public function getItems() {
37 6
    return (array) $this->items;
38
  }
39
40
  /**
41
   * @return array
42
   */
43 6
  public function getRawItems() {
44 6
    $data = array();
45
46 6
    foreach ($this->getItems() as $item) {
47 6
      $data[] = $item->getItem();
48 6
    }
49
50 6
    return $data;
51
  }
52
53
  /**
54
   * @return int
55
   */
56
  public function getWeight() {
57
    $sum = 0;
58
59
    foreach((array) $this->items as $item) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
60
      $sum += $item->getValue();
61
    }
62
63
    return $sum;
64
  }
65
66
  /**
67
   * @param \drupol\phpartition\BasePartitionAlgorithm $algo
68
   */
69 6
  public function setAlgo(BasePartitionAlgorithm $algo) {
70 6
    $this->algo = $algo;
71 6
  }
72
73
  /**
74
   * @return BasePartitionAlgorithm
75
   */
76 6
  public function getAlgo() {
77 6
    return $this->algo;
78
  }
79
80
}