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

MultiCsFileLoader::ensureFileExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.7462

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
ccs 3
cts 7
cp 0.4286
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2.7462
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