Last active
June 13, 2018 10:34
-
-
Save funivan/7f131ba149eef5947722ad1dc86d9c49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * This class is ok. | |
| */ | |
| class User { | |
| /** | |
| * @var string | |
| */ | |
| private $name; | |
| public function __construct(string $name) { | |
| $this->name = $name; | |
| } | |
| public function getName() : string { | |
| return $this->name; | |
| } | |
| } | |
| class Auth { | |
| /** | |
| * @var User|null | |
| */ | |
| private $user; | |
| /** | |
| * This method is ok. | |
| */ | |
| public function __construct() { | |
| if (random_int(0, 1) === 1) { | |
| $this->user = new User('User Name'); | |
| } | |
| } | |
| public function isAuthorized() : bool { | |
| return $this->getUser() !== null; | |
| } | |
| public function getUser() : ?User { | |
| return $this->user; | |
| } | |
| } | |
| class ShowUserInfo { | |
| /** | |
| * This method is ok. | |
| * @param User $user | |
| */ | |
| public function show(User $user) { | |
| echo $user->getName(); | |
| } | |
| } | |
| $auth = new Auth(); | |
| if ($auth->isAuthorized()) { | |
| echo "Hello ".$auth->getUser()->getName()."\n" | |
| } else { | |
| echo "Hi\n" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment