Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some code refresh #183

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-mysql5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-mysql8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-anal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require-dev": {
"infection/infection": "*",
"phpstan/phpstan": "*",
"phpunit/phpunit": "*",
"phpunit/phpunit": "<10.0",
"roave/security-advisories": "dev-latest"
},
"autoload": {
Expand Down
27 changes: 15 additions & 12 deletions phpunit-no-yii-autoload.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap-no-autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
processIsolation="true">
<testsuites>
<testsuite name="Yii 2 Migration Test Suite (No Yii Autoloader)">
<directory>./tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap-no-autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" processIsolation="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/dummy</directory>
<directory suffix=".php">./src/views</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Yii 2 Migration Test Suite (No Yii Autoloader)">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
36 changes: 15 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
processIsolation="true">
<testsuites>
<testsuite name="Yii 2 Migration Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/dummy</directory>
<directory suffix=".php">./src/views</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" processIsolation="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/dummy</directory>
<directory suffix=".php">./src/views</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Yii 2 Migration Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 7 additions & 15 deletions src/Arranger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

use yii\base\NotSupportedException;

use function array_diff;
use function array_key_exists;
use function array_merge_recursive;
use function array_unique;
use function count;

final class Arranger implements ArrangerInterface
{
/** @var TableMapperInterface */
Expand Down Expand Up @@ -49,12 +43,10 @@ public function arrangeTables(array $inputTables): void

/**
* Adds dependency of the table.
* @param string $table
* @param string|null $dependsOnTable
*/
private function addDependency(string $table, string $dependsOnTable = null): void
{
if (!array_key_exists($table, $this->dependencies)) {
if (!\array_key_exists($table, $this->dependencies)) {
$this->dependencies[$table] = [];
}

Expand Down Expand Up @@ -92,7 +84,7 @@ public function getReferencesToPostpone(): array
}
}

return array_unique($flattenedReferencesToPostpone);
return \array_unique($flattenedReferencesToPostpone);
}

/**
Expand All @@ -104,21 +96,21 @@ private function arrangeDependencies(array $input): void
$order = [];
$checkList = [];

$inputCount = count($input);
$inputCount = \count($input);

while ($inputCount > count($order)) {
while ($inputCount > \count($order)) {
$done = false;
$lastCheckedName = $lastCheckedDependency = null;

foreach ($input as $name => $dependencies) {
if (array_key_exists($name, $checkList)) {
if (\array_key_exists($name, $checkList)) {
continue;
}

$resolved = true;

foreach ($dependencies as $dependency) {
if (!array_key_exists($dependency, $checkList)) {
if (!\array_key_exists($dependency, $checkList)) {
$resolved = false;
$lastCheckedName = $name;
$lastCheckedDependency = $dependency;
Expand All @@ -135,7 +127,7 @@ private function arrangeDependencies(array $input): void
}

if ($done === false) {
$input[$lastCheckedName] = array_diff($input[$lastCheckedName], [$lastCheckedDependency]);
$input[$lastCheckedName] = \array_diff($input[$lastCheckedName], [$lastCheckedDependency]);

$this->arrangeDependencies($input);
$order = $this->getTablesInOrder();
Expand Down
Loading
Loading