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

YamlDefinitionParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 38
loc 38
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 5 5 2
A parseMigrationDefinition() 17 17 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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