Completed
Push — master ( 0d7df6...af5d39 )
by Gaetano
08:38
created

IgnorableStepExecutorTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setReferenceMatcher() 0 4 1
A skipStepIfNeeded() 0 8 3
A matchConditions() 0 5 1
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\Executor;
4
5
use Kaliop\eZMigrationBundle\API\Value\MigrationStep;
6
use Kaliop\eZMigrationBundle\API\Exception\MigrationStepSkippedException;
7
8
trait IgnorableStepExecutorTrait
9
{
10
    protected $referenceMatcher;
11
12
    public function setReferenceMatcher($referenceMatcher)
13
    {
14
        $this->referenceMatcher = $referenceMatcher;
15
    }
16
17
    /**
18
     * @param MigrationStep $step
19
     * @return void
20
     * @throws MigrationStepSkippedException
21
     */
22
    protected function skipStepIfNeeded(MigrationStep $step)
23
    {
24
        if (isset($step->dsl['if'])) {
25
            if (!$this->matchConditions($step->dsl['if'])) {
26
                throw new MigrationStepSkippedException();
27
            }
28
        }
29
    }
30
31
    protected function matchConditions($conditions)
32
    {
33
        $match = $this->referenceMatcher->match($conditions);
34
        return reset($match);
35
    }
36
37
}