base/MigrationsHandler.php$1   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 10
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2025 Iain Cambridge
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10
 * the Free Software Foundation, either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\MultiTenancy\Database;
23
24
use Doctrine\Migrations\Configuration\Configuration;
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Configuration\Configuration 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 Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader;
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Conf...ger\EntityManagerLoader 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 Doctrine\Migrations\Configuration\Migration\ConfigurationLoader;
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Conf...ion\ConfigurationLoader 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...
27
use Doctrine\Migrations\DependencyFactory;
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\DependencyFactory 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...
28
use Doctrine\ORM\EntityManagerInterface;
29
use Doctrine\Persistence\ManagerRegistry;
30
use Parthenon\MultiTenancy\Entity\TenantInterface;
31
use Symfony\Component\Console\Input\ArrayInput;
32
use Symfony\Component\Console\Input\InputInterface;
33
use Symfony\Component\Console\Output\NullOutput;
34
use Symfony\Component\Console\Output\OutputInterface;
35
36
class MigrationsHandler implements MigrationsHandlerInterface
37
{
38
    public function __construct(
39
        private ManagerRegistry $managerRegistry,
40
        private string $migrationsDirectory,
41
        private string $entityManagerName,
42
    ) {
43
    }
44
45
    public function handleMigrations(TenantInterface $tenant): void
46
    {
47
        $newInput = new ArrayInput([]);
48
49
        $newInput->setInteractive(false);
50
        $otherCommand = new \Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand($this->getDependencyFactory());
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Tool...and\SyncMetadataCommand 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...
51
        $otherCommand->run($newInput, new NullOutput());
52
53
        $newInput = new ArrayInput([
54
            '--add' => true,
55
            '--all' => true,
56
        ]);
57
58
        $newInput->setInteractive(false);
59
        $otherCommand = new \Doctrine\Migrations\Tools\Console\Command\VersionCommand($this->getDependencyFactory());
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Tool...\Command\VersionCommand 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...
60
        $otherCommand->run($newInput, new NullOutput());
61
    }
62
63
    protected function getDependencyFactory(): DependencyFactory
64
    {
65
        $em = $this->managerRegistry->getManager($this->entityManagerName);
66
        $a = new Configuration();
67
        $a->addMigrationsDirectory('DoctrineMigrations', $this->migrationsDirectory);
68
        $a->setAllOrNothing(false);
69
        $a->setCheckDatabasePlatform(true);
70
        $a->setTransactional(true);
71
        $a->setMetadataStorageConfiguration(new \Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration());
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Meta...ataStorageConfiguration 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...
72
73
        $configLoader = $this->getConfigLoader($a);
74
        $emLoader = $this->getEmLoader($em);
75
76
        return DependencyFactory::fromEntityManager($configLoader, $emLoader);
77
    }
78
79
    protected function executeMigrations(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $output is not used and could be removed. ( Ignorable by Annotation )

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

79
    protected function executeMigrations(InputInterface $input, /** @scrutinizer ignore-unused */ OutputInterface $output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $input is not used and could be removed. ( Ignorable by Annotation )

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

79
    protected function executeMigrations(/** @scrutinizer ignore-unused */ InputInterface $input, OutputInterface $output)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
    }
82
83
    protected function getConfigLoader(Configuration $a)
84
    {
85
        $configLoader = new class($a) implements ConfigurationLoader {
86
            public function __construct(private $a)
87
            {
88
            }
89
90
            public function getConfiguration(): Configuration
91
            {
92
                return $this->a;
93
            }
94
        };
95
96
        return $configLoader;
97
    }
98
99
    protected function getEmLoader(\Doctrine\Persistence\ObjectManager $em)
100
    {
101
        $emLoader = new class($em) implements EntityManagerLoader {
102
            public function __construct(private $em)
103
            {
104
            }
105
106
            public function getEntityManager(?string $name = null): EntityManagerInterface
107
            {
108
                return $this->em;
109
            }
110
        };
111
112
        return $emLoader;
113
    }
114
}
115