Provider.php$0   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0
ccs 2
cts 2
cp 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Security\Authentication;
6
7
use Chubbyphp\ErrorHandler\HttpException;
8
use Pimple\Container;
9
use Pimple\ServiceProviderInterface;
10
use Psr\Http\Message\ServerRequestInterface as Request;
11
use Psr\Http\Message\ResponseInterface as Response;
12
13
final class AuthenticationProvider implements ServiceProviderInterface
14
{
15
    /**
16
     * @param Container $container
17
     */
18
    public function register(Container $container)
19
    {
20 1
        $container['security.authentication.passwordmanager'] = function () {
21 1
            return new PasswordManager();
22
        };
23
24 1
        $this->registerAuthentication($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Chubbyphp\Security\Authe...egisterAuthentication() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
25 1
        $this->registerMiddleware($container);
26 1
    }
27
28
    /**
29
     * @param Container $container
30
     */
31
    private function registerAuthentication(Container $container)
32
    {
33 1
        $container['security.authentication.authentications'] = function () {
34 1
            return [];
35
        };
36
37 1
        $container['security.authentication'] = function () use ($container) {
38 1
            return new AuthenticationStack($container['security.authentication.authentications']);
39
        };
40 1
    }
41
42
    /**
43
     * @param Container $container
44
     */
45
    private function registerMiddleware(Container $container)
46
    {
47
        $container['security.authentication.errorResponseHandler'] = new class() implements AuthenticationErrorHandlerInterface {
48 1
            public function errorResponse(
49
                Request $request,
50
                Response $response,
51
                int $code,
52
                string $reasonPhrase = null
53
            ): Response {
54 1
                throw HttpException::create($request, $response, $code, $reasonPhrase);
55
            }
56
        };
57
58 1
        $container['security.authentication.middleware'] = function () use ($container) {
59 1
            return new AuthenticationErrorResponseMiddleware(
60 1
                $container['security.authentication'],
61 1
                $container['security.authentication.errorResponseHandler']
62
            );
63
        };
64 1
    }
65
}
66