Passed
Branch php-scrutinizer (9ddcba)
by Jens
09:45
created

TokenSubscriber::onBefore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Helper\Subscriber;
7
8
use Commercetools\Core\Client\OAuth\TokenProvider;
9
use GuzzleHttp\Event\BeforeEvent;
1 ignored issue
show
Bug introduced by
The type GuzzleHttp\Event\BeforeEvent 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...
10
use GuzzleHttp\Event\RequestEvents;
1 ignored issue
show
Bug introduced by
The type GuzzleHttp\Event\RequestEvents 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...
11
use GuzzleHttp\Event\SubscriberInterface;
1 ignored issue
show
Bug introduced by
The type GuzzleHttp\Event\SubscriberInterface 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...
12
13
class TokenSubscriber implements SubscriberInterface
14
{
15
    /**
16
     * @var TokenProvider
17
     */
18
    private $provider;
19
20
    public function __construct(TokenProvider $provider)
21
    {
22
        $this->provider = $provider;
23
    }
24
25
    public function getEvents()
26
    {
27
        return ['before' => ['onBefore', RequestEvents::PREPARE_REQUEST - 15]];
28
    }
29
30
    public function onBefore(BeforeEvent $event, $name)
31
    {
32
        $event->getRequest()->addHeader('Authorization', 'Bearer ' . $this->provider->getToken()->getToken());
33
    }
34
}
35