Skip to content

Commit

Permalink
Avoid call top level function (#6859)
Browse files Browse the repository at this point in the history
  • Loading branch information
sormes authored Feb 15, 2021
1 parent 2127a5d commit 04baa16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Admin/BaseFieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public function getFieldValue($object, $fieldName)

// prefer the method or the property path given in the code option
$accessor = $this->getOption('accessor', $fieldName);
if (\is_callable($accessor)) {
if (!\is_string($accessor) && \is_callable($accessor)) {
return $accessor($object);
} elseif (!\is_string($accessor) && !$accessor instanceof PropertyPathInterface) {
throw new \TypeError(sprintf(
Expand Down
8 changes: 8 additions & 0 deletions tests/Admin/BaseFieldDescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ public function testGetFieldValueWithAccessor(): void
$this->assertSame(42, $description->getFieldValue($mock, 'fake'));
}

public function testGetFieldValueWithTopLevelFunctionName(): void
{
$description = new FieldDescription('microtime');
$mock = $this->getMockBuilder(\stdClass::class)->addMethods(['getMicrotime'])->getMock();
$mock->expects($this->once())->method('getMicrotime')->willReturn(42);
$this->assertSame(42, $description->getFieldValue($mock, 'microtime'));
}

public function testGetFieldValueWithCallableAccessor(): void
{
$description = new FieldDescription('name', [
Expand Down

0 comments on commit 04baa16

Please sign in to comment.