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

@@ -4,10 +4,7 @@ namespace DesignPatterns\Structural\DataMapper;
class StorageAdapter
{
/**
* @var array
*/
private $data = [];
private array $data = [];
public function __construct(array $data)
{

View File

@@ -2,6 +2,7 @@
namespace DesignPatterns\Structural\DataMapper\Tests;
use InvalidArgumentException;
use DesignPatterns\Structural\DataMapper\StorageAdapter;
use DesignPatterns\Structural\DataMapper\User;
use DesignPatterns\Structural\DataMapper\UserMapper;
@@ -21,7 +22,7 @@ class DataMapperTest extends TestCase
public function testWillNotMapInvalidData()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$storage = new StorageAdapter([]);
$mapper = new UserMapper($storage);

View File

@@ -4,15 +4,8 @@ namespace DesignPatterns\Structural\DataMapper;
class User
{
/**
* @var string
*/
private $username;
/**
* @var string
*/
private $email;
private string $username;
private string $email;
public static function fromState(array $state): User
{
@@ -32,18 +25,12 @@ class User
$this->email = $email;
}
/**
* @return string
*/
public function getUsername()
public function getUsername(): string
{
return $this->username;
}
/**
* @return string
*/
public function getEmail()
public function getEmail(): string
{
return $this->email;
}

View File

@@ -2,16 +2,12 @@
namespace DesignPatterns\Structural\DataMapper;
use InvalidArgumentException;
class UserMapper
{
/**
* @var StorageAdapter
*/
private $adapter;
private StorageAdapter $adapter;
/**
* @param StorageAdapter $storage
*/
public function __construct(StorageAdapter $storage)
{
$this->adapter = $storage;
@@ -22,17 +18,13 @@ class UserMapper
* in memory. Normally this kind of logic will be implemented using the Repository pattern.
* However the important part is in mapRowToUser() below, that will create a business object from the
* data fetched from storage
*
* @param int $id
*
* @return User
*/
public function findById(int $id): User
{
$result = $this->adapter->find($id);
if ($result === null) {
throw new \InvalidArgumentException("User #$id not found");
throw new InvalidArgumentException("User #$id not found");
}
return $this->mapRowToUser($result);