Skip to content

CallableThisArrayToAnonymousFunctionRector adds the return statement to void functions #1499

@Aerendir

Description

@Aerendir
    ---------- begin diff ----------
--- Original
+++ New
@@ -247,7 +247,9 @@
         // Add a log message
         $this->logger->debug(\Safe\sprintf('<success-nobg>(%s)</success-nobg> Object <success-nobg>%s</success-nobg> is of kind <success-nobg>%s</success-nobg>.', $displayPath, $objectKind, $type));

-        set_error_handler([$this, '_HydrationErrorHandler']);
+        set_error_handler(function (int $errno, string $errstr) : void {
+            return $this->_HydrationErrorHandler($errno, $errstr);
+        });

         // Hydrate the needed object
         switch ($type) {
    ----------- end diff -----------

Applied rectors:

 * Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector

The rector correctly transforms the use of the array into an anonymous function and correctly sets the return type hint.

But as thi method doesn't return anything, it should not add also the return value.

The function should be:

        set_error_handler(function (int $errno, string $errstr) : void {
-            return $this->_HydrationErrorHandler($errno, $errstr);
+            $this->_HydrationErrorHandler($errno, $errstr);
        });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions