Passed
Pull Request — master (#2)
by Pol
05:29
created

Partition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exportArrayCopy() 0 7 1
A getWeight() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpartition\Partition;
6
7
use drupol\phpartition\Contract\Valuable;
8
use drupol\phpartition\Contract\Weightable;
9
10
/**
11
 * Class Partition.
12
 */
13
class Partition extends \ArrayObject implements Weightable
14
{
15
    /**
16
     * @return array
17
     */
18
    public function exportArrayCopy()
19
    {
20
        return \array_map(
21
            static function (Valuable $item) {
22
                return $item->getValue();
23
            },
24
            $this->getArrayCopy()
25
        );
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getWeight(): float
32
    {
33
        $weight = 0;
34
35
        foreach ($this as $item) {
36
            $weight += $item->getWeight();
37
        }
38
39
        return $weight;
40
    }
41
}
42