Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
18 / 18 |
|
58.33% |
7 / 12 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Planner | |
100.00% |
19 / 19 |
|
100.00% |
18 / 18 |
|
58.33% |
7 / 12 |
|
100.00% |
4 / 4 |
17.23 | |
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 |
|
40.00% |
2 / 5 |
|
100.00% |
1 / 1 |
7.46 | |||
| 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 Celemas\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 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 49 | } |
| 50 | |
| 51 | return $pending; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param list<string> $migrations |
| 56 | * |
| 57 | * @return array<string, list<string>> |
| 58 | */ |
| 59 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 60 | { |
| 61 | $pathsById = []; |
| 62 | |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 71 | } |
| 72 | |
| 73 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 74 | } |
| 75 | } |
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 | ) {} |
| 59 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 60 | { |
| 61 | $pathsById = []; |
| 62 | |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 71 | } |
| 72 | |
| 73 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 74 | } |
| 59 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 60 | { |
| 61 | $pathsById = []; |
| 62 | |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 71 | } |
| 72 | |
| 73 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 74 | } |
| 59 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 60 | { |
| 61 | $pathsById = []; |
| 62 | |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 71 | } |
| 72 | |
| 73 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 74 | } |
| 59 | public function duplicateMigrationIds(string $namespace, array $migrations): array |
| 60 | { |
| 61 | $pathsById = []; |
| 62 | |
| 63 | foreach ($migrations as $migration) { |
| 63 | foreach ($migrations as $migration) { |
| 64 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 65 | |
| 66 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | $pathsById[$this->migrationId($namespace, $migration)][] = $migration; |
| 71 | } |
| 72 | |
| 73 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |
| 74 | } |
| 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 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 49 | } |
| 50 | |
| 51 | return $pending; |
| 52 | } |
| 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 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 49 | } |
| 50 | |
| 51 | return $pending; |
| 52 | } |
| 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 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 37 | foreach ($migrations as $migration) { |
| 37 | foreach ($migrations as $migration) { |
| 38 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 49 | } |
| 50 | |
| 51 | return $pending; |
| 52 | } |
| 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 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 49 | } |
| 50 | |
| 51 | return $pending; |
| 52 | } |
| 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 | assert($migration !== '', 'Migration path must be a non-empty string.'); |
| 39 | |
| 40 | if (in_array($this->migrationId($namespace, $migration), $appliedMigrations, strict: true)) { |
| 41 | continue; |
| 42 | } |
| 43 | |
| 44 | if (!$this->driverPolicy->supportsMigration($migration)) { |
| 45 | continue; |
| 46 | } |
| 47 | |
| 48 | $pending[] = $migration; |
| 49 | } |
| 50 | |
| 51 | return $pending; |
| 52 | } |
| 73 | return array_filter($pathsById, static fn(array $paths): bool => count($paths) > 1); |