Completed
Pull Request — master (#60)
by Matthijs
05:08
created

GuzzleTimerMiddleware::onRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace Example;
3
4
use GuzzleHttp\Promise\FulfilledPromise;
5
use Psr\Http\Message\RequestInterface;
6
7
class GuzzleTimerMiddleware
8
{
9
    private $total = 0;
10
11
    private $start = 0;
12
13
    public function onRequest(RequestInterface $request, array $options)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
    {
15
        $this->start = microtime(true);
0 ignored issues
show
Documentation Bug introduced by
The property $start was declared of type integer, but microtime(true) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
16
    }
17
18
    public function onResponse(RequestInterface $request, array $options, FulfilledPromise $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20
        $duration = microtime(true) - $this->start;
21
        $this->total = $this->total + $duration;
0 ignored issues
show
Documentation Bug introduced by
The property $total was declared of type integer, but $this->total + $duration is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
22
    }
23
24
    public function getTotal()
25
    {
26
        return round($this->total, 2);
27
    }
28
}
29