@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Specification; |
| 6 | 6 | |
| 7 | -class RangeSpecification extends AbstractSpecification |
|
| 8 | -{ |
|
| 7 | +class RangeSpecification extends AbstractSpecification |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var int|null |
| 11 | 11 | */ |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | * @param int $min |
| 23 | 23 | * @param int $max |
| 24 | 24 | */ |
| 25 | - public function __construct(int $min, int $max) |
|
| 26 | - { |
|
| 25 | + public function __construct(int $min, int $max) |
|
| 26 | + {
|
|
| 27 | 27 | $this->min = $min; |
| 28 | 28 | $this->max = $max; |
| 29 | 29 | } |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | public function isSatisfiedBy(Item $item): bool |
| 37 | 37 | { |
| 38 | 38 | $value = $item->getValue(); |
| 39 | - if ($this->max !== null && $value > $this->max) { |
|
| 39 | + if ($this->max !== null && $value > $this->max) {
|
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ($this->min !== null && $value < $this->min) { |
|
| 43 | + if ($this->min !== null && $value < $this->min) {
|
|
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -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\Spl; |
| 6 | 6 | |
| 7 | -class Product implements \SplSubject |
|
| 8 | -{ |
|
| 7 | +class Product implements \SplSubject |
|
| 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->price = 0; |
| 33 | 33 | $this->observers = new \SplObjectStorage(); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | public function notify(): void |
| 69 | 69 | { |
| 70 | 70 | /** @var \SplObserver $observer */ |
| 71 | - foreach ($this->observers as $observer) { |
|
| 71 | + foreach ($this->observers as $observer) {
|
|
| 72 | 72 | $observer->update($this); |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | use Psr\Http\Message\RequestInterface; |
| 8 | 8 | |
| 9 | -abstract class Handler |
|
| 10 | -{ |
|
| 9 | +abstract class Handler |
|
| 10 | +{
|
|
| 11 | 11 | /** |
| 12 | 12 | * @var \DesignPattern\Behavioral\ChainOfResponsibility\Handler|null |
| 13 | 13 | */ |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param \DesignPattern\Behavioral\ChainOfResponsibility\Handler|null $handler |
| 20 | 20 | */ |
| 21 | - public function __construct(Handler $handler = null) |
|
| 22 | - { |
|
| 21 | + public function __construct(Handler $handler = null) |
|
| 22 | + {
|
|
| 23 | 23 | $this->handler = $handler; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return mixed |
| 32 | 32 | */ |
| 33 | - final public function handle(RequestInterface $request) |
|
| 34 | - { |
|
| 33 | + final public function handle(RequestInterface $request) |
|
| 34 | + {
|
|
| 35 | 35 | $process = $this->process($request); |
| 36 | 36 | |
| 37 | - if ($process === null && $this->handler !== null) { |
|
| 37 | + if ($process === null && $this->handler !== null) {
|
|
| 38 | 38 | $process = $this->handler->handle($request); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | use Psr\Http\Message\RequestInterface; |
| 8 | 8 | |
| 9 | -class MemoryHandler extends Handler |
|
| 10 | -{ |
|
| 9 | +class MemoryHandler extends Handler |
|
| 10 | +{
|
|
| 11 | 11 | /** |
| 12 | 12 | * @var array |
| 13 | 13 | */ |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | * @param array $data |
| 20 | 20 | * @param \DesignPattern\Behavioral\ChainOfResponsibility\Handler|null $handler |
| 21 | 21 | */ |
| 22 | - public function __construct(array $data, Handler $handler = null) |
|
| 23 | - { |
|
| 22 | + public function __construct(array $data, Handler $handler = null) |
|
| 23 | + {
|
|
| 24 | 24 | parent::__construct($handler); |
| 25 | 25 | |
| 26 | 26 | $this->data = $data; |
@@ -33,15 +33,15 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return mixed|null |
| 35 | 35 | */ |
| 36 | - protected function process(RequestInterface $request) |
|
| 37 | - { |
|
| 36 | + protected function process(RequestInterface $request) |
|
| 37 | + {
|
|
| 38 | 38 | $key = sprintf( |
| 39 | 39 | '%s?%s', |
| 40 | 40 | $request->getUri()->getPath(), |
| 41 | 41 | $request->getUri()->getQuery() |
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | - if (isset($this->data[$key]) && $request->getMethod() === 'GET') { |
|
| 44 | + if (isset($this->data[$key]) && $request->getMethod() === 'GET') {
|
|
| 45 | 45 | return $this->data[$key]; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
| 6 | 6 | |
| 7 | -class User implements RoleInterface |
|
| 8 | -{ |
|
| 7 | +class User implements RoleInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var string |
| 11 | 11 | */ |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @param string $name |
| 18 | 18 | */ |
| 19 | - public function __construct(string $name) |
|
| 20 | - { |
|
| 19 | + public function __construct(string $name) |
|
| 20 | + {
|
|
| 21 | 21 | $this->name = $name; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return mixed|void |
| 38 | 38 | */ |
| 39 | - public function allow(VisitorInterface $visitor) |
|
| 40 | - { |
|
| 39 | + public function allow(VisitorInterface $visitor) |
|
| 40 | + {
|
|
| 41 | 41 | $visitor->visitUser($this); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
| 6 | 6 | |
| 7 | -class Group implements RoleInterface |
|
| 8 | -{ |
|
| 7 | +class Group implements RoleInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var string |
| 11 | 11 | */ |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @param string $name |
| 18 | 18 | */ |
| 19 | - public function __construct(string $name) |
|
| 20 | - { |
|
| 19 | + public function __construct(string $name) |
|
| 20 | + {
|
|
| 21 | 21 | $this->name = $name; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return mixed|void |
| 38 | 38 | */ |
| 39 | - public function allow(VisitorInterface $visitor) |
|
| 40 | - { |
|
| 39 | + public function allow(VisitorInterface $visitor) |
|
| 40 | + {
|
|
| 41 | 41 | $visitor->visitGroup($this); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
| 6 | 6 | |
| 7 | -interface VisitorInterface |
|
| 8 | -{ |
|
| 7 | +interface VisitorInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @param \DesignPattern\Behavioral\Visitor\User $user |
| 11 | 11 | * |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
| 6 | 6 | |
| 7 | -interface RoleInterface |
|
| 8 | -{ |
|
| 7 | +interface RoleInterface |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @param \DesignPattern\Behavioral\Visitor\VisitorInterface $visitor |
| 11 | 11 | * |