Skip to content

Commit

Permalink
7.0: Null coalescing operator and Anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhukMax committed Aug 20, 2021
1 parent ab88205 commit 1f3bd4f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class User
*/
public function __construct(string $name, $city, $birthday = null)
{
$this->name = isset($name) ? $name : '';
$this->name = $name ?? '';
$this->city = $city;
$this->birthday = $birthday;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getRole()

public function setRole(string $role = self::CUSTOMER)
{
$this->role = isset($this->role) ? $this->role : $role;
$this->role = $this->role ?? $role;
}

public function getAvatar(): string
Expand All @@ -91,8 +91,16 @@ public function getAvatar(): string
}
}

public function setLogger(LoggerInterface $logger)
/**
* @param LoggerInterface|null $logger
*/
public function setLogger($logger = null)
{
$this->logger = $logger;
$this->logger = $logger ?? new class implements LoggerInterface {
public function log($message)
{
echo $message;
}
};
}
}

0 comments on commit 1f3bd4f

Please sign in to comment.