Skip to content

Commit

Permalink
[Rules] Skip Closure/callable on NarrowPublicClassMethodParamTypeRule (
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Jun 18, 2024
1 parent df83404 commit a0812a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Printer/CollectorMetadataPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function printParamTypesToString(ClassMethod $classMethod, ?string $class
}

$printedParamType = $this->printerStandard->prettyPrint([$paramType]);
$printedParamType = str_replace('\Closure', 'callable', $printedParamType);
$printedParamType = ltrim($printedParamType, '\\');
$printedParamType = str_replace('|\\', '|', $printedParamType);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\TypePerfect\Tests\Rules\ReturnNullOverFalseRule\Fixture;

final class SkipCallable
{
public function map(callable $mapper): array
{
return [];
}

public function run()
{
$this->map(function () {});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\TypePerfect\Tests\Rules\ReturnNullOverFalseRule\Fixture;

final class SkipClosure
{
public function map(\Closure $mapper): array
{
return [];
}

public function run()
{
$this->map(function () {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public static function provideData(): Iterator
__DIR__ . '/Fixture/SkipSelf.php',
], []];

yield [[
__DIR__ . '/Fixture/SkipClosure.php',
], []];

yield [[
__DIR__ . '/Fixture/SkipCallable.php',
], []];

$argErrorMessage = sprintf(NarrowPublicClassMethodParamTypeRule::ERROR_MESSAGE, 'int');
yield [[
__DIR__ . '/Fixture/HandleDefaultValue.php',
Expand Down

0 comments on commit a0812a4

Please sign in to comment.