EndPointResponseListenerTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 35
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A callResponseListeners() 0 5 2
A onResponse() 0 6 1
1
<?php
2
3
namespace Parroauth2\Client\EndPoint;
4
5
/**
6
 * Add response listener handling on endpoint
7
 *
8
 * @template T as object
9
 */
10
trait EndPointResponseListenerTrait
11
{
12
    /**
13
     * @var list<callable(T):void>
0 ignored issues
show
Bug introduced by
The type Parroauth2\Client\EndPoint\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
     * @readonly
15
     */
16
    private $responseListeners = [];
17
18
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @param callable(T):void $listener
23
     *
24
     * @return static
25
     * @psalm-mutation-free
26
     */
27 11
    public function onResponse(callable $listener): CallableEndPointInterface
28
    {
29 11
        $endpoint = clone $this;
30 11
        $endpoint->responseListeners[] = $listener;
31
32 11
        return $endpoint;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $endpoint returns the type Parroauth2\Client\EndPoi...ntResponseListenerTrait which is incompatible with the type-hinted return Parroauth2\Client\EndPoi...llableEndPointInterface.
Loading history...
33
    }
34
35
    /**
36
     * Call all response listeners
37
     *
38
     * @param T $response
39
     */
40 47
    protected function callResponseListeners($response): void
41
    {
42 47
        foreach ($this->responseListeners as $listener) {
43
            /** @psalm-suppress ArgumentTypeCoercion */
44 11
            $listener($response);
45
        }
46 46
    }
47
}
48