Completed
Push — master ( c10b24...254ad5 )
by Nils
06:13
created

HeadlessChromeClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 18.42 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 3
dl 7
loc 38
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 7 10 2
A sendRequest() 0 4 1
A sendRequests() 0 4 1
A getClientType() 0 4 1
A close() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace whm\Smoke\Http;
4
5
use phm\HttpWebdriverClient\Http\Client\Decorator\FileCacheDecorator;
6
use phm\HttpWebdriverClient\Http\Client\Decorator\LoggerDecorator;
7
use phm\HttpWebdriverClient\Http\Client\HeadlessChrome\HeadlessChromeClient as HeadlessChrome;
8
use phm\HttpWebdriverClient\Http\Client\HttpClient;
9
use Psr\Http\Message\RequestInterface;
10
11
class HeadlessChromeClient implements HttpClient
12
{
13
    /**
14
     * @var HeadlessChrome
15
     */
16
    private $chromeClient;
17
18
    public function init($nocache = false)
19
    {
20 View Code Duplication
        if ($nocache) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
            $this->chromeClient = new HeadlessChrome();
22
        } else {
23
            $chromeClient = new HeadlessChrome();
24
            $cachedClient = new FileCacheDecorator($chromeClient);
25
            $this->chromeClient = new LoggerDecorator($cachedClient);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \phm\HttpWebdriverCl...ecorator($cachedClient) of type object<phm\HttpWebdriver...orator\LoggerDecorator> is incompatible with the declared type object<phm\HttpWebdriver...e\HeadlessChromeClient> of property $chromeClient.

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...
26
        }
27
    }
28
29
    public function sendRequest(RequestInterface $request)
30
    {
31
        return $this->chromeClient->sendRequest($request);
32
    }
33
34
    public function sendRequests(array $requests)
35
    {
36
        return $this->chromeClient->sendRequests($requests);
37
    }
38
39
    public function getClientType()
40
    {
41
        return $this->chromeClient->getClientType();
42
    }
43
44
    public function close()
45
    {
46
        $this->chromeClient->close();
47
    }
48
}
49