Completed
Push — master ( 1ee05e...99144a )
by Gaetano
05:13
created

YamlDefinitionParser::parseMigrationDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 17
loc 17
c 0
b 0
f 0
ccs 0
cts 11
cp 0
rs 9.7
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\DefinitionParser;
4
5
use Kaliop\eZMigrationBundle\API\DefinitionParserInterface;
6
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
7
use Symfony\Component\Yaml\Yaml;
8
9
/**
10
 * Handles Yaml migration definitions.
11
 */
12 View Code Duplication
class YamlDefinitionParser extends AbstractDefinitionParser implements DefinitionParserInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * Tells whether the given file can be handled by this handler, by checking e.g. the suffix
16
     *
17
     * @param string $migrationName typically a filename
18
     * @return bool
19
     */
20
    public function supports($migrationName)
21
    {
22
        $ext = pathinfo($migrationName, PATHINFO_EXTENSION);
23
        return  $ext == 'yml' || $ext == 'yaml';
24
    }
25
26
    /**
27
     * Parses a migration definition file, and returns the list of actions to take
28
     *
29
     * @param MigrationDefinition $definition
30
     * @return MigrationDefinition
31
     */
32
    public function parseMigrationDefinition(MigrationDefinition $definition)
33
    {
34
        try {
35
            $data = Yaml::parse($definition->rawDefinition);
36
        } catch (\Exception $e) {
37
            return new MigrationDefinition(
38
                $definition->name,
39
                $definition->path,
40
                $definition->rawDefinition,
41
                MigrationDefinition::STATUS_INVALID,
42
                array(),
43
                $e->getMessage()
44
            );
45
        }
46
47
        return $this->parseMigrationDefinitionData($data, $definition);
48
    }
49
}
50