Skip to content

Commit

Permalink
Represent callable strings as strings (#1741)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Bouma <alex@bouma.me>
Co-authored-by: Michi Hoffmann <cleptric@users.noreply.github.com>
  • Loading branch information
3 people authored May 28, 2024
1 parent 7a51be0 commit 6051f41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Serializer/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected function serializeValue($value)
*/
protected function serializeCallable($callable): string
{
if (\is_string($callable) && !\function_exists($callable)) {
if (\is_string($callable)) {
return $callable;
}

Expand All @@ -292,7 +292,7 @@ protected function serializeCallable($callable): string
if (\is_array($callable)) {
$reflection = new \ReflectionMethod($callable[0], $callable[1]);
$class = $reflection->getDeclaringClass();
} elseif ($callable instanceof \Closure || (\is_string($callable) && \function_exists($callable))) {
} elseif ($callable instanceof \Closure) {
$reflection = new \ReflectionFunction($callable);
$class = null;
} elseif (\is_object($callable) && method_exists($callable, '__invoke')) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Serializer/AbstractSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ public function serializableCallableProvider(): array
'callable' => $callableWithoutNamespaces,
'expected' => 'Lambda void {closure} [int|null param1_70ns]',
],
[
// This is (a example of) a PHP provided function that is technically callable but we want to ignore that because it causes more false positives than it helps
'callable' => 'header',
'expected' => 'header',
],
[
'callable' => __METHOD__,
'expected' => __METHOD__,
Expand Down

0 comments on commit 6051f41

Please sign in to comment.