Get::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oliverde8\Component\RuleEngine\Rules;
6
7
use oliverde8\AssociativeArraySimplified\AssociativeArray;
8
9
/**
10
 * Class Get
11
 *
12
 * @author    de Cramer Oliver<[email protected]>
13
 * @copyright 2018 Oliverde8
14
 * @package Oliverde8\Component\RuleEngine\Rules
15
 */
16
class Get extends AbstractRule
17
{
18
    /**
19 2
     * @inheritdoc
20
     */
21 2
    public function apply(array $rowData, array &$transformedData, array $options = [])
22 2
    {
23
        if (!is_array($options['field'])) {
24
            $options['field'] = [$options['field']];
25 2
        }
26 2
27 2
        $fields = [];
28
        foreach ($options['field'] as $field) {
29
            $fields[] = AssociativeArray::getFromKey($rowData, '@column.' . $field, $field, '.');
30 2
        }
31
32
        return AssociativeArray::getFromKey($rowData, $fields);
33
    }
34
35
    /**
36 2
     * @inheritdoc
37
     */
38 2
    public function validate(array $options): void
39 2
    {
40
        $this->requireOption('field', $options);
41
    }
42
43
    /**
44 1
     * @inheritdoc
45
     */
46 1
    public function getRuleCode(): string
47
    {
48
        return 'get';
49
    }
50
}
51