Skip to content

Commit

Permalink
[Rules] Skip enum on NarrowPublicClassMethodParamTypeRule (#19)
Browse files Browse the repository at this point in the history
* Add test for skip Enum

* fix test

* Fix

* rectify

* clean up
  • Loading branch information
samsonasik authored Jun 18, 2024
1 parent 35a977b commit 9388c31
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Printer/CollectorMetadataPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPStan\Type\BooleanType;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\ClosureType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\MixedType;
Expand Down Expand Up @@ -179,6 +180,10 @@ private function printTypeToString(Type $type): string
return 'callable';
}

if ($type instanceof EnumCaseObjectType) {
return $type->getClassName();
}

return $type->describe(VerbosityLevel::typeOnly());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

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

use Rector\TypePerfect\Tests\Rules\NarrowPublicClassMethodParamTypeRule\Source\PickReasonEnum;

class SkipEnum
{
public function pick(PickReasonEnum $pickReasonEnum): void
{
}

public function run()
{
$this->pick(PickReasonEnum::BarcodeIssue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public static function provideData(): Iterator
__DIR__ . '/Fixture/SkipCallable.php',
], []];

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

$argErrorMessage = sprintf(NarrowPublicClassMethodParamTypeRule::ERROR_MESSAGE, 'int');
yield [[
__DIR__ . '/Fixture/HandleDefaultValue.php',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Rector\TypePerfect\Tests\Rules\NarrowPublicClassMethodParamTypeRule\Source;

enum PickReasonEnum: string
{
case BarcodeIssue = 'barcode_issue';
case EmptyLocation = 'empty_location';
}

0 comments on commit 9388c31

Please sign in to comment.