@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | use Psr\Http\Message\RequestInterface; |
| 6 | 6 | |
| 7 | -class DatabaseHandler extends Handler |
|
| 8 | -{ |
|
| 7 | +class DatabaseHandler extends Handler |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * Database processing. |
| 11 | 11 | * |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Observer\Npl; |
| 6 | 6 | |
| 7 | -interface SubjectInterface |
|
| 8 | -{ |
|
| 7 | +interface SubjectInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * Attach an ObserverInterface. |
| 11 | 11 | * |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | public function attach(ObserverInterface $observer) |
| 41 | 41 | { |
| 42 | - if (! in_array($observer, $this->observers, true)) { |
|
| 42 | + if ( ! in_array($observer, $this->observers, true)) { |
|
| 43 | 43 | $this->observers[] = $observer; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Observer\Npl; |
| 6 | 6 | |
| 7 | -class Subject implements SubjectInterface |
|
| 8 | -{ |
|
| 7 | +class Subject implements SubjectInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var string |
| 11 | 11 | */ |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param string $name |
| 28 | 28 | */ |
| 29 | - public function __construct(string $name = '') |
|
| 30 | - { |
|
| 29 | + public function __construct(string $name = '') |
|
| 30 | + {
|
|
| 31 | 31 | $this->name = $name; |
| 32 | 32 | $this->observers = []; |
| 33 | 33 | } |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param \DesignPattern\Behavioral\Observer\Npl\ObserverInterface $observer |
| 39 | 39 | */ |
| 40 | - public function attach(ObserverInterface $observer) |
|
| 41 | - { |
|
| 42 | - if (! in_array($observer, $this->observers, true)) { |
|
| 40 | + public function attach(ObserverInterface $observer) |
|
| 41 | + {
|
|
| 42 | + if (! in_array($observer, $this->observers, true)) {
|
|
| 43 | 43 | $this->observers[] = $observer; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @param \DesignPattern\Behavioral\Observer\Npl\ObserverInterface $observer |
| 51 | 51 | */ |
| 52 | - public function detach(ObserverInterface $observer) |
|
| 53 | - { |
|
| 52 | + public function detach(ObserverInterface $observer) |
|
| 53 | + {
|
|
| 54 | 54 | $key = array_search($observer, $this->observers, true); |
| 55 | - if ($key !== false) { |
|
| 55 | + if ($key !== false) {
|
|
| 56 | 56 | unset($this->observers[$key]); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Notify an observer. |
| 62 | 62 | */ |
| 63 | - public function notify() |
|
| 64 | - { |
|
| 63 | + public function notify() |
|
| 64 | + {
|
|
| 65 | 65 | /** @var \DesignPattern\Behavioral\Observer\Npl\Observer $observer */ |
| 66 | - foreach ($this->observers as $observer) { |
|
| 66 | + foreach ($this->observers as $observer) {
|
|
| 67 | 67 | $observer->update($this); |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public function doSomethingReport(): void |
| 77 | 77 | { |
| 78 | 78 | /** @var \DesignPattern\Behavioral\Observer\Npl\Observer $observer */ |
| 79 | - foreach ($this->observers as $observer) { |
|
| 79 | + foreach ($this->observers as $observer) {
|
|
| 80 | 80 | $observer->report(random_int(20, 29), 'Something happened.', $this); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Observer\Npl; |
| 6 | 6 | |
| 7 | -class Observer implements ObserverInterface |
|
| 8 | -{ |
|
| 7 | +class Observer implements ObserverInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * Receive update from subject. |
| 11 | 11 | * |
@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * @return mixed|void |
| 15 | 15 | */ |
| 16 | - public function update(SubjectInterface $subject) |
|
| 17 | - { |
|
| 16 | + public function update(SubjectInterface $subject) |
|
| 17 | + {
|
|
| 18 | 18 | echo sprintf('Subject author is %s.', $subject->getAuthor()); |
| 19 | 19 | } |
| 20 | 20 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | int $code, |
| 32 | 32 | string $message, |
| 33 | 33 | SubjectInterface $subject |
| 34 | - ) { |
|
| 34 | + ) {
|
|
| 35 | 35 | // TODO: Implement report() method. |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Observer\Npl; |
| 6 | 6 | |
| 7 | -interface ObserverInterface |
|
| 8 | -{ |
|
| 7 | +interface ObserverInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * Receive update from subject. |
| 11 | 11 | * |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Observer\Spl; |
| 6 | 6 | |
| 7 | -class ProductObserver implements \SplObserver |
|
| 8 | -{ |
|
| 7 | +class ProductObserver implements \SplObserver |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * Update product price. |
| 11 | 11 | * |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Memento; |
| 6 | 6 | |
| 7 | -class History implements \Countable |
|
| 8 | -{ |
|
| 7 | +class History implements \Countable |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var \DesignPattern\Behavioral\Memento\Memento[] |
| 11 | 11 | */ |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * History constructor. |
| 16 | 16 | */ |
| 17 | - public function __construct() |
|
| 18 | - { |
|
| 17 | + public function __construct() |
|
| 18 | + {
|
|
| 19 | 19 | $this->mementos = []; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @return \DesignPattern\Behavioral\Memento\Memento|mixed|null |
| 36 | 36 | */ |
| 37 | - public function popMemento() |
|
| 38 | - { |
|
| 39 | - if ($this->count() > 0) { |
|
| 37 | + public function popMemento() |
|
| 38 | + {
|
|
| 39 | + if ($this->count() > 0) {
|
|
| 40 | 40 | return array_pop($this->mementos); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | */ |
| 65 | 65 | private static function isValidState(int $state): void |
| 66 | 66 | { |
| 67 | - if (! in_array($state, self::$validStates, true)) { |
|
| 67 | + if ( ! in_array($state, self::$validStates, true)) { |
|
| 68 | 68 | throw new \InvalidArgumentException('Invalid state given.'); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Memento; |
| 6 | 6 | |
| 7 | -class State |
|
| 8 | -{ |
|
| 7 | +class State |
|
| 8 | +{
|
|
| 9 | 9 | public const STATUS_LOCKED = 1; |
| 10 | 10 | public const STATUS_CONFIRMED = 2; |
| 11 | 11 | public const STATUS_PAID = 3; |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @throws \Exception|\InvalidArgumentException |
| 47 | 47 | */ |
| 48 | - public function __construct($state = self::STATUS_LOCKED) |
|
| 49 | - { |
|
| 48 | + public function __construct($state = self::STATUS_LOCKED) |
|
| 49 | + {
|
|
| 50 | 50 | self::isValidState($state); |
| 51 | 51 | |
| 52 | 52 | $this->state = $state; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | private static function isValidState(int $state): void |
| 66 | 66 | { |
| 67 | - if (! in_array($state, self::$validStates, true)) { |
|
| 67 | + if (! in_array($state, self::$validStates, true)) {
|
|
| 68 | 68 | throw new \InvalidArgumentException('Invalid state given.'); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Strategy; |
| 6 | 6 | |
| 7 | -interface ComparatorInterface |
|
| 8 | -{ |
|
| 7 | +interface ComparatorInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * Compare the two given values. |
| 11 | 11 | * |