From 8283fb9c82c97a76ddb11a08d45e91efc629f540 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Mon, 6 Jan 2020 12:35:15 -0300 Subject: [PATCH] Avoid to call not accessible `toString()` methods --- src/Model/ModelManager.php | 6 +++--- tests/Model/ModelManagerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index ebca1530d..fda9da020 100644 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -640,12 +640,12 @@ private function getValueFromType($value, Type $type, string $fieldType, Abstrac return (string) $type->convertToPHPValue($value, $platform); } - // some libraries may have `toString` implementation - if (method_exists($value, 'toString')) { + // some libraries may have `toString()` implementation + if (\is_callable([$value, 'toString'])) { return $value->toString(); } - // final fallback to magic __toString which it may throw an exception in 7.4 + // final fallback to magic `__toString()` which may throw an exception in 7.4 if (method_exists($value, '__toString')) { return $value->__toString(); } diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index 516724162..497c340ba 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -75,7 +75,7 @@ public static function setUpBeforeClass(): void } } - public function valueObjectDataProvider() + public function valueObjectDataProvider(): array { return [ 'value object with toString implementation' => [ValueObjectWithToStringImpl::class], @@ -86,7 +86,7 @@ public function valueObjectDataProvider() /** * @dataProvider valueObjectDataProvider */ - public function testGetIdentifierValuesWhenIdentifierIsValueObjectWithToStringMethod($vbClassName) + public function testGetIdentifierValuesWhenIdentifierIsValueObjectWithToStringMethod(string $vbClassName): void { $entity = new UuidBinaryEntity(new $vbClassName('a7ef873a-e7b5-11e9-81b4-2a2ae2dbcce4'));