mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-07 15:36:34 +02:00
PHP8
This commit is contained in:
@@ -4,16 +4,11 @@ namespace DesignPatterns\Structural\DataMapper;
|
||||
|
||||
class StorageAdapter
|
||||
{
|
||||
private array $data = [];
|
||||
|
||||
public function __construct(array $data)
|
||||
public function __construct(private array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function find(int $id)
|
||||
|
@@ -4,9 +4,6 @@ namespace DesignPatterns\Structural\DataMapper;
|
||||
|
||||
class User
|
||||
{
|
||||
private string $username;
|
||||
private string $email;
|
||||
|
||||
public static function fromState(array $state): User
|
||||
{
|
||||
// validate state before accessing keys!
|
||||
@@ -17,12 +14,8 @@ class User
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct(string $username, string $email)
|
||||
public function __construct(private string $username, private string $email)
|
||||
{
|
||||
// validate parameters before setting them!
|
||||
|
||||
$this->username = $username;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
|
@@ -6,11 +6,8 @@ use InvalidArgumentException;
|
||||
|
||||
class UserMapper
|
||||
{
|
||||
private StorageAdapter $adapter;
|
||||
|
||||
public function __construct(StorageAdapter $storage)
|
||||
public function __construct(private StorageAdapter $adapter)
|
||||
{
|
||||
$this->adapter = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user