mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-19 21:11:38 +02:00
update deps & install rector
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user