AuthenticationMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * This file is part of PHP CS Fixer.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *     Dariusz Rumiński <[email protected]>
8
 *
9
 * This source file is subject to the MIT license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Etrias\EwarehousingConnector\Client\Middleware;
14
15
use Etrias\EwarehousingConnector\Services\AuthenticationService;
16
use Etrias\EwarehousingConnector\Services\AuthenticationServiceInterface;
17
use Psr\Http\Message\RequestInterface;
18
19
class AuthenticationMiddleware
20
{
21
    /**
22
     * @var AuthenticationService
23
     */
24
    protected $authenticationService;
25
26
    /**
27
     * AuthenticationMiddleware constructor.
28
     *
29
     * @param AuthenticationServiceInterface $authenticationService
30
     */
31
    public function __construct(AuthenticationServiceInterface $authenticationService)
32
    {
33
        $this->authenticationService = $authenticationService;
0 ignored issues
show
Documentation Bug introduced by
$authenticationService is of type Etrias\EwarehousingConne...icationServiceInterface, but the property $authenticationService was declared to be of type Etrias\EwarehousingConne...s\AuthenticationService. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
34
    }
35
36
    public function __invoke(callable $handler)
37
    {
38
        return function(RequestInterface $request, array $options) use ($handler) {
39
            $encodedAuth = base64_encode($this->authenticationService->getUsername().':'.$this->authenticationService->getHash());
40
            $request = $request->withHeader('Authorization', 'Basic '.$encodedAuth);
41
42
            return $handler($request, $options);
43
        };
44
    }
45
}
46