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

IgnorableStepExecutorTrait::setReferenceMatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
}