Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
18 / 18 |
|
66.67% |
8 / 12 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Planner | |
100.00% |
19 / 19 |
|
100.00% |
18 / 18 |
|
66.67% |
8 / 12 |
|
100.00% |
4 / 4 |
13.70 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| migrationId | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| pendingMigrations | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
|
60.00% |
3 / 5 |
|
100.00% |
1 / 1 |
5.02 | |||
| duplicateMigrationIds | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
|
50.00% |
2 / 4 |
|
100.00% |
1 / 1 |
4.12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celema\Quma\Migrations; |
| 6 | |
| 7 | final readonly class Planner |
| 8 | { |
| 9 | public function __construct( |
| 10 | private DriverPolicy $driverPolicy, |
| 11 | ) {} |
| 12 | |
| 13 | public function migrationId(string $namespace, string $migration): string |
| 14 | { |
| 15 | $name = basename($migration); |
| 16 | |
| 17 | if ($namespace === 'default') { |
| 18 | return $name; |
| 19 | } |
| 20 | |
| 21 | return $namespace . ':' . $name; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @param list<string> $migrations |
| 26 | * @param list<string> $appliedMigrations |
| 27 | * |
| 28 | * @return list<string> |
| 29 | */ |
| 30 | public function pendingMigrations( |
| 31 | string $namespace, |
| 32 | array $migrations, |
| 33 | array $appliedMigrations, |
| 34 | ): array { |
| 35 | $pending = []; |
| 36 | |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 47 | } |
| 48 | |
| 49 | return $pending; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param list<string> $migrations |
| 54 | * |
| 55 | * @return array<string, list<string>> |
| 56 | */ |
| 57 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 58 | { |
| 59 | $pathsById = []; |
| 60 | |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 67 | } |
| 68 | |
| 69 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 70 | } |
| 71 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 10 | private DriverPolicy $driverPolicy, |
| 11 | ) {} |
| 57 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 58 | { |
| 59 | $pathsById = []; |
| 60 | |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 67 | } |
| 68 | |
| 69 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 70 | } |
| 57 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 58 | { |
| 59 | $pathsById = []; |
| 60 | |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 67 | } |
| 68 | |
| 69 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 70 | } |
| 57 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 58 | { |
| 59 | $pathsById = []; |
| 60 | |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 67 | } |
| 68 | |
| 69 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 70 | } |
| 57 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 58 | { |
| 59 | $pathsById = []; |
| 60 | |
| 61 | foreach ($migrations as $migration) { |
| 61 | foreach ($migrations as $migration) { |
| 62 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 67 | } |
| 68 | |
| 69 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 70 | } |
| 13 | public function migrationId(string $namespace, string $migration): string |
| 14 | { |
| 15 | $name = basename($migration); |
| 16 | |
| 17 | if ($namespace === 'default') { |
| 18 | return $name; |
| 13 | public function migrationId(string $namespace, string $migration): string |
| 14 | { |
| 15 | $name = basename($migration); |
| 16 | |
| 17 | if ($namespace === 'default') { |
| 21 | return $namespace . ':' . $name; |
| 22 | } |
| 31 | string $namespace, |
| 32 | array $migrations, |
| 33 | array $appliedMigrations, |
| 34 | ): array { |
| 35 | $pending = []; |
| 36 | |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 47 | } |
| 48 | |
| 49 | return $pending; |
| 50 | } |
| 31 | string $namespace, |
| 32 | array $migrations, |
| 33 | array $appliedMigrations, |
| 34 | ): array { |
| 35 | $pending = []; |
| 36 | |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 47 | } |
| 48 | |
| 49 | return $pending; |
| 50 | } |
| 31 | string $namespace, |
| 32 | array $migrations, |
| 33 | array $appliedMigrations, |
| 34 | ): array { |
| 35 | $pending = []; |
| 36 | |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 47 | } |
| 48 | |
| 49 | return $pending; |
| 50 | } |
| 31 | string $namespace, |
| 32 | array $migrations, |
| 33 | array $appliedMigrations, |
| 34 | ): array { |
| 35 | $pending = []; |
| 36 | |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 47 | } |
| 48 | |
| 49 | return $pending; |
| 50 | } |
| 31 | string $namespace, |
| 32 | array $migrations, |
| 33 | array $appliedMigrations, |
| 34 | ): array { |
| 35 | $pending = []; |
| 36 | |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 39 | continue; |
| 40 | } |
| 41 | |
| 42 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 43 | continue; |
| 44 | } |
| 45 | |
| 46 | $pending[] = $migration; |
| 47 | } |
| 48 | |
| 49 | return $pending; |
| 50 | } |
| 69 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |