Test Failed
Pull Request — master (#10)
by Yo
02:33
created

ConfigurationLoader::fromPath()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 19
cts 19
cp 1
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 1
crap 2
1
<?php
2
namespace Yoanm\ComposerConfigManager\Infrastructure\Loader;
3
4
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
5
use Symfony\Component\Finder\Finder;
6
use Symfony\Component\Finder\SplFileInfo;
7
use Symfony\Component\Serializer\SerializerInterface;
8
use Yoanm\ComposerConfigManager\Application\Loader\ConfigurationLoaderInterface;
9
use Yoanm\ComposerConfigManager\Domain\Model\Configuration;
10
use Yoanm\ComposerConfigManager\Infrastructure\Serializer\Encoder\ComposerEncoder;
11
use Yoanm\ComposerConfigManager\Infrastructure\Writer\ConfigurationWriter;
12
13
class ConfigurationLoader implements ConfigurationLoaderInterface
14
{
15
    /** @var Finder */
16
    private $finder;
17
    /** @var SerializerInterface */
18
    private $serializer;
19
20 2
    public function __construct(Finder $finder, SerializerInterface $serializer)
21
    {
22 2
        $this->finder = $finder;
23 2
        $this->serializer = $serializer;
24 2
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function fromPath($path)
30
    {
31
        /** @var SplFileInfo|null $file */
32 2
        $file = null;
0 ignored issues
show
Unused Code introduced by
$file is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33 2
        $finder = $this->finder
34 2
            ->in($path)
35 2
            ->files()
36 2
            ->name(ConfigurationWriter::FILENAME)
37 2
            ->depth(0);
38
39 2
        $file = $finder->getIterator()->current();
40
41 2
        if (null === $file) {
42 1
            throw new FileNotFoundException(
43 1
                null,
44 1
                0,
45 1
                null,
46 1
                sprintf(
47 1
                    'File %s not found in %s',
48 1
                    ConfigurationWriter::FILENAME,
49
                    $path
50 1
                )
51 1
            );
52
        }
53
54 1
        return $this->serializer->deserialize($file->getContents(), Configuration::class, ComposerEncoder::FORMAT);
55
    }
56
}
57