Completed
Push — master ( 35235e...bb4db2 )
by Greg
01:14
created

FilterHooks   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A filterOutput() 0 12 2
1
<?php
2
3
namespace Consolidation\Filter\Hooks;
4
5
use Consolidation\AnnotatedCommand\CommandData;
6
use Consolidation\Filter\LogicalOpFactory;
7
use Consolidation\Filter\FilterOutputData;
8
use Symfony\Component\Yaml\Yaml;
9
10
class FilterHooks
11
{
12
    /**
13
     * @hook alter @filter-output
14
     * @option $filter Filter output based on provided expression
15
     * @default $filter ''
16
     */
17
    public function filterOutput($result, CommandData $commandData)
18
    {
19
        $expr = $commandData->input()->getOption('filter');
20
        if (!empty($expr)) {
21
            $factory = LogicalOpFactory::get();
22
            $op = $factory->evaluate($expr);
23
            $filter = new FilterOutputData();
24
            $result = $filter->filter($result, $op);
25
        }
26
27
        return $result;
28
    }
29
}
30