From a78799e03a3306ac44794466347106a5660a28eb Mon Sep 17 00:00:00 2001
From: pongee <36171363+pongee@users.noreply.github.com>
Date: Tue, 31 Dec 2024 20:50:37 +0100
Subject: [PATCH] feat: change to php8.1, and run rector, and phpcs in build
---
.github/workflows/tests.yml | 10 ++-
CHANGELOG.md | 4 ++
composer.json | 25 +++----
example/code/image.php | 4 +-
example/code/json.php | 4 +-
example/code/plantuml.php | 4 +-
phpcs.xml | 15 +----
phpstan.neon.dist => phpstan.neon | 4 --
rector.php | 24 +++++++
src/Command/Mysql/MysqlCommandAbstract.php | 15 ++---
src/Command/Mysql/MysqlImageCommand.php | 4 +-
src/Command/Mysql/MysqlJsonCommand.php | 4 +-
src/Command/Mysql/MysqlPlantumlCommand.php | 4 +-
.../Connection/ConnectionAbstract.php | 4 +-
.../Connection/ConnectionCollection.php | 4 +-
.../ConnectionCollectionInterface.php | 4 +-
.../Connection/ConnectionInterface.php | 4 +-
.../Connection/ConnectionIterator.php | 4 +-
.../Connection/NotDefinedConnection.php | 4 +-
.../Connection/OneToManyConnection.php | 4 +-
.../Connection/OneToOneConnection.php | 4 +-
src/DataObject/Sql/Database/Table.php | 14 ++--
src/DataObject/Sql/Database/Table/Column.php | 14 ++--
.../Sql/Database/Table/ColumnCollection.php | 6 +-
.../Table/ColumnCollectionInterface.php | 4 +-
.../Sql/Database/Table/ColumnInterface.php | 4 +-
.../Sql/Database/Table/ColumnIterator.php | 4 +-
.../Database/Table/Index/FulltextIndex.php | 4 +-
.../Table/Index/FulltextIndexCollection.php | 4 +-
.../FulltextIndexCollectionInterface.php | 4 +-
.../Table/Index/FulltextIndexInterface.php | 4 +-
.../Table/Index/FulltextIndexIterator.php | 4 +-
.../Database/Table/Index/IndexAbstract.php | 4 +-
.../Database/Table/Index/IndexInterface.php | 4 +-
.../Table/Index/NamedIndexAbstract.php | 4 +-
.../Table/Index/NamedIndexInterface.php | 4 +-
.../Sql/Database/Table/Index/PrimaryKey.php | 4 +-
.../Table/Index/PrimaryKeyInterface.php | 4 +-
.../Sql/Database/Table/Index/SimpleIndex.php | 4 +-
.../Table/Index/SimpleIndexCollection.php | 4 +-
.../Index/SimpleIndexCollectionInterface.php | 4 +-
.../Table/Index/SimpleIndexInterface.php | 4 +-
.../Table/Index/SimpleIndexIterator.php | 4 +-
.../Sql/Database/Table/Index/SpatialIndex.php | 4 +-
.../Table/Index/SpatialIndexCollection.php | 4 +-
.../Index/SpatialIndexCollectionInterface.php | 4 +-
.../Table/Index/SpatialIndexInterface.php | 4 +-
.../Table/Index/SpatialIndexIterator.php | 4 +-
.../Sql/Database/Table/Index/UniqueIndex.php | 4 +-
.../Table/Index/UniqueIndexCollection.php | 4 +-
.../Index/UniqueIndexCollectionInterface.php | 4 +-
.../Table/Index/UniqueIndexInterface.php | 4 +-
.../Table/Index/UniqueIndexIterator.php | 4 +-
.../Sql/Database/TableCollection.php | 4 +-
.../Sql/Database/TableCollectionInterface.php | 4 +-
.../Sql/Database/TableInterface.php | 4 +-
src/DataObject/Sql/Database/TableIterator.php | 4 +-
src/DataObject/Sql/Schema.php | 4 +-
src/DataObject/Sql/SchemaInterface.php | 4 +-
src/Export/ExportInterface.php | 4 +-
src/Export/Json.php | 4 +-
src/Export/Plantuml.php | 4 +-
src/Generator/ImageGenerator.php | 18 ++---
src/Parser/CassandraParser.php | 30 ++++-----
src/Parser/MysqlParser.php | 12 ++--
src/Parser/ParserAbstract.php | 66 ++++++++++---------
src/Parser/ParserInterface.php | 4 +-
.../References/expectedSchema.php | 4 +-
.../FullDatabases/Auth/expectedSchema.php | 4 +-
.../FullDatabases/Auth/forcedConnection.php | 4 +-
.../FullDatabases/Sakila/expectedSchema.php | 4 +-
.../FullDatabases/World/expectedSchema.php | 4 +-
.../AlterTableForeignKey/expectedSchema.php | 4 +-
.../Comments/expectedSchema.php | 4 +-
.../DifferentFormatting/expectedSchema.php | 4 +-
.../EmptyDatabase/expectedSchema.php | 4 +-
.../LowerCasedDefinitions/expectedSchema.php | 4 +-
.../NoPrimaryKey/expectedSchema.php | 4 +-
.../UpperCasedDefinitions/expectedSchema.php | 4 +-
.../Command/Mysql/MysqlJsonCommandTest.php | 4 +-
.../Mysql/MysqlPlantumlCommandTest.php | 4 +-
.../Connection/ConnectionAbstract.php | 4 +-
.../Connection/ConnectionCollectionTest.php | 4 +-
.../Connection/OneToManyConnectionTest.php | 4 +-
.../Connection/OneToOneConnectionTest.php | 4 +-
.../Database/Table/ColumnCollectionTest.php | 4 +-
.../Sql/Database/Table/ColumnTest.php | 4 +-
.../Index/FulltextIndexCollectionTest.php | 4 +-
.../Table/Index/FulltextIndexTest.php | 4 +-
.../Table/Index/NamedIndexAbstract.php | 4 +-
.../Database/Table/Index/PrimaryKeyTest.php | 4 +-
.../Table/Index/SimpleIndexCollectionTest.php | 4 +-
.../Database/Table/Index/SimpleIndexTest.php | 4 +-
.../Index/SpatialIndexCollectionTest.php | 4 +-
.../Database/Table/Index/SpatialIndexTest.php | 4 +-
...Test.php => UniqueIndexCollectionTest.php} | 4 +-
.../Database/Table/Index/UniqueIndexTest.php | 4 +-
.../Sql/Database/TableCollectionTest.php | 4 +-
.../DataObject/Sql/Database/TableTest.php | 4 +-
test/Unit/DataObject/Sql/SchemaTest.php | 4 +-
test/Unit/Export/JsonTest.php | 4 +-
test/Unit/Export/PlantumlTest.php | 4 +-
test/Unit/Parser/CassandraParserTest.php | 6 +-
test/Unit/Parser/MysqlParserTest.php | 6 +-
.../Unit/Template/Plantuml/V1TemplateTest.php | 10 +--
test/bootstrap.php | 4 +-
106 files changed, 420 insertions(+), 215 deletions(-)
rename phpstan.neon.dist => phpstan.neon (93%)
create mode 100644 rector.php
rename test/Unit/DataObject/Sql/Database/Table/Index/{UniqueIndexCollecetionTest.php => UniqueIndexCollectionTest.php} (97%)
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 @@
-