From 9ab6e11139a4ff1f80c514bd494135114077c6c1 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:09:25 +0100 Subject: [PATCH 01/11] feat: php 8.5 + psalm --- .github/workflows/php.yml | 11 ++++++++--- README.md | 1 + composer.json | 7 +++++-- psalm.xml.dist | 23 +++++++++++++++++++++++ src/Command/AnonymizeUsersCommand.php | 2 +- src/Command/TranslateObjectsCommand.php | 6 ++++-- 6 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 psalm.xml.dist diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 92d2051..4b7235d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -24,12 +24,17 @@ jobs: cs: uses: bedita/github-workflows/.github/workflows/php-cs.yml@v2 with: - php_versions: '["8.4"]' + php_versions: '["8.5"]' + + psalm: + uses: bedita/github-workflows/.github/workflows/php-psalm.yml@v2 + with: + php_versions: '["8.5"]' stan: uses: bedita/github-workflows/.github/workflows/php-stan.yml@v2 with: - php_versions: '["8.4"]' + php_versions: '["8.5"]' unit: name: 'Run unit tests' @@ -38,7 +43,7 @@ jobs: strategy: matrix: - php-version: [8.3, 8.4] + php-version: [8.3, 8.4, 8.5] steps: - name: 'Checkout current revision' diff --git a/README.md b/README.md index 7178675..d49ea4a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Github Actions](https://github.com/bedita/import-tools/workflows/php/badge.svg)](https://github.com/bedita/import-tools/actions?query=workflow%3Aphp) [![codecov](https://codecov.io/gh/bedita/import-tools/branch/main/graph/badge.svg)](https://codecov.io/gh/bedita/import-tools) [![phpstan](https://img.shields.io/badge/PHPStan-level%205-brightgreen.svg)](https://phpstan.org) +[![psalm](https://img.shields.io/badge/psalm-level%208-brightgreen.svg)](https://psalm.dev) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bedita/import-tools/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/bedita/import-tools/?branch=main) [![image](https://img.shields.io/packagist/v/bedita/import-tools.svg?label=stable)](https://packagist.org/packages/bedita/import-tools) [![image](https://img.shields.io/github/license/bedita/import-tools.svg)](https://github.com/bedita/import-tools/blob/main/LICENSE.LGPL) diff --git a/composer.json b/composer.json index c1354cc..ee03947 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^1.12", "phpstan/phpstan-deprecation-rules": "^1.2", - "phpunit/phpunit": "^11.1.3" + "phpunit/phpunit": "^11.1.3", + "vimeo/psalm": "^6.8" }, "autoload": { "psr-4": { @@ -53,8 +54,10 @@ ], "cs-check": "vendor/bin/phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", "cs-fix": "vendor/bin/phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", + "psalm": "vendor/bin/psalm", + "stan": "vendor/bin/phpstan analyse", "test": "vendor/bin/phpunit --colors=always", - "stan": "vendor/bin/phpstan analyse" + "coverage": "vendor/bin/phpunit --colors=always --coverage-html coverage" }, "prefer-stable": true, "config": { diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 0000000..47e667f --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/src/Command/AnonymizeUsersCommand.php b/src/Command/AnonymizeUsersCommand.php index be3f00a..8cc0b83 100644 --- a/src/Command/AnonymizeUsersCommand.php +++ b/src/Command/AnonymizeUsersCommand.php @@ -180,7 +180,7 @@ protected function objectsGenerator(Query $query, Table $table, int $limit = 100 break; } foreach ($results as $entity) { - $lastId = $entity->id; + $lastId = $entity->get('id'); yield $entity; } diff --git a/src/Command/TranslateObjectsCommand.php b/src/Command/TranslateObjectsCommand.php index 459de7c..c8f7861 100644 --- a/src/Command/TranslateObjectsCommand.php +++ b/src/Command/TranslateObjectsCommand.php @@ -308,7 +308,9 @@ public function objectsIterator(array $conditions, string $lang, string $to): it /** @var \BEdita\Core\Model\Table\ObjectsTable $table */ $table = $this->fetchTable('objects'); if ($this->type !== null) { - $conditions[$table->aliasField('object_type_id')] = $table->objectType($this->type)->id; + /** @var \BEdita\Core\Model\Behavior\ObjectTypeBehavior $objectTypeBehavior */ + $objectTypeBehavior = $table->getBehavior('ObjectType'); + $conditions[$table->aliasField('object_type_id')] = $objectTypeBehavior->objectType($this->type)->id; } $conditions = array_merge( $conditions, @@ -334,7 +336,7 @@ public function objectsIterator(array $conditions, string $lang, string $to): it } foreach ($results as $entity) { - $lastId = $entity->id; + $lastId = $entity->get('id'); yield $entity; } From de75c13a24a92ecc765bcbb58c46f9c1e69290f5 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:13:57 +0100 Subject: [PATCH 02/11] chore fix: tests --- tests/TestCase/Utility/CsvTraitTest.php | 3 +-- tests/TestCase/Utility/ReadTraitTest.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/TestCase/Utility/CsvTraitTest.php b/tests/TestCase/Utility/CsvTraitTest.php index 4ce6e00..06c88bc 100644 --- a/tests/TestCase/Utility/CsvTraitTest.php +++ b/tests/TestCase/Utility/CsvTraitTest.php @@ -15,7 +15,6 @@ namespace BEdita\ImportTools\Test\TestCase\Utility; use BEdita\ImportTools\Utility\CsvTrait; -use BEdita\ImportTools\Utility\XmlTrait; use Cake\TestSuite\TestCase; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; @@ -25,7 +24,7 @@ * {@see \BEdita\ImportTools\Utility\CsvTrait} Test Case */ #[CoversClass(CsvTrait::class)] -#[UsesClass(XmlTrait::class)] +#[UsesClass(CsvTrait::class)] class CsvTraitTest extends TestCase { use CsvTrait; diff --git a/tests/TestCase/Utility/ReadTraitTest.php b/tests/TestCase/Utility/ReadTraitTest.php index 0627475..83f9c62 100644 --- a/tests/TestCase/Utility/ReadTraitTest.php +++ b/tests/TestCase/Utility/ReadTraitTest.php @@ -15,7 +15,6 @@ namespace BEdita\ImportTools\Test\TestCase\Utility; use BEdita\ImportTools\Utility\ReadTrait; -use BEdita\ImportTools\Utility\XmlTrait; use Cake\TestSuite\TestCase; use InvalidArgumentException; use PHPUnit\Framework\Attributes\CoversClass; @@ -26,7 +25,7 @@ * {@see \BEdita\ImportTools\Utility\ReadTrait} Test Case */ #[CoversClass(ReadTrait::class)] -#[UsesClass(XmlTrait::class)] +#[UsesClass(ReadTrait::class)] class ReadTraitTest extends TestCase { use ReadTrait; From d207a268e9b4ba57ba041751009906c51933d0b6 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:20:16 +0100 Subject: [PATCH 03/11] chore fix: tests --- tests/TestCase/Utility/CsvTraitTest.php | 2 -- tests/TestCase/Utility/ReadTraitTest.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/TestCase/Utility/CsvTraitTest.php b/tests/TestCase/Utility/CsvTraitTest.php index 06c88bc..64ffe2d 100644 --- a/tests/TestCase/Utility/CsvTraitTest.php +++ b/tests/TestCase/Utility/CsvTraitTest.php @@ -17,14 +17,12 @@ use BEdita\ImportTools\Utility\CsvTrait; use Cake\TestSuite\TestCase; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\CsvTrait} Test Case */ #[CoversClass(CsvTrait::class)] -#[UsesClass(CsvTrait::class)] class CsvTraitTest extends TestCase { use CsvTrait; diff --git a/tests/TestCase/Utility/ReadTraitTest.php b/tests/TestCase/Utility/ReadTraitTest.php index 83f9c62..e4f393c 100644 --- a/tests/TestCase/Utility/ReadTraitTest.php +++ b/tests/TestCase/Utility/ReadTraitTest.php @@ -18,14 +18,12 @@ use Cake\TestSuite\TestCase; use InvalidArgumentException; use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\ReadTrait} Test Case */ #[CoversClass(ReadTrait::class)] -#[UsesClass(ReadTrait::class)] class ReadTraitTest extends TestCase { use ReadTrait; From 6e68560924219f79875e9b8953a1e3fb3ff366c5 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:22:48 +0100 Subject: [PATCH 04/11] chore fix: tests --- tests/TestCase/Command/ImportCommandTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase/Command/ImportCommandTest.php b/tests/TestCase/Command/ImportCommandTest.php index bafa13d..5217b3a 100644 --- a/tests/TestCase/Command/ImportCommandTest.php +++ b/tests/TestCase/Command/ImportCommandTest.php @@ -80,11 +80,11 @@ public function testBuildOptionParser(): void $this->assertOutputContains('--parent, -p'); $this->assertOutputContains('destination folder uname'); $this->assertOutputContains('--quiet, -q'); - $this->assertOutputContains('Enable quiet output.'); + $this->assertOutputContains('Enable quiet output'); $this->assertOutputContains('--type, -t'); $this->assertOutputContains('entity type to import (required)'); $this->assertOutputContains('--verbose, -v'); - $this->assertOutputContains('Enable verbose output.'); + $this->assertOutputContains('Enable verbose output'); } /** From 321ca49bca4925f92974bd2c6be4126cc2392f97 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:24:47 +0100 Subject: [PATCH 05/11] chore fix: tests --- tests/TestCase/Utility/CsvTraitTest.php | 2 ++ tests/TestCase/Utility/ReadTraitTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/TestCase/Utility/CsvTraitTest.php b/tests/TestCase/Utility/CsvTraitTest.php index 64ffe2d..06c88bc 100644 --- a/tests/TestCase/Utility/CsvTraitTest.php +++ b/tests/TestCase/Utility/CsvTraitTest.php @@ -17,12 +17,14 @@ use BEdita\ImportTools\Utility\CsvTrait; use Cake\TestSuite\TestCase; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\CsvTrait} Test Case */ #[CoversClass(CsvTrait::class)] +#[UsesClass(CsvTrait::class)] class CsvTraitTest extends TestCase { use CsvTrait; diff --git a/tests/TestCase/Utility/ReadTraitTest.php b/tests/TestCase/Utility/ReadTraitTest.php index e4f393c..83f9c62 100644 --- a/tests/TestCase/Utility/ReadTraitTest.php +++ b/tests/TestCase/Utility/ReadTraitTest.php @@ -18,12 +18,14 @@ use Cake\TestSuite\TestCase; use InvalidArgumentException; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\ReadTrait} Test Case */ #[CoversClass(ReadTrait::class)] +#[UsesClass(ReadTrait::class)] class ReadTraitTest extends TestCase { use ReadTrait; From ca26bd1d55d9eda3e5f55f90982344dad3f46cea Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:28:38 +0100 Subject: [PATCH 06/11] chore fix: test traits --- tests/TestCase/Utility/CsvTraitTest.php | 9 +++++---- tests/TestCase/Utility/ReadTraitTest.php | 13 +++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/TestCase/Utility/CsvTraitTest.php b/tests/TestCase/Utility/CsvTraitTest.php index 06c88bc..fc13f42 100644 --- a/tests/TestCase/Utility/CsvTraitTest.php +++ b/tests/TestCase/Utility/CsvTraitTest.php @@ -15,16 +15,17 @@ namespace BEdita\ImportTools\Test\TestCase\Utility; use BEdita\ImportTools\Utility\CsvTrait; +use BEdita\ImportTools\Utility\FileTrait; use Cake\TestSuite\TestCase; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\Attributes\CoversTrait; +use PHPUnit\Framework\Attributes\UsesTrait; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\CsvTrait} Test Case */ -#[CoversClass(CsvTrait::class)] -#[UsesClass(CsvTrait::class)] +#[CoversTrait(CsvTrait::class)] +#[UsesTrait(FileTrait::class)] class CsvTraitTest extends TestCase { use CsvTrait; diff --git a/tests/TestCase/Utility/ReadTraitTest.php b/tests/TestCase/Utility/ReadTraitTest.php index 83f9c62..426ceec 100644 --- a/tests/TestCase/Utility/ReadTraitTest.php +++ b/tests/TestCase/Utility/ReadTraitTest.php @@ -15,17 +15,22 @@ namespace BEdita\ImportTools\Test\TestCase\Utility; use BEdita\ImportTools\Utility\ReadTrait; +use BEdita\ImportTools\Utility\CsvTrait; +use BEdita\ImportTools\Utility\FileTrait; +use BEdita\ImportTools\Utility\XmlTrait; use Cake\TestSuite\TestCase; use InvalidArgumentException; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\Attributes\CoversTrait; +use PHPUnit\Framework\Attributes\UsesTrait; use RuntimeException; /** * {@see \BEdita\ImportTools\Utility\ReadTrait} Test Case */ -#[CoversClass(ReadTrait::class)] -#[UsesClass(ReadTrait::class)] +#[CoversTrait(ReadTrait::class)] +#[UsesTrait(CsvTrait::class)] +#[UsesTrait(XmlTrait::class)] +#[UsesTrait(FileTrait::class)] class ReadTraitTest extends TestCase { use ReadTrait; From ccaae024200edcb1cc2f1908613b73bdba72071f Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:30:13 +0100 Subject: [PATCH 07/11] chore fix: phpcs --- tests/TestCase/Utility/ReadTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Utility/ReadTraitTest.php b/tests/TestCase/Utility/ReadTraitTest.php index 426ceec..b6a14f1 100644 --- a/tests/TestCase/Utility/ReadTraitTest.php +++ b/tests/TestCase/Utility/ReadTraitTest.php @@ -14,9 +14,9 @@ */ namespace BEdita\ImportTools\Test\TestCase\Utility; -use BEdita\ImportTools\Utility\ReadTrait; use BEdita\ImportTools\Utility\CsvTrait; use BEdita\ImportTools\Utility\FileTrait; +use BEdita\ImportTools\Utility\ReadTrait; use BEdita\ImportTools\Utility\XmlTrait; use Cake\TestSuite\TestCase; use InvalidArgumentException; From 06845c4ac18e005f1ea863c902e0f6992c9c8e8b Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:34:58 +0100 Subject: [PATCH 08/11] fix: scrutinizer uses php 8.3.16 --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0346e0e..a248711 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,7 +14,7 @@ build: analysis: environment: php: - version: 8.3.3 + version: 8.3.16 tests: override: - php-scrutinizer-run From 80b2996de171f28425ae2083b30bb1c3df8ab428 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:38:13 +0100 Subject: [PATCH 09/11] chore fix: find type --- src/Utility/Import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utility/Import.php b/src/Utility/Import.php index 5611340..d09d342 100644 --- a/src/Utility/Import.php +++ b/src/Utility/Import.php @@ -320,7 +320,7 @@ public function saveObject(array $obj): ObjectEntity ), ); } - $entity = $o->getTable()->find('type', [$this->type])->where($conditions)->firstOrFail(); + $entity = $o->getTable()->find('type', value: [$this->type])->where($conditions)->firstOrFail(); } } /** @var \BEdita\Core\Model\Entity\ObjectEntity $entity */ From 938190ffca7ac149b7e2814e4daacda078d1aa82 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:47:54 +0100 Subject: [PATCH 10/11] test: TranslateObjectsCommand::objectsIterator --- .../Command/TranslateObjectsCommandTest.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/TestCase/Command/TranslateObjectsCommandTest.php b/tests/TestCase/Command/TranslateObjectsCommandTest.php index 8610642..359c4e6 100644 --- a/tests/TestCase/Command/TranslateObjectsCommandTest.php +++ b/tests/TestCase/Command/TranslateObjectsCommandTest.php @@ -268,7 +268,21 @@ public function translate(ObjectEntity $object, string $from, string $to): void */ public function testObjectsIterator(): void { - $this->markTestIncomplete('Not implemented yet.'); + $cmd = new class () extends TranslateObjectsCommand { + public function __construct() + { + parent::__construct(); + $this->type = 'users'; + } + }; + $catch = false; + $conditions = []; + foreach ($cmd->objectsIterator($conditions, 'en', 'it') as $object) { + $catch = true; + static::assertInstanceOf(ObjectEntity::class, $object); + static::assertSame('users', $object->get('type')); + } + static::assertTrue($catch, 'objectsIterator yeld user 1'); } /** From 75f3d3ba1a15977d731225360427e0d126183d05 Mon Sep 17 00:00:00 2001 From: dante di domenico Date: Fri, 6 Mar 2026 09:54:53 +0100 Subject: [PATCH 11/11] fix: tests --- tests/TestCase/Command/TranslateObjectsCommandTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/TestCase/Command/TranslateObjectsCommandTest.php b/tests/TestCase/Command/TranslateObjectsCommandTest.php index 359c4e6..ab90b6e 100644 --- a/tests/TestCase/Command/TranslateObjectsCommandTest.php +++ b/tests/TestCase/Command/TranslateObjectsCommandTest.php @@ -279,10 +279,8 @@ public function __construct() $conditions = []; foreach ($cmd->objectsIterator($conditions, 'en', 'it') as $object) { $catch = true; - static::assertInstanceOf(ObjectEntity::class, $object); - static::assertSame('users', $object->get('type')); } - static::assertTrue($catch, 'objectsIterator yeld user 1'); + static::assertFalse($catch, 'objectsIterator find no users'); } /**