Completed
Push — master ( 2369b9...396de1 )
by Nils
02:11
created

CliReporter::getRequestString()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
1
<?php
2
3
namespace whm\Smoke\Extensions\SmokeReporter\Reporter;
4
5
use phm\HttpWebdriverClient\Http\Request\DeviceAwareRequest;
6
use phm\HttpWebdriverClient\Http\Request\ViewportAwareRequest;
7
use phm\HttpWebdriverClient\Http\Response\RequestAwareResponse;
8
use Psr\Http\Message\ResponseInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use whm\Smoke\Extensions\SmokeResponseRetriever\Retriever\Retriever;
11
use whm\Smoke\Rules\CheckResult;
12
13
abstract class CliReporter implements Reporter
14
{
15
    /**
16
     * @var OutputInterface
17
     */
18
    protected $output;
19
20
    /**
21
     * @var Retriever
22
     */
23
    protected $retriever;
24
25
    public function setResponseRetriever(Retriever $retriever)
26
    {
27
        $this->retriever = $retriever;
28
    }
29
30
    protected function setOutputInterface(OutputInterface $output)
31
    {
32
        $this->output = $output;
33
    }
34
35
    private function getRequestString(ResponseInterface $response)
36
    {
37
        if ($response instanceof RequestAwareResponse) {
0 ignored issues
show
Bug introduced by
The class phm\HttpWebdriverClient\...se\RequestAwareResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
38
            $request = $response->getRequest();
39
            if ($request instanceof DeviceAwareRequest) {
0 ignored issues
show
Bug introduced by
The class phm\HttpWebdriverClient\...uest\DeviceAwareRequest does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
40
                return ' (Device: ' . $request->getDevice()->getName() . ')';
41
            } else if ($request instanceof ViewportAwareRequest) {
0 ignored issues
show
Bug introduced by
The class phm\HttpWebdriverClient\...st\ViewportAwareRequest does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
42
                $viewport = $request->getViewport();
43
                return ' (Viewport: width: ' . $viewport->getWidth() . ', height: ' . $viewport->getHeight() . ')';
44
            }
45
        }
46
47
        return '';
48
    }
49
50
    protected function renderFailure(CheckResult $result)
51
    {
52
        $this->output->writeln('   <error> ' . (string)$result->getResponse()->getUri() . $this->getRequestString($result->getResponse()) . ' </error> coming from ' . (string)$this->retriever->getComingFrom($result->getResponse()->getUri()));
53
        $this->output->writeln('    - ' . $result->getMessage() . ' [rule: ' . $result->getRuleName() . ']');
54
        $this->output->writeln('');
55
    }
56
57
    protected function renderSuccess(CheckResult $result)
58
    {
59
        $this->output->writeln('   <info> ' . (string)$result->getResponse()->getUri() . $this->getRequestString($result->getResponse()) . ' </info> all tests passed');
60
    }
61
62
    protected function renderSkipped(CheckResult $result)
63
    {
64
        $this->output->writeln('   <comment> ' . (string)$result->getResponse()->getUri() . $this->getRequestString($result->getResponse()) . ' </comment>test skipped');
65
        $this->output->writeln('    - ' . $result->getMessage() . ' [rule: ' . $result->getRuleName() . ']');
66
    }
67
}
68