From 63ab18d1890c2c8b62afaf84578b5137c4379771 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 9 Dec 2021 23:07:43 +0100 Subject: [PATCH 1/9] Bump phpstan version --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 7092ac5..31e95d3 100644 --- a/composer.json +++ b/composer.json @@ -9,16 +9,16 @@ "license": "MIT", "require": { "ext-json": "*", - "symfony/console": "^4.3|^5.1", - "flix-tech/avro-php": "^3.0|^4.0" + "flix-tech/avro-php": "^3.0|^4.0", + "symfony/console": "^4.3|^5.1" }, "require-dev": { - "phpunit/phpunit": "^9.3", - "phpstan/phpstan": "^0.12", - "squizlabs/php_codesniffer": "^3.4.2", "friendsofphp/php-cs-fixer": "^2.15", "infection/infection": "^0.20.2", - "rregeer/phpunit-coverage-check": "^0.3" + "phpstan/phpstan": "^1.2", + "phpunit/phpunit": "^9.3", + "rregeer/phpunit-coverage-check": "^0.3", + "squizlabs/php_codesniffer": "^3.4.2" }, "bin": [ "bin/avro-cli" From 81b9eda40718b44e76c2ff4cdbe6898b8a5e0537 Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 9 Dec 2021 23:08:23 +0100 Subject: [PATCH 2/9] Adjust ignored errors --- phpstan.neon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 2ee099c..a648eff 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,6 +4,6 @@ parameters: checkGenericClassInNonGenericObjectType: false ignoreErrors: - "#Call to function token_get_all\\(\\) on a separate line has no effect.#" - - "#Strict comparison using === between array&nonEmpty and ',' will always evaluate to false.#" - - "#Strict comparison using === between array&nonEmpty and ';' will always evaluate to false.#" + - "#Strict comparison using === between non-empty-array and ',' will always evaluate to false.#" + - "#Strict comparison using === between non-empty-array and ';' will always evaluate to false.#" - "#Method PhpKafka\\\\\\PhpAvroSchemaGenerator\\\\\\Optimizer\\\\\\OptimizerInterface::optimize\\(\\) invoked with 2 parameters, 1 required.#" From 8945531c34eac33ee4a1dfb86e36ba0588e4806c Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 9 Dec 2021 23:09:02 +0100 Subject: [PATCH 3/9] Fix phpstan errors --- src/Command/SubSchemaMergeCommand.php | 2 ++ src/Parser/TokenParser.php | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Command/SubSchemaMergeCommand.php b/src/Command/SubSchemaMergeCommand.php index 0045c22..d518efa 100644 --- a/src/Command/SubSchemaMergeCommand.php +++ b/src/Command/SubSchemaMergeCommand.php @@ -6,6 +6,7 @@ use PhpKafka\PhpAvroSchemaGenerator\Optimizer\FieldOrderOptimizer; use PhpKafka\PhpAvroSchemaGenerator\Optimizer\FullNameOptimizer; +use PhpKafka\PhpAvroSchemaGenerator\Optimizer\OptimizerInterface; use PhpKafka\PhpAvroSchemaGenerator\Optimizer\PrimitiveSchemaOptimizer; use PhpKafka\PhpAvroSchemaGenerator\Registry\SchemaRegistry; use PhpKafka\PhpAvroSchemaGenerator\Merger\SchemaMerger; @@ -76,6 +77,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $merger = new SchemaMerger($registry, $outputDirectory); + /** @var OptimizerInterface $optimizerClass */ foreach ($this->optimizerOptionMapping as $optionName => $optimizerClass) { if (true === (bool) $input->getOption($optionName)) { $merger->addOptimizer(new $optimizerClass()); diff --git a/src/Parser/TokenParser.php b/src/Parser/TokenParser.php index bef4718..d8e08a2 100644 --- a/src/Parser/TokenParser.php +++ b/src/Parser/TokenParser.php @@ -39,7 +39,7 @@ class TokenParser /** * @var string */ - private $className; + private string $className; /** * @var string @@ -200,8 +200,10 @@ public function getProperties(string $classPath): array public function getPropertyClass(ReflectionProperty $property, bool $ignorePrimitive = true) { $type = null; - $phpVersion = false === phpversion() ? '7.0.0' : phpversion(); - // Get is explicit type decralation if possible + /** @var false|string $phpVersionResult */ + $phpVersionResult = phpversion(); + $phpVersion = false === $phpVersionResult ? '7.0.0' : $phpVersionResult; + // Get is explicit type declaration if possible if (version_compare($phpVersion, '7.4.0', '>=') && null !== $property->getType()) { $reflectionType = $property->getType(); From fdf31db447fdaf2cbb159075adcd93d7c59f8515 Mon Sep 17 00:00:00 2001 From: Marko Date: Fri, 10 Dec 2021 00:09:27 +0100 Subject: [PATCH 4/9] Bump infection --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 31e95d3..4a93cdb 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.15", - "infection/infection": "^0.20.2", + "infection/infection": "^0.25", "phpstan/phpstan": "^1.2", "phpunit/phpunit": "^9.3", "rregeer/phpunit-coverage-check": "^0.3", From 074cda7ef1ce24ca183c925db3efa871e2b13956 Mon Sep 17 00:00:00 2001 From: Marko Date: Fri, 10 Dec 2021 00:19:25 +0100 Subject: [PATCH 5/9] Add missing command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8ad1867..7dae24c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean code-style coverage help static-analysis update-dependencies install-dependencies infection-testing +.PHONY: clean code-style coverage fix-code-style help static-analysis update-dependencies install-dependencies infection-testing .DEFAULT_GOAL := coverage PHPUNIT = ./vendor/bin/phpunit -c ./phpunit.xml From f935489557790b2f090b8e9595c9dea4b6e151da Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 13 Dec 2021 20:16:36 +0100 Subject: [PATCH 6/9] Improve infection --- tests/Unit/Merger/SchemaMergerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Unit/Merger/SchemaMergerTest.php b/tests/Unit/Merger/SchemaMergerTest.php index aede98d..73b1248 100644 --- a/tests/Unit/Merger/SchemaMergerTest.php +++ b/tests/Unit/Merger/SchemaMergerTest.php @@ -403,8 +403,9 @@ public function testMerge() $optimizer->expects(self::once())->method('optimize')->with($definition)->willReturn($definition); $merger = new SchemaMerger($schemaRegistry, '/tmp/foobar'); $merger->addOptimizer($optimizer); - $merger->merge(true); + $mergedFiles = $merger->merge(true); + self::assertEquals(1, $mergedFiles); self::assertFileExists('/tmp/foobar/com.example.Book.avsc'); unlink('/tmp/foobar/com.example.Book.avsc'); rmdir('/tmp/foobar'); From 1592b5854dc1bf2e8621919af1878b33c7c9d9fc Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 13 Dec 2021 20:17:15 +0100 Subject: [PATCH 7/9] Ignore infection where code coverage is ignored --- src/Parser/TokenParser.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Parser/TokenParser.php b/src/Parser/TokenParser.php index d8e08a2..bf0435e 100644 --- a/src/Parser/TokenParser.php +++ b/src/Parser/TokenParser.php @@ -143,6 +143,7 @@ public function getNamespace(): string * * @return array A list with all found use statements. * @codeCoverageIgnore + * @infection-ignore-all */ public function parseUseStatements($namespaceName) { @@ -196,6 +197,7 @@ public function getProperties(string $classPath): array * @throws \RuntimeException * @return string|null Type of the property (content of var annotation) * @codeCoverageIgnore + * @infection-ignore-all */ public function getPropertyClass(ReflectionProperty $property, bool $ignorePrimitive = true) { @@ -283,6 +285,7 @@ public function getPropertyClass(ReflectionProperty $property, bool $ignorePrimi * * @return string|null Fully qualified name of the type, or null if it could not be resolved * @codeCoverageIgnore + * @infection-ignore-all */ private function tryResolveFqn($type, ReflectionClass $class, Reflector $member) { @@ -326,6 +329,7 @@ private function tryResolveFqn($type, ReflectionClass $class, Reflector $member) * * @return string|null Fully qualified name of the type, or null if it could not be resolved * @codeCoverageIgnore + * @infection-ignore-all */ private function tryResolveFqnInTraits($type, ReflectionClass $class, Reflector $member) { @@ -391,6 +395,7 @@ private function next($docCommentIsComment = true) * * @return array A list with all found class names for a use statement. * @codeCoverageIgnore + * @infection-ignore-all */ private function parseUseStatement() { From 8637a90a7f4a46e3f32b4b9a470669a511c6498e Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 13 Dec 2021 20:24:09 +0100 Subject: [PATCH 8/9] Added missing binary --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7dae24c..0a3d087 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ PHPUNIT = ./vendor/bin/phpunit -c ./phpunit.xml PHPSTAN = ./vendor/bin/phpstan PHPCS = ./vendor/bin/phpcs --extensions=php -PHPCBF = ./vendor/bin/ +PHPCBF = ./vendor/bin/phpcbf INFECTION = ./vendor/bin/infection CONSOLE = ./bin/console COVCHECK = ./vendor/bin/coverage-check From 629368a06cd61af5c1078b618715d82fbbf90a5b Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 13 Dec 2021 20:24:34 +0100 Subject: [PATCH 9/9] Fix CS --- src/Generator/SchemaGenerator.php | 1 - src/Merger/SchemaMergerInterface.php | 1 - src/PhpClass/PhpClassProperty.php | 1 - src/Registry/ClassRegistry.php | 1 - src/Registry/ClassRegistryInterface.php | 1 - src/Registry/SchemaRegistryInterface.php | 1 - 6 files changed, 6 deletions(-) diff --git a/src/Generator/SchemaGenerator.php b/src/Generator/SchemaGenerator.php index aad2aca..432eafb 100644 --- a/src/Generator/SchemaGenerator.php +++ b/src/Generator/SchemaGenerator.php @@ -11,7 +11,6 @@ final class SchemaGenerator implements SchemaGeneratorInterface { - /** * @var int[] */ diff --git a/src/Merger/SchemaMergerInterface.php b/src/Merger/SchemaMergerInterface.php index 93f3c6e..ea847a3 100644 --- a/src/Merger/SchemaMergerInterface.php +++ b/src/Merger/SchemaMergerInterface.php @@ -10,7 +10,6 @@ interface SchemaMergerInterface { - /** * @return SchemaRegistryInterface */ diff --git a/src/PhpClass/PhpClassProperty.php b/src/PhpClass/PhpClassProperty.php index 01e9815..5a62467 100644 --- a/src/PhpClass/PhpClassProperty.php +++ b/src/PhpClass/PhpClassProperty.php @@ -6,7 +6,6 @@ class PhpClassProperty implements PhpClassPropertyInterface { - /** * @var string */ diff --git a/src/Registry/ClassRegistry.php b/src/Registry/ClassRegistry.php index c282794..e768895 100644 --- a/src/Registry/ClassRegistry.php +++ b/src/Registry/ClassRegistry.php @@ -14,7 +14,6 @@ final class ClassRegistry implements ClassRegistryInterface { - /** * @var array */ diff --git a/src/Registry/ClassRegistryInterface.php b/src/Registry/ClassRegistryInterface.php index 197c67b..1559ec1 100644 --- a/src/Registry/ClassRegistryInterface.php +++ b/src/Registry/ClassRegistryInterface.php @@ -8,7 +8,6 @@ interface ClassRegistryInterface { - /** * @param string $classDirectory * @return ClassRegistryInterface diff --git a/src/Registry/SchemaRegistryInterface.php b/src/Registry/SchemaRegistryInterface.php index a0aa470..65d2efa 100644 --- a/src/Registry/SchemaRegistryInterface.php +++ b/src/Registry/SchemaRegistryInterface.php @@ -8,7 +8,6 @@ interface SchemaRegistryInterface { - /** * @param string $schemaTemplateDirectory * @return SchemaRegistryInterface