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'));