update deps & install rector

This commit is contained in:
Dominik Liebler
2019-12-14 12:50:05 +01:00
parent 04acce6759
commit 579a5ac946
87 changed files with 2432 additions and 786 deletions

View File

@@ -3,14 +3,10 @@
namespace DesignPatterns\Behavioral\ChainOfResponsibilities;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
abstract class Handler
{
/**
* @var Handler|null
*/
private $successor = null;
private ?Handler $successor = null;
public function __construct(Handler $handler = null)
{
@@ -20,12 +16,8 @@ abstract class Handler
/**
* This approach by using a template method pattern ensures you that
* each subclass will not forget to call the successor
*
* @param RequestInterface $request
*
* @return string|null
*/
final public function handle(RequestInterface $request)
final public function handle(RequestInterface $request): ?string
{
$processed = $this->processing($request);
@@ -37,5 +29,5 @@ abstract class Handler
return $processed;
}
abstract protected function processing(RequestInterface $request);
abstract protected function processing(RequestInterface $request): ?string;
}

View File

@@ -7,28 +7,16 @@ use Psr\Http\Message\RequestInterface;
class HttpInMemoryCacheHandler extends Handler
{
/**
* @var array
*/
private $data;
private array $data;
/**
* @param array $data
* @param Handler|null $successor
*/
public function __construct(array $data, Handler $successor = null)
public function __construct(array $data, ?Handler $successor = null)
{
parent::__construct($successor);
$this->data = $data;
}
/**
* @param RequestInterface $request
*
* @return string|null
*/
protected function processing(RequestInterface $request)
protected function processing(RequestInterface $request): ?string
{
$key = sprintf(
'%s?%s',

View File

@@ -7,12 +7,7 @@ use Psr\Http\Message\RequestInterface;
class SlowDatabaseHandler extends Handler
{
/**
* @param RequestInterface $request
*
* @return string|null
*/
protected function processing(RequestInterface $request)
protected function processing(RequestInterface $request): ?string
{
// this is a mockup, in production code you would ask a slow (compared to in-memory) DB for the results

View File

@@ -5,17 +5,13 @@ namespace DesignPatterns\Behavioral\ChainOfResponsibilities\Tests;
use DesignPatterns\Behavioral\ChainOfResponsibilities\Handler;
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\HttpInMemoryCacheHandler;
use DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowDatabaseHandler;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
class ChainTest extends TestCase
{
/**
* @var Handler
*/
private $chain;
private Handler $chain;
protected function setUp(): void
{