Passed
Push — master ( 1da312...9d0d84 )
by Filipe
12:48 queued 15s
created

OrmModule::onDisable()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
nc 3
nop 1
dl 0
loc 8
c 0
b 0
f 0
cc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of orm
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\Orm;
13
14
use Dotenv\Dotenv;
15
use JsonException;
16
use Slick\Di\ContainerInterface;
17
use Slick\ModuleApi\Infrastructure\AbstractModule;
18
use Slick\ModuleApi\Infrastructure\Console\ConsoleModuleInterface;
19
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewareHandler;
20
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewareHandlerInterface;
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\Orm\Infrastructure\Http\EntityManagerFlushMiddleware;
0 ignored issues
show
Bug introduced by
The type Slick\Orm\Infrastructure...yManagerFlushMiddleware 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\Orm\OrmModule\ModuleEventHandling;
26
use Slick\WebStack\Infrastructure\ComposerParser;
27
use Symfony\Component\Console\Application;
28
use function Slick\ModuleApi\importSettingsFile;
29
30
/**
31
 * OrmModule
32
 *
33
 * @package Slick\Orm
34
 *
35
 */
36
final class OrmModule extends AbstractModule implements ConsoleModuleInterface, WebModuleInterface
37
{
38
    use ModuleEventHandling;
39
40
    public static string $appConfig = APP_ROOT . '/config';
41
    public static string $migrationCnfFile = APP_ROOT . '/config/migrations.json';
42
    public static string $ormCnfFile = APP_ROOT . '/config/modules/orm.php';
43
44
    private ComposerParser $composerParser;
45
46
    /**
47
     * @throws JsonException
48
     */
49
    public function __construct()
50
    {
51
        $this->composerParser = new ComposerParser(APP_ROOT . "/composer.json");
52
    }
53
54
    public function description(): ?string
55
    {
56
        return "This module offers Migrations, Database Abstraction (DBA), and Object-Relational Mapping (ORM)";
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function settings(Dotenv $dotenv): array
63
    {
64
        $settingsFile = APP_ROOT .'/config/modules/orm.php';
65
        $defaultSettings = [
66
            'databases' => [
67
                'default' => [
68
                    'url' => 'pdo-sqlite:///:memory:'
69
                ]
70
            ]
71
        ];
72
        return importSettingsFile($settingsFile, $defaultSettings);
73
    }
74
75
    public function services(): array
76
    {
77
        return importSettingsFile(dirname(__DIR__) . '/config/services.php');
78
    }
79
80
    /**
81
     * @inheritdoc
82
     * @SuppressWarnings(PHPMD.StaticAccess)
83
     */
84
    public function configureConsole(Application $cli, ContainerInterface $container): void
85
    {
86
        $configure = require dirname(__DIR__) . '/config/console.php';
87
        $configure($cli, self::$migrationCnfFile);
88
    }
89
90
91
    /**
92
     * Retrieve the middleware handlers for the application.
93
     *
94
     * @return array<MiddlewareHandlerInterface> The middleware handlers.
95
     */
96
    public function middlewareHandlers(): array
97
    {
98
        return [
99
            new MiddlewareHandler(
100
                'orm-flush',
101
                new MiddlewarePosition(Position::Top),
102
                EntityManagerFlushMiddleware::class
103
            )
104
        ];
105
    }
106
}
107