Skip to content

Commit

Permalink
Avoid to call not accessible toString() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys authored and OskarStark committed Jan 6, 2020
1 parent ed4c577 commit 8283fb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Model/ModelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function setUpBeforeClass(): void
}
}

public function valueObjectDataProvider()
public function valueObjectDataProvider(): array
{
return [
'value object with toString implementation' => [ValueObjectWithToStringImpl::class],
Expand All @@ -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'));

Expand Down

0 comments on commit 8283fb9

Please sign in to comment.