MultiCsFileLoader::ensureFileExists()   A
last analyzed

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 0
Metric Value
dl 0
loc 12
ccs 3
cts 7
cp 0.4286
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2.7462
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\MultiCodingStandard\Configuration;
11
12
use Nette\Utils\Json;
13
use Symplify\MultiCodingStandard\Exception\Configuration\MultiCsFileNotFoundException;
14
15
final class MultiCsFileLoader
16
{
17
    /**
18
     * @var string
19
     */
20
    private $multiCsJsonFile;
21
22 1
    public function __construct(string $multiCsJsonFile = null)
23
    {
24 1
        $this->multiCsJsonFile = $multiCsJsonFile ?: getcwd().DIRECTORY_SEPARATOR.'multi-cs.json';
25 1
    }
26
27 1
    public function load() : array
28
    {
29 1
        $this->ensureFileExists($this->multiCsJsonFile);
30
31 1
        $fileContent = file_get_contents($this->multiCsJsonFile);
32
33 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...
34
    }
35
36 1
    private function ensureFileExists(string $multiCsJsonFile)
37
    {
38 1
        if (!file_exists($multiCsJsonFile)) {
39
            throw new MultiCsFileNotFoundException(
40
                sprintf(
41
                    'File "%s" was not found in "%s". Did you forget to create it?',
42
                    'multi-cs.json',
43
                    realpath(dirname($multiCsJsonFile)).'/'.basename($multiCsJsonFile)
44
                )
45
            );
46
        }
47 1
    }
48
}
49