From 06f576be1eee44ed20913163c23514abe0f0ccf6 Mon Sep 17 00:00:00 2001 From: Mitchell <37925797+ping-localhost@users.noreply.github.com> Date: Fri, 21 Sep 2018 10:17:35 +0200 Subject: [PATCH] Phpstan upgrade (#5) * Update phpstan/phpstan requirement from ^0.9.2 to ^0.10.3 Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Commits](https://github.com/phpstan/phpstan/commits/0.10.3) Signed-off-by: dependabot[bot] * Made changes for the PHPStan upgrade --- composer.json | 26 ++++++++++----------- src/Metadata/AnonymizedPropertyMetadata.php | 2 +- src/Processor/AnonymizeProcessor.php | 9 ++++++- tests/Processor/AnonymizeProcessorTest.php | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index ceabb69..33fcd4f 100644 --- a/composer.json +++ b/composer.json @@ -26,24 +26,24 @@ }, "require": { "php": "^7.1.0", - "doctrine/annotations": "^1.6", - "doctrine/cache": "^1.7.0", - "doctrine/common": "^2.8.0", - "fzaninotto/faker": "^1.7", - "jms/metadata": "^1.6", + "doctrine/annotations": "^1.6.0", + "doctrine/cache": "^1.8.0", + "doctrine/common": "^2.9.0", + "fzaninotto/faker": "^1.8.0", + "jms/metadata": "^1.6.0", "symfony/dependency-injection": "^3.4.12|^4.0.11", "symfony/framework-bundle": "^3.4.12|^4.0.11", "symfony/http-foundation": "^3.4.14|^4.0.14|^4.1.3", "symfony/yaml": "^3.4.12|^4.0.11" }, "require-dev": { - "hostnet/phpcs-tool": "^8.0.1", - "jakub-onderka/php-parallel-lint": "^1.0", - "nyholm/symfony-bundle-test": "^1.4", - "phpstan/phpstan": "^0.9.2", - "phpunit/phpunit": "^7.0", - "sebastian/phpcpd": "^4.0", - "sensiolabs/security-checker": "^4.1" + "hostnet/phpcs-tool": "^8.2.0", + "jakub-onderka/php-parallel-lint": "^1.0.0", + "nyholm/symfony-bundle-test": "^1.4.0", + "phpstan/phpstan": "^0.10.3", + "phpunit/phpunit": "^7.3.3", + "sebastian/phpcpd": "^4.0.0", + "sensiolabs/security-checker": "^4.1.8" }, "conflict": { "paragonie/random_compat": "<2.0.0" @@ -70,7 +70,7 @@ "@composer phpstan" ], "phpcpd": "./vendor/bin/phpcpd src/", - "phpstan": "./vendor/bin/phpstan analyse --level=4 src", + "phpstan": "./vendor/bin/phpstan analyse --level=3 src", "security-checker": "./vendor/bin/security-checker security:check ./composer.lock --end-point=http://security.sensiolabs.org/check_lock", "syntax-check": [ "./vendor/bin/parallel-lint --exclude vendor .", diff --git a/src/Metadata/AnonymizedPropertyMetadata.php b/src/Metadata/AnonymizedPropertyMetadata.php index 01a587d..31db944 100644 --- a/src/Metadata/AnonymizedPropertyMetadata.php +++ b/src/Metadata/AnonymizedPropertyMetadata.php @@ -93,7 +93,7 @@ public function setGenerator($generator): void private function shouldBeExcluded($value): bool { - if (!is_scalar($this) && \is_object($value) && !method_exists($value, '__toString')) { + if (\is_object($value) && false === method_exists($value, '__toString')) { return false; } diff --git a/src/Processor/AnonymizeProcessor.php b/src/Processor/AnonymizeProcessor.php index 82fc65d..c396370 100644 --- a/src/Processor/AnonymizeProcessor.php +++ b/src/Processor/AnonymizeProcessor.php @@ -30,7 +30,14 @@ public function anonymize($object): void { /** @var AnonymizedClassMetadata $metadata */ if (null === ($metadata = $this->metadata_factory->getMetadataForClass(\get_class($object)))) { - throw new \RuntimeException(sprintf("Couldn't load the metadata for class %s,", \get_class($object))); + throw new \RuntimeException(sprintf("Couldn't load the metadata for class %s.", \get_class($object))); + } + + if (false === ($metadata instanceof AnonymizedClassMetadata)) { + throw new \RuntimeException(sprintf( + 'We expected to receive a AnonymizedClassMetadata-class, but got %s.', + \get_class($metadata) + )); } $property_metadata = $this->getPropertyMetadata($metadata); diff --git a/tests/Processor/AnonymizeProcessorTest.php b/tests/Processor/AnonymizeProcessorTest.php index 8fca119..4f428ef 100644 --- a/tests/Processor/AnonymizeProcessorTest.php +++ b/tests/Processor/AnonymizeProcessorTest.php @@ -36,7 +36,7 @@ public function testAnonymizeNoMetadata(): void $this->metadata_factory->getMetadataForClass(EmptyObject::class)->willReturn(null); $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage(sprintf("Couldn't load the metadata for class %s,", EmptyObject::class)); + $this->expectExceptionMessage(sprintf("Couldn't load the metadata for class %s.", EmptyObject::class)); $this->anonymize_processor->anonymize($object); }