AddFieldHandler::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 10
cp 0.8
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 7
nop 1
crap 2.032
1
<?php
2
3
namespace Nayjest\Querying\Handler\PostProcess;
4
5
use Nayjest\Querying\Handler\AbstractHandler;
6
use Nayjest\Querying\Handler\Priority;
7
use Nayjest\Querying\Operation\AddFieldOperation;
8
use Nayjest\Querying\Row\RowInterface;
9
10
class AddFieldHandler extends AbstractHandler
11
{
12
    const PRIORITY = Priority::INITIALIZE_ROWS - 1;
13
14 1
    public function getPriority()
15
    {
16 1
        return self::PRIORITY;
17
    }
18
    /**
19
     * Applies operation to source and returns modified source.
20
     *
21
     */
22 1
    public function apply($dataSource)
23
    {
24
        /** @var AddFieldOperation $operation */
25 1
        $operation = $this->operation;
26 1
        foreach ($dataSource as $row) {
27
            /** @var RowInterface $row */
28 1
            $row->dynamicFieldsRegistry()->add(
29 1
                $operation->getFieldName(),
30 1
                $operation->getCallable()
31 1
            );
32 1
            return $dataSource;
33
        }
34
    }
35
}
36