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.

Esprima::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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\Validator;
10
11
use Symfony\Component\Config\FileLocatorInterface;
12
13
/**
14
 * PHP PhantomJs
15
 *
16
 * @author Jon Wenmoth <[email protected]>
17
 */
18
class Esprima implements EngineInterface
19
{
20
    /**
21
     * File locator
22
     *
23
     * @var \Symfony\Component\Config\FileLocatorInterface
24
     * @access protected
25
     */
26
    protected $locator;
27
28
    /**
29
     * Esprima file.
30
     *
31
     * @var string
32
     * @access protected
33
     */
34
    protected $file;
35
36
    /**
37
     * Esprima script.
38
     *
39
     * @var string
40
     * @access protected
41
     */
42
    protected $esprima;
43
44
    /**
45
     * Internal constructor.
46
     *
47
     * @access public
48
     * @param  \Symfony\Component\Config\FileLocatorInterface $locator
49
     * @param  string                                         $file
50
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
51
     */
52 10
    public function __construct($locator, $file)
53
    {
54 10
        $this->locator = $locator;
55 10
        $this->file    = $file;
56 10
    }
57
58
    /**
59
     * Returns engine as string.
60
     *
61
     * @access public
62
     * @return string
63
     */
64 18
    public function toString()
65
    {
66 18
        $this->load();
67
68 18
        return $this->esprima;
69
    }
70
71
    /**
72
     * To string magic method.
73
     *
74
     * @access public
75
     * @return string
76
     */
77 1
    public function __toString()
78
    {
79 1
        return $this->toString();
80
    }
81
82
    /**
83
     * Load esprima script.
84
     *
85
     * @access public
86
     * @return string
87
     */
88 21
    public function load()
89
    {
90 21
        if (!$this->esprima) {
91
92 10
            $this->esprima = $this->loadFile(
93 10
                $this->locator->locate($this->file)
0 ignored issues
show
Bug introduced by
It seems like $this->locator->locate($this->file) targeting Symfony\Component\Config...atorInterface::locate() can also be of type array; however, JonnyW\PhantomJs\Validator\Esprima::loadFile() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94 8
            );
95 8
        }
96
97 19
        return $this->esprima;
98
    }
99
100
    /**
101
     * Load procedure file content.
102
     *
103
     * @access protected
104
     * @param  string $file
105
     * @return string
106
     */
107 8
    protected function loadFile($file)
108
    {
109 8
        return file_get_contents($file);
110
    }
111
}
112