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.
Completed
Push — 5.0 ( c6890e )
by Jonny
23:29
created

Client::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
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
10
namespace JonnyW\PhantomJs;
11
12
use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface;
13
use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface;
14
use JonnyW\PhantomJs\IO\InputInterface;
15
use JonnyW\PhantomJs\IO\OutputInterface;
16
17
/**
18
 * PHP PhantomJs.
19
 *
20
 * @author Jon Wenmoth <[email protected]>
21
 */
22
class Client implements ClientInterface
23
{
24
    /**
25
     * Client.
26
     *
27
     * @var \JonnyW\PhantomJs\Client\ClientInterface
28
     */
29
    protected static $instance;
30
31
    /**
32
     * PhantomJs engine.
33
     *
34
     * @var \JonnyW\PhantomJs\Engine
35
     */
36
    protected $engine;
37
38
    /**
39
     * Procedure loader.
40
     *
41
     * @var \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
42
     */
43
    protected $procedureLoader;
44
45
    /**
46
     * Procedure validator.
47
     *
48
     * @var \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
49
     */
50
    protected $procedureCompiler;
51
52
    /**
53
     * Procedure template.
54
     *
55
     * @var string
56
     */
57
    protected $procedure;
58
59
    /**
60
     * Internal constructor.
61
     *
62
     * @param \JonnyW\PhantomJs\Engine                               $engine
63
     * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface   $procedureLoader
64
     * @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
65
     */
66
    public function __construct(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler)
67
    {
68
        $this->engine = $engine;
69
        $this->procedureLoader = $procedureLoader;
70
        $this->procedureCompiler = $procedureCompiler;
71
        $this->procedure = 'default';
72
    }
73
74
    /**
75
     * Get singleton instance.
76
     *
77
     * @return \JonnyW\PhantomJs\Client\ClientInterface
78
     */
79
    public static function getInstance()
80
    {
81
        if (!self::$instance instanceof ClientInterface) {
82
            $serviceContainer = ServiceContainer::getInstance();
83
84
            self::$instance = new static(
0 ignored issues
show
Documentation Bug introduced by
It seems like new static($serviceConta...('procedure_compiler')) of type this<JonnyW\PhantomJs\Client> is incompatible with the declared type object<JonnyW\PhantomJs\Client\ClientInterface> of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
                $serviceContainer->get('engine'),
86
                $serviceContainer->get('procedure_loader'),
87
                $serviceContainer->get('procedure_compiler')
88
            );
89
        }
90
91
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return self::$instance; (JonnyW\PhantomJs\Client) is incompatible with the return type declared by the interface JonnyW\PhantomJs\ClientInterface::getInstance of type JonnyW\PhantomJs\Client\ClientInterface.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
92
    }
93
94
    /**
95
     * Run client.
96
     *
97
     * @param \JonnyW\PhantomJs\IO\InputInterface  $input
98
     * @param \JonnyW\PhantomJs\IO\OutputInterface $output
99
     *
100
     * @return \JonnyW\PhantomJs\IO\OutputInterface
101
     */
102
    public function run(InputInterface $input, OutputInterface $output)
103
    {
104
        $procedure = $this->procedureLoader->load($this->procedure);
105
106
        $this->procedureCompiler->compile($procedure, $input);
0 ignored issues
show
Bug introduced by
The call to compile() misses a required argument $output.

This check looks for function calls that miss required arguments.

Loading history...
107
108
        $procedure->run($input, $output);
0 ignored issues
show
Documentation introduced by
$input is of type object<JonnyW\PhantomJs\IO\InputInterface>, but the function expects a object<JonnyW\PhantomJs\Procedure\InputInterface>.

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...
Documentation introduced by
$output is of type object<JonnyW\PhantomJs\IO\OutputInterface>, but the function expects a object<JonnyW\PhantomJs\...cedure\OutputInterface>.

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...
109
110
        return $output;
111
    }
112
113
    /**
114
     * Get PhantomJs engine.
115
     *
116
     * @return \JonnyW\PhantomJs\Engine
117
     */
118
    public function getEngine()
119
    {
120
        return $this->engine;
121
    }
122
123
    /**
124
     * Get procedure loader instance.
125
     *
126
     * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
127
     */
128
    public function getProcedureLoader()
129
    {
130
        return $this->procedureLoader;
131
    }
132
133
    /**
134
     * Get procedure compiler.
135
     *
136
     * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
137
     */
138
    public function getProcedureCompiler()
139
    {
140
        return $this->procedureCompiler;
141
    }
142
143
    /**
144
     * Set procedure template.
145
     *
146
     * @param string $procedure
147
     */
148
    public function setProcedure($procedure)
149
    {
150
        $this->procedure = $procedure;
151
    }
152
153
    /**
154
     * Get procedure template.
155
     *
156
     * @return string
157
     */
158
    public function getProcedure()
159
    {
160
        return $this->procedure;
161
    }
162
163
    /**
164
     * Get log.
165
     *
166
     * @return string
167
     */
168
    public function getLog()
169
    {
170
        return $this->getEngine()->getLog();
171
    }
172
}
173