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

@@ -2,38 +2,39 @@
namespace DesignPatterns\Creational\Builder;
use DesignPatterns\Creational\Builder\Parts\Door;
use DesignPatterns\Creational\Builder\Parts\Engine;
use DesignPatterns\Creational\Builder\Parts\Wheel;
use DesignPatterns\Creational\Builder\Parts\Car;
use DesignPatterns\Creational\Builder\Parts\Vehicle;
class CarBuilder implements Builder
{
/**
* @var Parts\Car
*/
private $car;
private Car $car;
public function addDoors()
{
$this->car->setPart('rightDoor', new Parts\Door());
$this->car->setPart('leftDoor', new Parts\Door());
$this->car->setPart('trunkLid', new Parts\Door());
$this->car->setPart('rightDoor', new Door());
$this->car->setPart('leftDoor', new Door());
$this->car->setPart('trunkLid', new Door());
}
public function addEngine()
{
$this->car->setPart('engine', new Parts\Engine());
$this->car->setPart('engine', new Engine());
}
public function addWheel()
{
$this->car->setPart('wheelLF', new Parts\Wheel());
$this->car->setPart('wheelRF', new Parts\Wheel());
$this->car->setPart('wheelLR', new Parts\Wheel());
$this->car->setPart('wheelRR', new Parts\Wheel());
$this->car->setPart('wheelLF', new Wheel());
$this->car->setPart('wheelRF', new Wheel());
$this->car->setPart('wheelLR', new Wheel());
$this->car->setPart('wheelRR', new Wheel());
}
public function createVehicle()
{
$this->car = new Parts\Car();
$this->car = new Car();
}
public function getVehicle(): Vehicle

View File

@@ -7,13 +7,9 @@ abstract class Vehicle
/**
* @var object[]
*/
private $data = [];
private array $data = [];
/**
* @param string $key
* @param object $value
*/
public function setPart($key, $value)
public function setPart(string $key, object $value)
{
$this->data[$key] = $value;
}

View File

@@ -2,39 +2,40 @@
namespace DesignPatterns\Creational\Builder;
use DesignPatterns\Creational\Builder\Parts\Door;
use DesignPatterns\Creational\Builder\Parts\Engine;
use DesignPatterns\Creational\Builder\Parts\Wheel;
use DesignPatterns\Creational\Builder\Parts\Truck;
use DesignPatterns\Creational\Builder\Parts\Vehicle;
class TruckBuilder implements Builder
{
/**
* @var Parts\Truck
*/
private $truck;
private Truck $truck;
public function addDoors()
{
$this->truck->setPart('rightDoor', new Parts\Door());
$this->truck->setPart('leftDoor', new Parts\Door());
$this->truck->setPart('rightDoor', new Door());
$this->truck->setPart('leftDoor', new Door());
}
public function addEngine()
{
$this->truck->setPart('truckEngine', new Parts\Engine());
$this->truck->setPart('truckEngine', new Engine());
}
public function addWheel()
{
$this->truck->setPart('wheel1', new Parts\Wheel());
$this->truck->setPart('wheel2', new Parts\Wheel());
$this->truck->setPart('wheel3', new Parts\Wheel());
$this->truck->setPart('wheel4', new Parts\Wheel());
$this->truck->setPart('wheel5', new Parts\Wheel());
$this->truck->setPart('wheel6', new Parts\Wheel());
$this->truck->setPart('wheel1', new Wheel());
$this->truck->setPart('wheel2', new Wheel());
$this->truck->setPart('wheel3', new Wheel());
$this->truck->setPart('wheel4', new Wheel());
$this->truck->setPart('wheel5', new Wheel());
$this->truck->setPart('wheel6', new Wheel());
}
public function createVehicle()
{
$this->truck = new Parts\Truck();
$this->truck = new Truck();
}
public function getVehicle(): Vehicle

View File

@@ -4,10 +4,7 @@ namespace DesignPatterns\Creational\FactoryMethod;
class FileLogger implements Logger
{
/**
* @var string
*/
private $filePath;
private string $filePath;
public function __construct(string $filePath)
{

View File

@@ -4,10 +4,7 @@ namespace DesignPatterns\Creational\FactoryMethod;
class FileLoggerFactory implements LoggerFactory
{
/**
* @var string
*/
private $filePath;
private string $filePath;
public function __construct(string $filePath)
{

View File

@@ -10,7 +10,7 @@ final class Multiton
/**
* @var Multiton[]
*/
private static $instances = [];
private static array $instances = [];
/**
* this is private to prevent from creating arbitrary instances

View File

@@ -2,16 +2,15 @@
namespace DesignPatterns\Creational\Pool;
use DateTime;
class StringReverseWorker
{
/**
* @var \DateTime
*/
private $createdAt;
private DateTime $createdAt;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new DateTime();
}
public function run(string $text)

View File

@@ -2,17 +2,19 @@
namespace DesignPatterns\Creational\Pool;
class WorkerPool implements \Countable
use Countable;
class WorkerPool implements Countable
{
/**
* @var StringReverseWorker[]
*/
private $occupiedWorkers = [];
private array $occupiedWorkers = [];
/**
* @var StringReverseWorker[]
*/
private $freeWorkers = [];
private array $freeWorkers = [];
public function get(): StringReverseWorker
{

View File

@@ -4,10 +4,7 @@ namespace DesignPatterns\Creational\Prototype;
class BarBookPrototype extends BookPrototype
{
/**
* @var string
*/
protected $category = 'Bar';
protected string $category = 'Bar';
public function __clone()
{

View File

@@ -4,15 +4,8 @@ namespace DesignPatterns\Creational\Prototype;
abstract class BookPrototype
{
/**
* @var string
*/
protected $title;
/**
* @var string
*/
protected $category;
protected string $title;
protected string $category;
abstract public function __clone();
@@ -21,7 +14,7 @@ abstract class BookPrototype
return $this->title;
}
public function setTitle($title)
public function setTitle(string $title)
{
$this->title = $title;
}

View File

@@ -4,10 +4,7 @@ namespace DesignPatterns\Creational\Prototype;
class FooBookPrototype extends BookPrototype
{
/**
* @var string
*/
protected $category = 'Foo';
protected string $category = 'Foo';
public function __clone()
{

View File

@@ -4,10 +4,7 @@ namespace DesignPatterns\Creational\Singleton;
final class Singleton
{
/**
* @var Singleton
*/
private static $instance;
private static ?Singleton $instance = null;
/**
* gets the instance via lazy initialization (created on first usage)

View File

@@ -2,17 +2,14 @@
namespace DesignPatterns\Creational\StaticFactory;
use InvalidArgumentException;
/**
* Note1: Remember, static means global state which is evil because it can't be mocked for tests
* Note2: Cannot be subclassed or mock-upped or have multiple different instances.
*/
final class StaticFactory
{
/**
* @param string $type
*
* @return Formatter
*/
public static function factory(string $type): Formatter
{
if ($type == 'number') {
@@ -21,6 +18,6 @@ final class StaticFactory
return new FormatString();
}
throw new \InvalidArgumentException('Unknown format given');
throw new InvalidArgumentException('Unknown format given');
}
}

View File

@@ -2,6 +2,7 @@
namespace DesignPatterns\Creational\StaticFactory\Tests;
use InvalidArgumentException;
use DesignPatterns\Creational\StaticFactory\FormatNumber;
use DesignPatterns\Creational\StaticFactory\FormatString;
use DesignPatterns\Creational\StaticFactory\StaticFactory;
@@ -21,7 +22,7 @@ class StaticFactoryTest extends TestCase
public function testException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
StaticFactory::factory('object');
}