diff --git a/AbstractFactory/MediaInterface.php b/AbstractFactory/MediaInterface.php index 16c5d78..92d0089 100644 --- a/AbstractFactory/MediaInterface.php +++ b/AbstractFactory/MediaInterface.php @@ -16,5 +16,5 @@ interface MediaInterface * * @return string */ - function render(); + public function render(); } diff --git a/Builder/CarBuilder.php b/Builder/CarBuilder.php index 515f00b..ce0e3f4 100644 --- a/Builder/CarBuilder.php +++ b/Builder/CarBuilder.php @@ -7,20 +7,31 @@ namespace DesignPatterns\Builder; */ class CarBuilder implements Builder { - + /** + * @var Parts\Car + */ protected $car; + /** + * @return void + */ public function addDoors() { $this->car->setPart('rightdoor', new Parts\Door()); $this->car->setPart('leftDoor', new Parts\Door()); } + /** + * @return void + */ public function addEngine() { $this->car->setPart('engine', new Parts\Engine()); } + /** + * @return void + */ public function addWheel() { $this->car->setPart('wheelLF', new Parts\Wheel()); @@ -29,11 +40,17 @@ class CarBuilder implements Builder $this->car->setPart('wheelRR', new Parts\Wheel()); } + /** + * @return void + */ public function createVehicle() { $this->car = new Parts\Car(); } + /** + * @return Parts\Car + */ public function getVehicle() { return $this->car; diff --git a/Builder/Parts/Wheel.php b/Builder/Parts/Wheel.php index d2b8950..71337e4 100644 --- a/Builder/Parts/Wheel.php +++ b/Builder/Parts/Wheel.php @@ -2,7 +2,10 @@ namespace DesignPatterns\Builder\Parts; +/** + * Class Wheel + */ class Wheel { - -} \ No newline at end of file + +} diff --git a/ChainOfResponsibilities/Handler.php b/ChainOfResponsibilities/Handler.php index 1883ec3..35ec769 100644 --- a/ChainOfResponsibilities/Handler.php +++ b/ChainOfResponsibilities/Handler.php @@ -13,7 +13,7 @@ namespace DesignPatterns\ChainOfResponsibilities; abstract class Handler { /** - * @var null + * @var Handler */ private $successor = null; @@ -22,14 +22,16 @@ abstract class Handler * * A prepend method could be done with the same spirit * - * You could also send the successor in the contructor but in PHP it is a + * You could also send the successor in the constructor but in PHP it is a * bad idea because you have to remove the type-hint of the parameter because * the last handler has a null successor. * - * And if you override the contructor, that Handler can no longer have a + * And if you override the constructor, that Handler can no longer have a * successor. One solution is to provide a NullObject (see pattern). * It is more preferable to keep the constructor "free" to inject services * you need with the DiC of symfony2 for example. + * + * @param Handler $handler */ final public function append(Handler $handler) { @@ -46,6 +48,10 @@ abstract class Handler * This approach by using a template method pattern ensures you that * each subclass will not forget to call the successor. Beside, the returned * boolean value indicates you if the request have been processed or not. + * + * @param Request $req + * + * @return bool */ final public function handle(Request $req) { @@ -63,7 +69,9 @@ abstract class Handler /** * Each concrete handler has to implement the processing of the request - * + * + * @param Request $req + * * @return bool true if the request has been processed */ abstract protected function processing(Request $req); diff --git a/ChainOfResponsibilities/Responsible/FastStorage.php b/ChainOfResponsibilities/Responsible/FastStorage.php index ccdf518..d02fb5a 100644 --- a/ChainOfResponsibilities/Responsible/FastStorage.php +++ b/ChainOfResponsibilities/Responsible/FastStorage.php @@ -5,22 +5,30 @@ namespace DesignPatterns\ChainOfResponsibilities\Responsible; use DesignPatterns\ChainOfResponsibilities\Handler; use DesignPatterns\ChainOfResponsibilities\Request; +/** + * Class FastStorage + */ class FastStorage extends Handler { + /** + * @var array + */ + protected $data = array(); - protected $_data = array(); - + /** + * @param array $data + */ public function __construct($data = array()) { - $this->_data = $data; + $this->data = $data; } protected function processing(Request $req) { if ('get' === $req->verb) { - if (array_key_exists($req->key, $this->_data)) { + if (array_key_exists($req->key, $this->data)) { // the handler IS responsible and then processes the request - $req->response = $this->_data[$req->key]; + $req->response = $this->data[$req->key]; // instead of returning true, I could return the value but it proves // to be a bad idea. What if the value IS "false" ? return true; diff --git a/ChainOfResponsibilities/Responsible/SlowStorage.php b/ChainOfResponsibilities/Responsible/SlowStorage.php index 9b835d4..8d64484 100644 --- a/ChainOfResponsibilities/Responsible/SlowStorage.php +++ b/ChainOfResponsibilities/Responsible/SlowStorage.php @@ -20,21 +20,21 @@ class SlowStorage extends Handler /** * @var array */ - protected $_data = array(); + protected $data = array(); /** * @param array $data */ public function __construct($data = array()) { - $this->_data = $data; + $this->data = $data; } protected function processing(Request $req) { if ('get' === $req->verb) { - if (array_key_exists($req->key, $this->_data)) { - $req->response = $this->_data[$req->key]; + if (array_key_exists($req->key, $this->data)) { + $req->response = $this->data[$req->key]; return true; }