diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36fcbe7..a294045 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,8 +12,10 @@ jobs: fail-fast: true matrix: php: - - '8.0' - '8.1' + - '8.2' + - '8.3' + - '8.4' name: PHP ${{ matrix.php }} @@ -38,3 +40,9 @@ jobs: - name: Run static analysis run: composer run-script phpstan + + - name: Run rector + run: composer run-script rector-dry-run + + - name: Run phpcs analysis + run: composer run-script phpcs diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b99b1a..e8410db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.0.0] - 2024-01-04 +### Changed +- Switch to PHP 8.1 + ## [3.2.0] - 2022-03-05 ### Added - Base Apache Cassandra support diff --git a/composer.json b/composer.json index f0e12ee..e833a2a 100644 --- a/composer.json +++ b/composer.json @@ -10,17 +10,18 @@ "plantuml" ], "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-json": "*", - "symfony/console": "^3.0|^4.0|^5.0|^6.0", - "twig/twig": "^2.0" + "symfony/console": "^5.0||^6.0", + "twig/twig": "^3.0" }, "require-dev": { - "roave/security-advisories": "dev-master", - "phpunit/phpunit": "^9.0", - "squizlabs/php_codesniffer": "^3.0", - "slevomat/coding-standard": "^7.0", - "phpstan/phpstan": "^1.4" + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^10.0", + "rector/rector": "^2.0", + "roave/security-advisories": "dev-latest", + "slevomat/coding-standard": "^8.0", + "squizlabs/php_codesniffer": "^3.0" }, "autoload": { "psr-4": { @@ -36,9 +37,11 @@ "database-schema-visualization" ], "scripts": { - "phpcs": "phpcs --standard=PSR12", - "phpstan": "phpstan analyse", - "test": "php ./vendor/bin/phpunit" + "phpcs": "phpcs", + "phpstan": "phpstan analyse --memory-limit=512M", + "test": "php ./vendor/bin/phpunit", + "rector": "php ./vendor/bin/rector process example src test", + "rector-dry-run": "php ./vendor/bin/rector process example src test --dry-run" }, "config": { "allow-plugins": { diff --git a/example/code/image.php b/example/code/image.php index 7fffd85..b3f0d5c 100644 --- a/example/code/image.php +++ b/example/code/image.php @@ -1,4 +1,6 @@ - - src test + example - - - - - - - - - - - - + diff --git a/phpstan.neon.dist b/phpstan.neon similarity index 93% rename from phpstan.neon.dist rename to phpstan.neon index 464566f..016866b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon @@ -16,7 +16,3 @@ parameters: fileExtensions: - php - - excludes_analyse: - - vendor - diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..a26fbd0 --- /dev/null +++ b/rector.php @@ -0,0 +1,24 @@ +withRules([ + RemoveUselessParamTagRector::class, + RemoveUselessReturnTagRector::class, + RemoveUselessReadOnlyTagRector::class, + RemoveNonExistingVarAnnotationRector::class, + RemoveUselessVarTagRector::class, + ]) + ->withPreparedSets( + typeDeclarations: true, + ) + ->withPhpSets( + php81: true, + ); \ No newline at end of file diff --git a/src/Command/Mysql/MysqlCommandAbstract.php b/src/Command/Mysql/MysqlCommandAbstract.php index 48a01e0..45d179c 100644 --- a/src/Command/Mysql/MysqlCommandAbstract.php +++ b/src/Command/Mysql/MysqlCommandAbstract.php @@ -1,4 +1,6 @@ -parser = $parser; $this->rootDir = rtrim($rootDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $this @@ -103,9 +101,10 @@ protected function getForcedConnections(array $connections): ConnectionCollectio \. (?[^.]+) $ - #x', $connection, $matches); + #x', (string) $connection, $matches); - if (!empty($matches['childTableName']) + if ( + !empty($matches['childTableName']) && !empty($matches['childTableColumns']) && !empty($matches['parentTableName']) && !empty($matches['parentTableColumns']) diff --git a/src/Command/Mysql/MysqlImageCommand.php b/src/Command/Mysql/MysqlImageCommand.php index d99cc8b..ce40990 100644 --- a/src/Command/Mysql/MysqlImageCommand.php +++ b/src/Command/Mysql/MysqlImageCommand.php @@ -1,4 +1,6 @@ -columns[$column->getName()] = $column; } diff --git a/src/DataObject/Sql/Database/Table/ColumnCollectionInterface.php b/src/DataObject/Sql/Database/Table/ColumnCollectionInterface.php index d3d80b2..cc33cfa 100644 --- a/src/DataObject/Sql/Database/Table/ColumnCollectionInterface.php +++ b/src/DataObject/Sql/Database/Table/ColumnCollectionInterface.php @@ -1,4 +1,6 @@ -handleMapAndSetConnections($runResult->getTables(), $runResult->getConnections()); return $runResult; @@ -218,9 +219,7 @@ protected function getColumnsWithoutRequiredTypeParametersFromCreateTableSchema( protected function trimNames(string ...$strings): array { return array_map( - function ($string) { - return $this->trimName($string); - }, + fn($string): string => $this->trimName($string), $strings ); } @@ -228,9 +227,7 @@ function ($string) { protected function getFormatedParameters(string ...$strings): array { return array_map( - function ($string) { - return $this->getFormatedParameter($string); - }, + fn($string): string => $this->getFormatedParameter($string), $strings ); } @@ -532,21 +529,22 @@ public function getConnectionsByCreateTable(string $sql): ConnectionCollectionIn private function handleMapAndSetConnections( TableCollection $tables, ConnectionCollectionInterface $connections - ) : ConnectionCollection - { + ): ConnectionCollection { $allDefinedTables = array_map( - function (TableInterface $table) { - return $table->getName(); - }, + fn(TableInterface $table): string => $table->getName(), $tables->getIterator()->getArrayCopy() ); foreach ($tables as $table) { foreach ($table->getColumns() as $column) { - if (!in_array($column->getType(), ['set', 'map', 'frozen'])) continue; + if (!in_array($column->getType(), ['set', 'map', 'frozen'])) { + continue; + } foreach ($column->getTypeParameters() as $typeParameter) { - if (!isset($allDefinedTables[$typeParameter])) continue; + if (!isset($allDefinedTables[$typeParameter])) { + continue; + } $connections->add(new OneToManyConnection($table->getName(), $typeParameter, [], [])); } } diff --git a/src/Parser/MysqlParser.php b/src/Parser/MysqlParser.php index 880fe68..faa216b 100644 --- a/src/Parser/MysqlParser.php +++ b/src/Parser/MysqlParser.php @@ -1,4 +1,6 @@ -trimName($string); - }, + fn($string): string => $this->trimName($string), $strings ); } @@ -192,9 +192,7 @@ function ($string) { protected function getFormatedParameters(string ...$strings): array { return array_map( - function ($string) { - return $this->getFormatedParameter($string); - }, + fn($string): string => $this->getFormatedParameter($string), $strings ); } diff --git a/src/Parser/ParserAbstract.php b/src/Parser/ParserAbstract.php index 84a938b..89b4374 100644 --- a/src/Parser/ParserAbstract.php +++ b/src/Parser/ParserAbstract.php @@ -1,4 +1,6 @@ - trim( + $column, + '` ' + ), $childTableColumns ); $parentTableColumns = explode( ',', - $matches['parentTableColumns'][$index] + (string) $matches['parentTableColumns'][$index] ); $parentTableColumns = array_map( - static function ($column): string { - return trim( - $column, - '` ' - ); - }, + static fn(string $column): string => trim( + $column, + '` ' + ), $parentTableColumns ); @@ -176,7 +175,7 @@ protected function removeLineComments($schema): string return preg_replace( '#--.+$#m', '', - $schema + (string) $schema ); } @@ -216,11 +215,13 @@ protected function removeMultiLineComments($schema): string protected function getSafeRandomString(string $schema): string { do { - $safeRandomString = (string)rand(); - } while (strpos( - $schema, - $safeRandomString - ) !== false); + $safeRandomString = (string)random_int(0, mt_getrandmax()); + } while ( + str_contains( + $schema, + $safeRandomString + ) + ); return $safeRandomString; } @@ -229,12 +230,10 @@ protected function replaceCharactersInString(string $schema, array $replacePairs { return preg_replace_callback( '#(\'.*\')#Uxsm', - static function ($matches) use ($replacePairs): string { - return strtr( - $matches[0], - $replacePairs - ); - }, + static fn($matches): string => strtr( + $matches[0], + $replacePairs + ), $schema ); } @@ -244,7 +243,7 @@ protected function removeFormating($schema): string return preg_replace( '/^\s+/m', '', - $schema + (string) $schema ); } @@ -313,7 +312,8 @@ private function parserConnections( foreach ($tables as $iteratedTable) { foreach ($connections as $connection) { - if ($connection->getChildTableName() === '*' + if ( + $connection->getChildTableName() === '*' || $connection->getChildTableName() === $iteratedTable->getName() ) { $columns = $iteratedTable->getColumns(); @@ -321,7 +321,8 @@ private function parserConnections( if (empty(array_diff($connection->getChildTableColumns(), $columns->getColumnsName()))) { $parentTable = $tables->offsetGet($connection->getParentTableName()); - if ($parentTable instanceof TableInterface + if ( + $parentTable instanceof TableInterface && empty( array_diff( $connection->getParentTableColumns(), @@ -341,7 +342,8 @@ private function parserConnections( } } - if ($iteratedTable->getPrimaryKey() instanceof PrimaryKeyInterface + if ( + $iteratedTable->getPrimaryKey() instanceof PrimaryKeyInterface && $iteratedTable->getPrimaryKey()->getColumns() === $childTableColumns ) { $oneToOne = true; diff --git a/src/Parser/ParserInterface.php b/src/Parser/ParserInterface.php index 00a4f2a..a95d330 100644 --- a/src/Parser/ParserInterface.php +++ b/src/Parser/ParserInterface.php @@ -1,4 +1,6 @@ -run(file_get_contents($file->getRealPath()), $forcedConnections); //@todo diff --git a/test/Unit/Parser/MysqlParserTest.php b/test/Unit/Parser/MysqlParserTest.php index 1d0b389..ad54024 100644 --- a/test/Unit/Parser/MysqlParserTest.php +++ b/test/Unit/Parser/MysqlParserTest.php @@ -1,4 +1,6 @@ -run(file_get_contents($file->getRealPath()), $forcedConnections); //@todo diff --git a/test/Unit/Template/Plantuml/V1TemplateTest.php b/test/Unit/Template/Plantuml/V1TemplateTest.php index fac9ddb..1649020 100644 --- a/test/Unit/Template/Plantuml/V1TemplateTest.php +++ b/test/Unit/Template/Plantuml/V1TemplateTest.php @@ -1,4 +1,6 @@ -