This commit is contained in:
Dominik Liebler
2021-04-12 14:04:45 +02:00
parent 5c5d453506
commit 4678b5d86f
50 changed files with 992 additions and 1430 deletions

View File

@@ -6,11 +6,8 @@ use Psr\Http\Message\RequestInterface;
abstract class Handler
{
private ?Handler $successor = null;
public function __construct(Handler $handler = null)
public function __construct(private ?Handler $successor = null)
{
$this->successor = $handler;
}
/**

View File

@@ -7,13 +7,9 @@ use Psr\Http\Message\RequestInterface;
class HttpInMemoryCacheHandler extends Handler
{
private array $data;
public function __construct(array $data, ?Handler $successor = null)
public function __construct(private array $data, ?Handler $successor = null)
{
parent::__construct($successor);
$this->data = $data;
}
protected function processing(RequestInterface $request): ?string

View File

@@ -8,15 +8,12 @@ namespace DesignPatterns\Behavioral\Command;
*/
class AddMessageDateCommand implements UndoableCommand
{
private Receiver $output;
/**
* Each concrete command is built with different receivers.
* There can be one, many or completely no receivers, but there can be other commands in the parameters.
*/
public function __construct(Receiver $console)
public function __construct(private Receiver $output)
{
$this->output = $console;
}
/**

View File

@@ -8,15 +8,12 @@ namespace DesignPatterns\Behavioral\Command;
*/
class HelloCommand implements Command
{
private Receiver $output;
/**
* Each concrete command is built with different receivers.
* There can be one, many or completely no receivers, but there can be other commands in the parameters
*/
public function __construct(Receiver $console)
public function __construct(private Receiver $output)
{
$this->output = $console;
}
/**

View File

@@ -4,13 +4,8 @@ namespace DesignPatterns\Behavioral\Iterator;
class Book
{
private string $author;
private string $title;
public function __construct(string $title, string $author)
public function __construct(private string $title, private string $author)
{
$this->author = $author;
$this->title = $title;
}
public function getAuthor(): string

View File

@@ -4,14 +4,8 @@ namespace DesignPatterns\Behavioral\Mediator;
class UserRepositoryUiMediator implements Mediator
{
private UserRepository $userRepository;
private Ui $ui;
public function __construct(UserRepository $userRepository, Ui $ui)
public function __construct(private UserRepository $userRepository, private Ui $ui)
{
$this->userRepository = $userRepository;
$this->ui = $ui;
$this->userRepository->setMediator($this);
$this->ui->setMediator($this);
}

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Memento;
class Memento
{
private State $state;
public function __construct(State $stateToSave)
public function __construct(private State $state)
{
$this->state = $stateToSave;
}
public function getState(): State

View File

@@ -4,7 +4,7 @@ namespace DesignPatterns\Behavioral\Memento;
use InvalidArgumentException;
class State
class State implements \Stringable
{
const STATE_CREATED = 'created';
const STATE_OPENED = 'opened';

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\NullObject;
class Service
{
private Logger $logger;
public function __construct(Logger $logger)
public function __construct(private Logger $logger)
{
$this->logger = $logger;
}
/**

View File

@@ -12,7 +12,6 @@ use SplObserver;
*/
class User implements SplSubject
{
private string $email;
private SplObjectStorage $observers;
public function __construct()
@@ -32,7 +31,6 @@ class User implements SplSubject
public function changeEmail(string $email)
{
$this->email = $email;
$this->notify();
}

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Specification;
class Item
{
private float $price;
public function __construct(float $price)
public function __construct(private float $price)
{
$this->price = $price;
}
public function getPrice(): float

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Specification;
class NotSpecification implements Specification
{
private Specification $specification;
public function __construct(Specification $specification)
public function __construct(private Specification $specification)
{
$this->specification = $specification;
}
public function isSatisfiedBy(Item $item): bool

View File

@@ -4,13 +4,8 @@ namespace DesignPatterns\Behavioral\Specification;
class PriceSpecification implements Specification
{
private ?float $maxPrice;
private ?float $minPrice;
public function __construct(?float $minPrice, ?float $maxPrice)
public function __construct(private ?float $minPrice, private ?float $maxPrice)
{
$this->minPrice = $minPrice;
$this->maxPrice = $maxPrice;
}
public function isSatisfiedBy(Item $item): bool

View File

@@ -7,8 +7,6 @@ interface Comparator
/**
* @param mixed $a
* @param mixed $b
*
* @return int
*/
public function compare($a, $b): int;
}

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Strategy;
class Context
{
private Comparator $comparator;
public function __construct(Comparator $comparator)
public function __construct(private Comparator $comparator)
{
$this->comparator = $comparator;
}
public function executeStrategy(array $elements): array

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Visitor;
class Group implements Role
{
private string $name;
public function __construct(string $name)
public function __construct(private string $name)
{
$this->name = $name;
}
public function getName(): string

View File

@@ -4,11 +4,8 @@ namespace DesignPatterns\Behavioral\Visitor;
class User implements Role
{
private string $name;
public function __construct(string $name)
public function __construct(private string $name)
{
$this->name = $name;
}
public function getName(): string