GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ProcedureLoader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 85
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4
ccs 19
cts 19
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 9 1
A loadTemplate() 0 6 1
A loadFile() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the php-phantomjs.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
namespace JonnyW\PhantomJs\Procedure;
10
11
use Symfony\Component\Config\FileLocatorInterface;
12
use JonnyW\PhantomJs\Exception\NotExistsException;
13
14
/**
15
 * PHP PhantomJs
16
 *
17
 * @author Jon Wenmoth <[email protected]>
18
 */
19
class ProcedureLoader implements ProcedureLoaderInterface
20
{
21
    /**
22
     * Procedure factory.
23
     *
24
     * @var \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface
25
     * @access protected
26
     */
27
    protected $procedureFactory;
28
29
    /**
30
     * File locator.
31
     *
32
     * @var \Symfony\Component\Config\FileLocatorInterface
33
     * @access protected
34
     */
35
    protected $locator;
36
37
    /**
38
     * Internal constructor.
39
     *
40
     * @access public
41
     * @param \JonnyW\PhantomJs\Procedure\ProcedureFactoryInterface $procedureFactory
42
     * @param \Symfony\Component\Config\FileLocatorInterface        $locator
43
     */
44 9
    public function __construct(ProcedureFactoryInterface $procedureFactory, FileLocatorInterface $locator)
45
    {
46 9
        $this->procedureFactory = $procedureFactory;
47 9
        $this->locator          = $locator;
48 9
    }
49
50
    /**
51
     * Load procedure instance by id.
52
     *
53
     * @access public
54
     * @param  string                                         $id
55
     * @return \JonnyW\PhantomJs\Procedure\ProcedureInterface
56
     */
57 51
    public function load($id)
58
    {
59 51
        $procedure = $this->procedureFactory->createProcedure();
60 51
        $procedure->setTemplate(
61 51
            $this->loadTemplate($id)
62 49
        );
63
64 49
        return $procedure;
65
    }
66
67
    /**
68
     * Load procedure template by id.
69
     *
70
     * @access public
71
     * @param  string $id
72
     * @param  string $extension (default: 'proc')
73
     * @return string
74
     */
75 52
    public function loadTemplate($id, $extension = 'proc')
76
    {
77 52
        $path = $this->locator->locate(sprintf('%s.%s', $id, $extension));
78
79 52
        return $this->loadFile($path);
0 ignored issues
show
Bug introduced by
It seems like $path defined by $this->locator->locate(s....%s', $id, $extension)) on line 77 can also be of type array; however, JonnyW\PhantomJs\Procedu...edureLoader::loadFile() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
80
    }
81
82
    /**
83
     * Load procedure file content.
84
     *
85
     * @access protected
86
     * @param  string                                         $file
87
     * @return string
88
     * @throws \InvalidArgumentException
89
     * @throws \JonnyW\PhantomJs\Exception\NotExistsException
90
     */
91 52
    protected function loadFile($file)
92
    {
93 52
        if (!stream_is_local($file)) {
94 1
            throw new \InvalidArgumentException(sprintf('Procedure file is not a local file: "%s"', $file));
95
        }
96
97 51
        if (!file_exists($file)) {
98 1
            throw new NotExistsException(sprintf('Procedure file does not exist: "%s"', $file));
99
        }
100
101 50
        return file_get_contents($file);
102
    }
103
}
104