Completed
Push — master ( f808f4...fba7cb )
by Tomáš
07:11 queued 04:32
created

MultiCsFileLoader::ensureFileExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 3
cts 6
cp 0.5
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2.5
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\MultiCodingStandard\Configuration;
9
10
use Nette\Utils\Json;
11
use Symplify\MultiCodingStandard\Contract\Configuration\MultiCsFileLoaderInterface;
12
use Symplify\MultiCodingStandard\Exception\Configuration\MultiCsFileNotFoundException;
13
14
final class MultiCsFileLoader implements MultiCsFileLoaderInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    private $multiCsJsonFile;
20
21
    /**
22
     * @param string $multiCsJsonFile
23
     */
24 11
    public function __construct($multiCsJsonFile)
25
    {
26 11
        $this->multiCsJsonFile = $multiCsJsonFile;
27 11
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 11
    public function load()
33
    {
34 11
        $this->ensureFileExists($this->multiCsJsonFile);
35
        
36 11
        $fileContent = file_get_contents($this->multiCsJsonFile);
37 11
        return Json::decode($fileContent, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
    }
39
40
    /**
41
     * @param string $multiCsJsonFile
42
     */
43 11
    private function ensureFileExists($multiCsJsonFile)
44
    {
45 11
        if (!file_exists($multiCsJsonFile)) {
46
            throw new MultiCsFileNotFoundException(
47
                sprintf(
48
                    'File "multi-cs.json" was not found in "%s". Did you forget to create it?',
49
                    realpath(dirname($multiCsJsonFile)).'/'.basename($multiCsJsonFile)
50
                )
51
            );
52
        }
53 11
    }
54
}
55