YamlDefinitionParser::supports()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Kaliop\eZWorkflowEngineBundle\Core\DefinitionParser;
4
5
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
6
use Kaliop\eZMigrationBundle\API\DefinitionParserInterface;
7
use Kaliop\eZWorkflowEngineBundle\API\Value\WorkflowDefinition;
8
use Symfony\Component\Yaml\Yaml;
9
10
class YamlDefinitionParser extends AbstractDefinitionParser implements DefinitionParserInterface
11
{
12
    /**
13
     * Tells whether the given file can be handled by this handler, by checking e.g. the suffix
14
     *
15
     * @param string $migrationName typically a filename
16
     * @return bool
17
     */
18
    public function supports($migrationName)
19
    {
20
        $ext = pathinfo($migrationName, PATHINFO_EXTENSION);
21
        return  $ext == 'yml' || $ext == 'yaml';
22
    }
23
24
    /**
25
     * Parses a workflow definition file, and returns the list of actions to take
26
     *
27
     * @param MigrationDefinition $definition
28
     * @return WorkflowDefinition
29
     */
30
    public function parseMigrationDefinition(MigrationDefinition $definition)
31
    {
32
        try {
33
            $data = Yaml::parse($definition->rawDefinition);
34
        } catch (\Exception $e) {
35
            return new WorkflowDefinition(
36
                $definition->name,
37
                $definition->path,
38
                $definition->rawDefinition,
39
                MigrationDefinition::STATUS_INVALID,
40
                array(),
41
                $e->getMessage()
42
            );
43
        }
44
45
        return $this->parseMigrationDefinitionData($data, $definition);
46
    }
47
}