Completed
Pull Request — master (#1005)
by Asmir
06:55
created

YamlFile   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 6
loc 36
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfiguration() 6 33 6

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
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\Migration;
6
7
use Doctrine\Migrations\Configuration\Configuration;
8
use Doctrine\Migrations\Configuration\Exception\FileNotFound;
9
use Doctrine\Migrations\Configuration\Migration\Exception\YamlNotAvailable;
10
use Doctrine\Migrations\Configuration\Migration\Exception\YamlNotValid;
11
use Symfony\Component\Yaml\Exception\ParseException;
12
use Symfony\Component\Yaml\Yaml;
13
use function assert;
14
use function class_exists;
15
use function file_exists;
16
use function file_get_contents;
17
use function is_array;
18
19
final class YamlFile extends ConfigurationFile
20
{
21 11
    public function getConfiguration() : Configuration
22
    {
23 11
        if (! class_exists(Yaml::class)) {
24
            throw YamlNotAvailable::new();
25
        }
26
27 11
        if (! file_exists($this->file)) {
28 1
            throw FileNotFound::new($this->file);
29
        }
30
31 10
        $content = file_get_contents($this->file);
32
33 10
        assert($content !== false);
34
35
        try {
36 10
            $config = Yaml::parse($content);
37 1
        } catch (ParseException $e) {
38 1
            throw YamlNotValid::malformed();
39
        }
40
41 9
        if (! is_array($config)) {
42
            throw YamlNotValid::invalid();
43
        }
44
45 9 View Code Duplication
        if (isset($config['migrations_paths'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
46 4
            $config['migrations_paths'] = $this->getDirectoriesRelativeToFile(
47 4
                $config['migrations_paths'],
48 4
                $this->file
49
            );
50
        }
51
52 9
        return (new ConfigurationArray($config))->getConfiguration();
53
    }
54
}
55