JsonFile   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 6
loc 28
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfiguration() 6 25 4

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\JsonNotValid;
10
use function assert;
11
use function file_exists;
12
use function file_get_contents;
13
use function json_decode;
14
use function json_last_error;
15
use const JSON_ERROR_NONE;
16
17
final class JsonFile extends ConfigurationFile
18
{
19 10
    public function getConfiguration() : Configuration
20
    {
21 10
        if (! file_exists($this->file)) {
22 1
            throw FileNotFound::new($this->file);
23
        }
24
25 9
        $contents = file_get_contents($this->file);
26
27 9
        assert($contents !== false);
28
29 9
        $config = json_decode($contents, true);
30
31 9
        if (json_last_error() !== JSON_ERROR_NONE) {
32 1
            throw JsonNotValid::new();
33
        }
34
35 8 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...
36 3
            $config['migrations_paths'] = $this->getDirectoriesRelativeToFile(
37 3
                $config['migrations_paths'],
38 3
                $this->file
39
            );
40
        }
41
42 8
        return (new ConfigurationArray($config))->getConfiguration();
43
    }
44
}
45