Test Setup Failed
Push — master ( 717f23...417174 )
by Arkadiusz
02:44 queued 26s
created

ColumnFilter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phpml\Preprocessing;
6
7
final class ColumnFilter implements Preprocessor
8
{
9
    /**
10
     * @var string[]
11
     */
12
    private $datasetColumns = [];
13
14
    /**
15
     * @var string[]
16
     */
17
    private $filterColumns = [];
18
19
    public function __construct(array $datasetColumns, array $filterColumns)
20
    {
21
        $this->datasetColumns = array_map(static function (string $column): string {
22
            return $column;
23
        }, $datasetColumns);
24
        $this->filterColumns = array_map(static function (string $column): string {
25
            return $column;
26
        }, $filterColumns);
27
    }
28
29
    public function fit(array $samples, ?array $targets = null): void
30
    {
31
        //nothing to do
32
    }
33
34
    public function transform(array &$samples, ?array &$targets = null): void
35
    {
36
        $keys = array_intersect($this->datasetColumns, $this->filterColumns);
37
38
        foreach ($samples as &$sample) {
39
            $sample = array_values(array_intersect_key($sample, $keys));
40
        }
41
    }
42
}
43