Code Duplication    Length = 38-38 lines in 2 locations

Core/DefinitionParser/JsonDefinitionParser.php 1 location

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

Core/DefinitionParser/YamlDefinitionParser.php 1 location

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