Passed
Pull Request — master (#2)
by Pol
03:09
created

Partition::exportArrayCopy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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