Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created December 6, 2023 13:57
Show Gist options
  • Save tsh-code/0137a2d8177e4c75d8e0bb4190b59666 to your computer and use it in GitHub Desktop.
Save tsh-code/0137a2d8177e4c75d8e0bb4190b59666 to your computer and use it in GitHub Desktop.
<?php
// 1.
$isUserModerator = $user->isType(‘moderator’);
class User {
// . . .
public function isType(string $type): bool
{
return $this->type === $type;
}
// . . .
}
// 2.
$isUserModerator = $user->isModerator();
class User {
// . . .
function isModerator(): bool
{
return ‘moderator’ === $user->type;
}
// . . .
}
// 3.
$isUserModerator = $user->isType(User::TYPE_MODERATOR);
class User {
public const TYPE_MODERATOR = ‘moderator’;
// . . .
public function isType(string $type): bool
{
return $this->type === $type;
}
// . . .
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment