Completed
Pull Request — master (#10)
by Tomáš
31:42
created

MultiCsFileLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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\Exception\Configuration\MultiCsFileNotFoundException;
12
13
final class MultiCsFileLoader
14
{
15
    /**
16
     * @var string
17
     */
18
    private $multiCsJsonFile;
19
20 1
    public function __construct(string $multiCsJsonFile)
21
    {
22 1
        $this->multiCsJsonFile = $multiCsJsonFile;
23 1
    }
24
25 1
    public function load() : array
26
    {
27 1
        $this->ensureFileExists($this->multiCsJsonFile);
28
        
29 1
        $fileContent = file_get_contents($this->multiCsJsonFile);
30 1
        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...
31
    }
32
33 1
    private function ensureFileExists(string $multiCsJsonFile)
34
    {
35 1
        if (!file_exists($multiCsJsonFile)) {
36
            throw new MultiCsFileNotFoundException(
37
                sprintf(
38
                    'File "%s" was not found in "%s". Did you forget to create it?',
39
                    'multi-cs.json',
40
                    realpath(dirname($multiCsJsonFile)).'/'.basename($multiCsJsonFile)
41
                )
42
            );
43
        }
44 1
    }
45
}
46