Skip to content

Commit 8d6d458

Browse files
author
Dominik Liebler
committed
cs
1 parent 8b82ed1 commit 8d6d458

File tree

6 files changed

+53
-17
lines changed

6 files changed

+53
-17
lines changed

AbstractFactory/MediaInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ interface MediaInterface
1616
*
1717
* @return string
1818
*/
19-
function render();
19+
public function render();
2020
}

Builder/CarBuilder.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,31 @@
77
*/
88
class CarBuilder implements Builder
99
{
10-
10+
/**
11+
* @var Parts\Car
12+
*/
1113
protected $car;
1214

15+
/**
16+
* @return void
17+
*/
1318
public function addDoors()
1419
{
1520
$this->car->setPart('rightdoor', new Parts\Door());
1621
$this->car->setPart('leftDoor', new Parts\Door());
1722
}
1823

24+
/**
25+
* @return void
26+
*/
1927
public function addEngine()
2028
{
2129
$this->car->setPart('engine', new Parts\Engine());
2230
}
2331

32+
/**
33+
* @return void
34+
*/
2435
public function addWheel()
2536
{
2637
$this->car->setPart('wheelLF', new Parts\Wheel());
@@ -29,11 +40,17 @@ public function addWheel()
2940
$this->car->setPart('wheelRR', new Parts\Wheel());
3041
}
3142

43+
/**
44+
* @return void
45+
*/
3246
public function createVehicle()
3347
{
3448
$this->car = new Parts\Car();
3549
}
3650

51+
/**
52+
* @return Parts\Car
53+
*/
3754
public function getVehicle()
3855
{
3956
return $this->car;

Builder/Parts/Wheel.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace DesignPatterns\Builder\Parts;
44

5+
/**
6+
* Class Wheel
7+
*/
58
class Wheel
69
{
7-
8-
}
10+
11+
}

ChainOfResponsibilities/Handler.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
abstract class Handler
1414
{
1515
/**
16-
* @var null
16+
* @var Handler
1717
*/
1818
private $successor = null;
1919

@@ -22,14 +22,16 @@ abstract class Handler
2222
*
2323
* A prepend method could be done with the same spirit
2424
*
25-
* You could also send the successor in the contructor but in PHP it is a
25+
* You could also send the successor in the constructor but in PHP it is a
2626
* bad idea because you have to remove the type-hint of the parameter because
2727
* the last handler has a null successor.
2828
*
29-
* And if you override the contructor, that Handler can no longer have a
29+
* And if you override the constructor, that Handler can no longer have a
3030
* successor. One solution is to provide a NullObject (see pattern).
3131
* It is more preferable to keep the constructor "free" to inject services
3232
* you need with the DiC of symfony2 for example.
33+
*
34+
* @param Handler $handler
3335
*/
3436
final public function append(Handler $handler)
3537
{
@@ -46,6 +48,10 @@ final public function append(Handler $handler)
4648
* This approach by using a template method pattern ensures you that
4749
* each subclass will not forget to call the successor. Beside, the returned
4850
* boolean value indicates you if the request have been processed or not.
51+
*
52+
* @param Request $req
53+
*
54+
* @return bool
4955
*/
5056
final public function handle(Request $req)
5157
{
@@ -63,7 +69,9 @@ final public function handle(Request $req)
6369

6470
/**
6571
* Each concrete handler has to implement the processing of the request
66-
*
72+
*
73+
* @param Request $req
74+
*
6775
* @return bool true if the request has been processed
6876
*/
6977
abstract protected function processing(Request $req);

ChainOfResponsibilities/Responsible/FastStorage.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55
use DesignPatterns\ChainOfResponsibilities\Handler;
66
use DesignPatterns\ChainOfResponsibilities\Request;
77

8+
/**
9+
* Class FastStorage
10+
*/
811
class FastStorage extends Handler
912
{
13+
/**
14+
* @var array
15+
*/
16+
protected $data = array();
1017

11-
protected $_data = array();
12-
18+
/**
19+
* @param array $data
20+
*/
1321
public function __construct($data = array())
1422
{
15-
$this->_data = $data;
23+
$this->data = $data;
1624
}
1725

1826
protected function processing(Request $req)
1927
{
2028
if ('get' === $req->verb) {
21-
if (array_key_exists($req->key, $this->_data)) {
29+
if (array_key_exists($req->key, $this->data)) {
2230
// the handler IS responsible and then processes the request
23-
$req->response = $this->_data[$req->key];
31+
$req->response = $this->data[$req->key];
2432
// instead of returning true, I could return the value but it proves
2533
// to be a bad idea. What if the value IS "false" ?
2634
return true;

ChainOfResponsibilities/Responsible/SlowStorage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ class SlowStorage extends Handler
2020
/**
2121
* @var array
2222
*/
23-
protected $_data = array();
23+
protected $data = array();
2424

2525
/**
2626
* @param array $data
2727
*/
2828
public function __construct($data = array())
2929
{
30-
$this->_data = $data;
30+
$this->data = $data;
3131
}
3232

3333
protected function processing(Request $req)
3434
{
3535
if ('get' === $req->verb) {
36-
if (array_key_exists($req->key, $this->_data)) {
37-
$req->response = $this->_data[$req->key];
36+
if (array_key_exists($req->key, $this->data)) {
37+
$req->response = $this->data[$req->key];
3838

3939
return true;
4040
}

0 commit comments

Comments
 (0)