Skip to content

Instantly share code, notes, and snippets.

@funivan
Last active June 13, 2018 10:34
Show Gist options
  • Select an option

  • Save funivan/7f131ba149eef5947722ad1dc86d9c49 to your computer and use it in GitHub Desktop.

Select an option

Save funivan/7f131ba149eef5947722ad1dc86d9c49 to your computer and use it in GitHub Desktop.
<?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