SecurityModule   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 1
b 0
f 0
dl 0
loc 47
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureConsole() 0 4 1
A settings() 0 4 1
A middlewareHandlers() 0 12 1
A services() 0 3 1
A description() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of web-stack
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\WebStack;
13
14
use Dotenv\Dotenv;
15
use Psr\Container\ContainerExceptionInterface;
16
use Psr\Container\NotFoundExceptionInterface;
17
use Slick\Di\ContainerInterface;
18
use Slick\ModuleApi\Infrastructure\AbstractModule;
19
use Slick\ModuleApi\Infrastructure\Console\ConsoleModuleInterface;
20
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewareHandler;
21
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewarePosition;
0 ignored issues
show
Bug introduced by
The type Slick\ModuleApi\Infrastr...ller\MiddlewarePosition 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...
22
use Slick\ModuleApi\Infrastructure\FrontController\Position;
23
use Slick\ModuleApi\Infrastructure\FrontController\WebModuleInterface;
24
use Slick\WebStack\Infrastructure\Http\AuthorizationMiddleware;
0 ignored issues
show
Bug introduced by
The type Slick\WebStack\Infrastru...AuthorizationMiddleware 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...
25
use Slick\WebStack\Infrastructure\Http\SecurityMiddleware;
0 ignored issues
show
Bug introduced by
The type Slick\WebStack\Infrastru...Http\SecurityMiddleware 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...
26
use Slick\WebStack\UserInterface\Console\Security\GenerateSecretCommand;
27
use Slick\WebStack\UserInterface\Console\Security\HashPassword;
28
use Symfony\Component\Console\Application;
29
use function Slick\ModuleApi\importSettingsFile;
30
31
/**
32
 * SecurityModule
33
 *
34
 * @package Slick\WebStack
35
 */
36
final class SecurityModule extends AbstractModule implements ConsoleModuleInterface, WebModuleInterface
37
{
38
    public function description(): string
39
    {
40
        return "Provides authentication and authorization support for web applications.";
41
    }
42
43
44
    /**
45
     * @throws ContainerExceptionInterface
46
     * @throws NotFoundExceptionInterface
47
     */
48
    public function configureConsole(Application $cli, ContainerInterface $container): void
49
    {
50
        $cli->add($container->get(HashPassword::class));
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Console\Application::add() has been deprecated: since Symfony 7.4, use Application::addCommand() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
        /** @scrutinizer ignore-deprecated */ $cli->add($container->get(HashPassword::class));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
51
        $cli->add($container->get(GenerateSecretCommand::class));
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Console\Application::add() has been deprecated: since Symfony 7.4, use Application::addCommand() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
        /** @scrutinizer ignore-deprecated */ $cli->add($container->get(GenerateSecretCommand::class));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function services(): array
58
    {
59
        return importSettingsFile(dirname(__DIR__) . '/config/security.php');
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65
    public function settings(Dotenv $dotenv): array
66
    {
67
        $dotenv->required('APP_SECRET');
68
        return [];
69
    }
70
71
    public function middlewareHandlers(): array
72
    {
73
        return [
74
            new MiddlewareHandler(
75
                'security',
76
                new MiddlewarePosition(Position::Before, 'router'),
77
                SecurityMiddleware::class
78
            ),
79
            new MiddlewareHandler(
80
                'authorization',
81
                new MiddlewarePosition(Position::Before, 'dispatcher'),
82
                AuthorizationMiddleware::class
83
            ),
84
        ];
85
    }
86
}
87