Code Duplication    Length = 38-38 lines in 2 locations

Core/DefinitionParser/JsonDefinitionParser.php 1 location

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

Core/DefinitionParser/YamlDefinitionParser.php 1 location

@@ 12-49 (lines=38) @@
9
/**
10
 * Handles Yaml migration definitions.
11
 */
12
class YamlDefinitionParser extends AbstractDefinitionParser implements DefinitionParserInterface
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