Skip to content

[2.x] Narrow argument type for is/isNot #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
use Exception;
use Iterator;
use IteratorAggregate;
use UnitEnum;

trait Comparable
{
public function is(mixed $enum): bool
public function is(UnitEnum $enum): bool
{
return $this === $enum;
}

public function isNot(mixed $enum): bool
public function isNot(UnitEnum $enum): bool
{
return ! $this->is($enum);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Pest/ComparableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
expect(Role::ADMIN->is(Role::ADMIN))->toBeTrue();

expect(Role::ADMIN->is(Role::GUEST))->toBeFalse();
expect(Role::ADMIN->is('admin'))->toBeFalse();
});

it('the isNot method checks for inequality', function () {
Expand All @@ -16,7 +15,6 @@
expect(Role::ADMIN->isNot(Role::GUEST))->toBeTrue();

expect(Role::ADMIN->isNot(Role::ADMIN))->toBeFalse();
expect(Role::ADMIN->isNot('admin'))->toBeTrue();
});

it('the in method checks for presence in an array', function () {
Expand Down
Loading