From 0fab26d206e44c1f446638608a815e8df73d7c13 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 30 Aug 2017 00:21:31 +0300 Subject: [PATCH 01/35] use default arguments in PHP 7+ --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index eb072e6..6307b22 100644 --- a/README.md +++ b/README.md @@ -171,19 +171,23 @@ function paintCar(&$car) { ### Use default arguments instead of short circuiting or conditionals -**Bad:** +**Not bad:** + ```php -function createMicrobrewery($name = null) { - $breweryName = $name ?: 'Hipster Brew Co.'; +function createMicrobrewery($name = null) +{ +    $breweryName = $name ?: 'Hipster Brew Co.'; // ... } ``` -**Good**: +**Good for PHP 7+**: + ```php -function createMicrobrewery($breweryName = 'Hipster Brew Co.') { - // ... +function createMicrobrewery(string $breweryName = 'Hipster Brew Co.') +{ +    // ... } ``` From 47d6f95f43fc0150b192a6179baf1858a953e6b0 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 30 Aug 2017 08:41:34 +0300 Subject: [PATCH 02/35] Add origin bad example --- README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6307b22..7958a1b 100644 --- a/README.md +++ b/README.md @@ -171,26 +171,40 @@ function paintCar(&$car) { ### Use default arguments instead of short circuiting or conditionals +**Not good:** + +This is not good because `$breweryName` can be `NULL`. + +```php +function createMicrobrewery($breweryName = 'Hipster Brew Co.') +{ +    // ... +} +``` + **Not bad:** +This opinion is understandable than the previous version, but it better controls the value of the variable. + ```php function createMicrobrewery($name = null) {    $breweryName = $name ?: 'Hipster Brew Co.'; // ... } - ``` -**Good for PHP 7+**: +**Good**: + +If you support only PHP 7+, then you can use [type hinting](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration) and be sure that the `$breweryName` will not be `NULL`. ```php function createMicrobrewery(string $breweryName = 'Hipster Brew Co.') {    // ... } - ``` + **[⬆ back to top](#table-of-contents)** ## **Functions** ### Function arguments (2 or fewer ideally) From e15b99fb59349c237a8c47a4f89caf3e1b8fbb14 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 16:59:29 +0300 Subject: [PATCH 03/35] correct CS --- README.md | 83 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c8e650c..266f817 100644 --- a/README.md +++ b/README.md @@ -1176,6 +1176,7 @@ renderLargeRectangles($shapes); **[⬆ back to top](#table-of-contents)** ### Interface Segregation Principle (ISP) + ISP states that "Clients should not be forced to depend upon interfaces that they do not use." @@ -1185,97 +1186,123 @@ huge amounts of options is beneficial, because most of the time they won't need all of the settings. Making them optional helps prevent having a "fat interface". **Bad:** + ```php -interface WorkerInterface { +interface WorkerInterface +{ public function work(); public function eat(); } -class Worker implements WorkerInterface { - public function work() { +class Worker implements WorkerInterface +{ + public function work() + { // ....working } - public function eat() { + + public function eat() + { // ...... eating in launch break } } -class SuperWorker implements WorkerInterface { - public function work() { +class SuperWorker implements WorkerInterface +{ + public function work() + { //.... working much more } - public function eat() { + public function eat() + { //.... eating in launch break } } -class Manager { - /** @var WorkerInterface $worker **/ - private $worker; - - public function setWorker(WorkerInterface $worker) { +class Manager +{ + private $worker; + + public function setWorker(WorkerInterface $worker) + { $this->worker = $worker; } - public function manage() { + public function manage() + { $this->worker->work(); } } ``` **Good:** + ```php -interface WorkerInterface extends FeedableInterface, WorkableInterface { +interface WorkerInterface extends FeedableInterface, WorkableInterface +{ } -interface WorkableInterface { +interface WorkableInterface +{ public function work(); } -interface FeedableInterface { +interface FeedableInterface +{ public function eat(); } -class Worker implements WorkableInterface, FeedableInterface { - public function work() { +class Worker implements WorkableInterface, FeedableInterface +{ + public function work() + { // ....working } - public function eat() { + public function eat() + { //.... eating in launch break } } -class Robot implements WorkableInterface { - public function work() { +class Robot implements WorkableInterface +{ + public function work() + { // ....working } } -class SuperWorker implements WorkerInterface { - public function work() { +class SuperWorker implements WorkerInterface +{ + public function work() + { //.... working much more } - public function eat() { + public function eat() + { //.... eating in launch break } } -class Manager { - /** @var $worker WorkableInterface **/ +class Manager +{ private $worker; - public function setWorker(WorkableInterface $w) { + public function setWorker(WorkableInterface $w) + { $this->worker = $w; } - public function manage() { + public function manage() + { $this->worker->work(); } } ``` + **[⬆ back to top](#table-of-contents)** ### Dependency Inversion Principle (DIP) From 83eef477e9d8d53ea4165e528734930e41fc03c8 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:06:55 +0300 Subject: [PATCH 04/35] rename Worker to Employe --- README.md | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 266f817..1f2d2e9 100644 --- a/README.md +++ b/README.md @@ -1188,13 +1188,13 @@ all of the settings. Making them optional helps prevent having a "fat interface" **Bad:** ```php -interface WorkerInterface +interface Employe { public function work(); public function eat(); } -class Worker implements WorkerInterface +class Human implements Employe { public function work() { @@ -1207,7 +1207,7 @@ class Worker implements WorkerInterface } } -class SuperWorker implements WorkerInterface +class Robot implements Employe { public function work() { @@ -1216,22 +1216,22 @@ class SuperWorker implements WorkerInterface public function eat() { - //.... eating in launch break + //.... robot can't eating, but it must implement this method } } class Manager { - private $worker; + private $employe; - public function setWorker(WorkerInterface $worker) + public function setWorker(Employe $employe) { - $this->worker = $worker; + $this->employe = $employe; } public function manage() { - $this->worker->work(); + $this->employe->work(); } } ``` @@ -1239,21 +1239,21 @@ class Manager **Good:** ```php -interface WorkerInterface extends FeedableInterface, WorkableInterface -{ -} - -interface WorkableInterface +interface Workable { public function work(); } -interface FeedableInterface +interface Feedable { public function eat(); } -class Worker implements WorkableInterface, FeedableInterface +interface Employe extends Feedable, Workable +{ +} + +class Human implements Employe { public function work() { @@ -1266,7 +1266,7 @@ class Worker implements WorkableInterface, FeedableInterface } } -class Robot implements WorkableInterface +class Robot implements Workable { public function work() { @@ -1274,31 +1274,18 @@ class Robot implements WorkableInterface } } -class SuperWorker implements WorkerInterface -{ - public function work() - { - //.... working much more - } - - public function eat() - { - //.... eating in launch break - } -} - class Manager { - private $worker; + private $employe; - public function setWorker(WorkableInterface $w) + public function setWorker(Workable $employe) { - $this->worker = $w; + $this->employe = $employe; } public function manage() { - $this->worker->work(); + $this->employe->work(); } } ``` From d2d59eae49929c4323869a6783d2939d75ef5543 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:11:03 +0300 Subject: [PATCH 05/35] rename method Manager::setWorker() to Manager::subdue() --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f2d2e9..c680535 100644 --- a/README.md +++ b/README.md @@ -1224,7 +1224,7 @@ class Manager { private $employe; - public function setWorker(Employe $employe) + public function subdue(Employe $employe) { $this->employe = $employe; } @@ -1266,6 +1266,7 @@ class Human implements Employe } } +// robot can only work class Robot implements Workable { public function work() @@ -1278,7 +1279,7 @@ class Manager { private $employe; - public function setWorker(Workable $employe) + public function subdue(Workable $employe) { $this->employe = $employe; } From 84ca341bfa44121db2e62d3347d4ca3211c18e29 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:13:13 +0300 Subject: [PATCH 06/35] manager can manage several employees --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c680535..dfc6845 100644 --- a/README.md +++ b/README.md @@ -1222,16 +1222,18 @@ class Robot implements Employe class Manager { - private $employe; + private $employees; public function subdue(Employe $employe) { - $this->employe = $employe; + $this->employees[] = $employe; } public function manage() { - $this->employe->work(); + foreach ($this->employees as $employe) { + $employe->work(); + } } } ``` @@ -1277,16 +1279,18 @@ class Robot implements Workable class Manager { - private $employe; + private $employees; public function subdue(Workable $employe) { - $this->employe = $employe; + $this->employees[] = $employe; } public function manage() { - $this->employe->work(); + foreach ($this->employees as $employe) { + $employe->work(); + } } } ``` From e24c70fe7c04af7f0302347ac5ce615beff1016e Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:16:51 +0300 Subject: [PATCH 07/35] manager is also an employe. his work is to manage others --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dfc6845..73937b2 100644 --- a/README.md +++ b/README.md @@ -1191,6 +1191,7 @@ all of the settings. Making them optional helps prevent having a "fat interface" interface Employe { public function work(); + public function eat(); } @@ -1220,21 +1221,26 @@ class Robot implements Employe } } -class Manager +class Manager implements Employe { - private $employees; + private $employees = []; public function subdue(Employe $employe) { $this->employees[] = $employe; } - public function manage() + public function work() { foreach ($this->employees as $employe) { $employe->work(); } } + + public function eat() + { + // ...... eating in launch break + } } ``` @@ -1277,21 +1283,26 @@ class Robot implements Workable } } -class Manager +class Manager implements Employe { - private $employees; + private $employees = []; public function subdue(Workable $employe) { $this->employees[] = $employe; } - public function manage() + public function work() { foreach ($this->employees as $employe) { $employe->work(); } } + + public function eat() + { + // ...... eating in launch break + } } ``` From a64e611fa6a4fc384f438ed7afbfded5ce4ccaa8 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:25:11 +0300 Subject: [PATCH 08/35] correct word "employee" --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 73937b2..294839b 100644 --- a/README.md +++ b/README.md @@ -1188,14 +1188,14 @@ all of the settings. Making them optional helps prevent having a "fat interface" **Bad:** ```php -interface Employe +interface Employee { public function work(); public function eat(); } -class Human implements Employe +class Human implements Employee { public function work() { @@ -1208,7 +1208,7 @@ class Human implements Employe } } -class Robot implements Employe +class Robot implements Employee { public function work() { @@ -1221,19 +1221,19 @@ class Robot implements Employe } } -class Manager implements Employe +class Manager implements Employee { private $employees = []; - public function subdue(Employe $employe) + public function subdue(Employee $employee) { - $this->employees[] = $employe; + $this->employees[] = $employee; } public function work() { - foreach ($this->employees as $employe) { - $employe->work(); + foreach ($this->employees as $employee) { + $employee->work(); } } @@ -1257,11 +1257,11 @@ interface Feedable public function eat(); } -interface Employe extends Feedable, Workable +interface Employee extends Feedable, Workable { } -class Human implements Employe +class Human implements Employee { public function work() { @@ -1283,19 +1283,19 @@ class Robot implements Workable } } -class Manager implements Employe +class Manager implements Employee { private $employees = []; - public function subdue(Workable $employe) + public function subdue(Workable $employee) { - $this->employees[] = $employe; + $this->employees[] = $employee; } public function work() { - foreach ($this->employees as $employe) { - $employe->work(); + foreach ($this->employees as $employee) { + $employee->work(); } } From 2a04e3d6ac254b13e3a9d3375a645db430c9043c Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:28:47 +0300 Subject: [PATCH 09/35] correct CS --- README.md | 60 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c8e650c..4903917 100644 --- a/README.md +++ b/README.md @@ -1279,6 +1279,7 @@ class Manager { **[⬆ back to top](#table-of-contents)** ### Dependency Inversion Principle (DIP) + This principle states two essential things: 1. High-level modules should not depend on low-level modules. Both should depend on abstractions. @@ -1293,65 +1294,80 @@ the coupling between modules. Coupling is a very bad development pattern because it makes your code hard to refactor. **Bad:** + ```php -class Worker { - public function work() { +class Worker +{ + public function work() + { // ....working } } -class Manager { - /** @var Worker $worker **/ +class Manager +{ private $worker; - - public function __construct(Worker $worker) { + + public function __construct(Worker $worker) + { $this->worker = $worker; } - - public function manage() { + + public function manage() + { $this->worker->work(); } } -class SuperWorker extends Worker { - public function work() { +class SuperWorker extends Worker +{ + public function work() + { //.... working much more } } ``` **Good:** + ```php -interface WorkerInterface { +interface WorkerInterface +{ public function work(); } -class Worker implements WorkerInterface { - public function work() { +class Worker implements WorkerInterface +{ + public function work() + { // ....working } } -class SuperWorker implements WorkerInterface { - public function work() { +class SuperWorker implements WorkerInterface +{ + public function work() + { //.... working much more } } -class Manager { - /** @var Worker $worker **/ +class Manager +{ private $worker; - - public function __construct(WorkerInterface $worker) { + + public function __construct(WorkerInterface $worker) + { $this->worker = $worker; } - - public function manage() { + + public function manage() + { $this->worker->work(); } } - ``` + **[⬆ back to top](#table-of-contents)** ### Use method chaining From 9c1f626a0e29697f4696e9bba4acc92a40d56c7e Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 17:31:41 +0300 Subject: [PATCH 10/35] =?UTF-8?q?=D1=81hange=20dependencies=20without=20ch?= =?UTF-8?q?anging=20manager=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4903917..6990855 100644 --- a/README.md +++ b/README.md @@ -1304,6 +1304,14 @@ class Worker } } +class SuperWorker extends Worker +{ + public function work() + { + //.... working much more + } +} + class Manager { private $worker; @@ -1318,25 +1326,17 @@ class Manager $this->worker->work(); } } - -class SuperWorker extends Worker -{ - public function work() - { - //.... working much more - } -} ``` **Good:** ```php -interface WorkerInterface +interface Worker { public function work(); } -class Worker implements WorkerInterface +class SumeWorker implements Worker { public function work() { @@ -1344,7 +1344,7 @@ class Worker implements WorkerInterface } } -class SuperWorker implements WorkerInterface +class SuperWorker implements Worker { public function work() { @@ -1356,7 +1356,7 @@ class Manager { private $worker; - public function __construct(WorkerInterface $worker) + public function __construct(Worker $worker) { $this->worker = $worker; } From 80bd47f9fa8ca52682841e43948dac5bb5196354 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 18:27:33 +0300 Subject: [PATCH 11/35] Manager manage workers --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 294839b..16e339c 100644 --- a/README.md +++ b/README.md @@ -1285,17 +1285,17 @@ class Robot implements Workable class Manager implements Employee { - private $employees = []; + private $workers = []; - public function subdue(Workable $employee) + public function subdue(Workable $worker) { - $this->employees[] = $employee; + $this->workers[] = $worker; } public function work() { - foreach ($this->employees as $employee) { - $employee->work(); + foreach ($this->workers as $worker) { + $worker->work(); } } From e31b5b86cee98d1ee40a8ba06d94c2e8c5aefa72 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Aug 2017 18:33:00 +0300 Subject: [PATCH 12/35] add comment --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 16e339c..ad4a175 100644 --- a/README.md +++ b/README.md @@ -1246,6 +1246,8 @@ class Manager implements Employee **Good:** +Not every worker is an employee, but every employee is an worker. + ```php interface Workable { From 2992a4f3fd1d9cd9d673391d363ade0e15b1daea Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 1 Sep 2017 17:34:44 +0300 Subject: [PATCH 13/35] remove Manager in ISP --- README.md | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/README.md b/README.md index ad4a175..839d3b5 100644 --- a/README.md +++ b/README.md @@ -1220,28 +1220,6 @@ class Robot implements Employee //.... robot can't eating, but it must implement this method } } - -class Manager implements Employee -{ - private $employees = []; - - public function subdue(Employee $employee) - { - $this->employees[] = $employee; - } - - public function work() - { - foreach ($this->employees as $employee) { - $employee->work(); - } - } - - public function eat() - { - // ...... eating in launch break - } -} ``` **Good:** @@ -1284,28 +1262,6 @@ class Robot implements Workable // ....working } } - -class Manager implements Employee -{ - private $workers = []; - - public function subdue(Workable $worker) - { - $this->workers[] = $worker; - } - - public function work() - { - foreach ($this->workers as $worker) { - $worker->work(); - } - } - - public function eat() - { - // ...... eating in launch break - } -} ``` **[⬆ back to top](#table-of-contents)** From 32344ead21b0be088c1ee352c926191695f904a9 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Mon, 4 Sep 2017 13:03:17 +0300 Subject: [PATCH 14/35] correct access to $width and $height --- README.md | 115 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 4897765..9d41d65 100644 --- a/README.md +++ b/README.md @@ -1145,48 +1145,56 @@ if you model it using the "is-a" relationship via inheritance, you quickly get into trouble. **Bad:** + ```php -class Rectangle { - private $width, $height; - - public function __construct() { +class Rectangle +{ + protected $width + protected $height; + + public function __construct() + { $this->width = 0; $this->height = 0; } - - public function setColor($color) { + + public function render($area) + { // ... } - - public function render($area) { - // ... - } - - public function setWidth($width) { + + public function setWidth($width) + { $this->width = $width; } - - public function setHeight($height) { + + public function setHeight($height) + { $this->height = $height; } - - public function getArea() { + + public function getArea() + { return $this->width * $this->height; } } -class Square extends Rectangle { - public function setWidth($width) { +class Square extends Rectangle +{ + public function setWidth($width) + { $this->width = $this->height = $width; } - - public function setHeight(height) { + + public function setHeight(height) + { $this->width = $this->height = $height; } } -function renderLargeRectangles($rectangles) { - foreach($rectangles as $rectangle) { +function renderLargeRectangles($rectangles) +{ + foreach ($rectangles as $rectangle) { $rectangle->setWidth(4); $rectangle->setHeight(5); $area = $rectangle->getArea(); // BAD: Will return 25 for Square. Should be 20. @@ -1199,61 +1207,71 @@ renderLargeRectangles($rectangles); ``` **Good:** + ```php -abstract class Shape { - protected $width, $height; - +abstract class Shape +{ + protected $width; + protected $height; + abstract public function getArea(); - - public function setColor($color) { - // ... - } - - public function render($area) { + + public function render($area) + { // ... } } -class Rectangle extends Shape { - public function __construct() { +class Rectangle extends Shape +{ + public function __construct() + { parent::__construct(); $this->width = 0; $this->height = 0; } - - public function setWidth($width) { + + public function setWidth($width) + { $this->width = $width; } - - public function setHeight($height) { + + public function setHeight($height) + { $this->height = $height; } - - public function getArea() { + + public function getArea() + { return $this->width * $this->height; } } -class Square extends Shape { - public function __construct() { +class Square extends Shape +{ + public function __construct() + { parent::__construct(); $this->length = 0; } - - public function setLength($length) { + + public function setLength($length) + { $this->length = $length; } - - public function getArea() { + + public function getArea() + { return pow($this->length, 2); } } -function renderLargeRectangles($rectangles) { - foreach($rectangles as $rectangle) { +function renderLargeRectangles($rectangles) +{ + foreach ($rectangles as $rectangle) { if ($rectangle instanceof Square) { $rectangle->setLength(5); - } else if ($rectangle instanceof Rectangle) { + } elseif ($rectangle instanceof Rectangle) { $rectangle->setWidth(4); $rectangle->setHeight(5); } @@ -1266,6 +1284,7 @@ function renderLargeRectangles($rectangles) { $shapes = [new Rectangle(), new Rectangle(), new Square()]; renderLargeRectangles($shapes); ``` + **[⬆ back to top](#table-of-contents)** ### Interface Segregation Principle (ISP) From a71ad82a792399f7a6c9ed6c0808d9e07e0d8342 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Mon, 4 Sep 2017 13:06:19 +0300 Subject: [PATCH 15/35] forgot ; --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d41d65..b5ae5f0 100644 --- a/README.md +++ b/README.md @@ -1149,7 +1149,7 @@ get into trouble. ```php class Rectangle { - protected $width + protected $width; protected $height; public function __construct() From 25704346570d11e6422269a9641abb3975cabfcc Mon Sep 17 00:00:00 2001 From: webaholik Date: Mon, 4 Sep 2017 22:27:15 -0500 Subject: [PATCH 16/35] Update README.md Corrected a few words. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b5ae5f0..97cb7b9 100644 --- a/README.md +++ b/README.md @@ -1308,7 +1308,7 @@ class Worker implements WorkerInterface { // ....working } public function eat() { - // ...... eating in launch break + // ...... eating in lunch break } } @@ -1318,7 +1318,7 @@ class SuperWorker implements WorkerInterface { } public function eat() { - //.... eating in launch break + //.... eating in lunch break } } @@ -1355,7 +1355,7 @@ class Worker implements WorkableInterface, FeedableInterface { } public function eat() { - //.... eating in launch break + //.... eating in lunch break } } @@ -1371,7 +1371,7 @@ class SuperWorker implements WorkerInterface { } public function eat() { - //.... eating in launch break + //.... eating in lunch break } } @@ -1467,7 +1467,7 @@ class Manager { **[⬆ back to top](#table-of-contents)** ### Use method chaining -This pattern is very useful and commonly used it many libraries such +This pattern is very useful and commonly used in many libraries such as PHPUnit and Doctrine. It allows your code to be expressive, and less verbose. For that reason, I say, use method chaining and take a look at how clean your code will be. In your class functions, simply return `this` at the end of every function, From dc63a3e0d15aff0b9eafba36e4abd3e0227da580 Mon Sep 17 00:00:00 2001 From: zouyi Date: Tue, 5 Sep 2017 16:00:31 +0800 Subject: [PATCH 17/35] add Translation section add Translation section --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index b5ae5f0..bf68a53 100644 --- a/README.md +++ b/README.md @@ -1728,3 +1728,14 @@ function showList($employees) ``` **[⬆ back to top](#table-of-contents)** + + + +## Translation + +This is also available in other languages: + - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese**: + - [yangweijie/clean-code-php](https://github.com/yangweijie/clean-code-php) + - [php-cpm/clean-code-php](https://github.com/php-cpm/clean-code-php) + +**[⬆ back to top](#table-of-contents)** From 0368f8004aeccceb20079ba0d3916a12c7fc097e Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 5 Sep 2017 12:24:02 +0200 Subject: [PATCH 18/35] Restrict Method chaining to setters Remove "I say" that adds no value --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5ae5f0..6b18206 100644 --- a/README.md +++ b/README.md @@ -1469,8 +1469,8 @@ class Manager { ### Use method chaining This pattern is very useful and commonly used it many libraries such as PHPUnit and Doctrine. It allows your code to be expressive, and less verbose. -For that reason, I say, use method chaining and take a look at how clean your code -will be. In your class functions, simply return `this` at the end of every function, +For that reason, use method chaining and take a look at how clean your code +will be. In your class functions, simply use `return $this` at the end of every `set` function, and you can chain further class methods onto it. **Bad:** From aa24debbac9160c31e805ad8edafb07a27e3925f Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 14:08:13 +0300 Subject: [PATCH 19/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7958a1b..0530f2f 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ function createMicrobrewery($breweryName = 'Hipster Brew Co.') **Not bad:** -This opinion is understandable than the previous version, but it better controls the value of the variable. +This opinion is more understandable than the previous version, but it better controls the value of the variable. ```php function createMicrobrewery($name = null) From 9daf53d5455192a6bf127f66d0c16aabd794e139 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 17:27:09 +0300 Subject: [PATCH 20/35] remove introduction of mocking --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4897765..33d894e 100644 --- a/README.md +++ b/README.md @@ -462,8 +462,6 @@ class BetterJSAlternative } ``` -Now we can mock the dependencies and test only the work of method `BetterJSAlternative::parse()`. - **[⬆ back to top](#table-of-contents)** ### Don't use flags as function parameters From 0a5cb98bb0aad18e129a943ae4b32c3d1ad3a755 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 18:36:34 +0300 Subject: [PATCH 21/35] use PSR CS --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4897765..f5d1f79 100644 --- a/README.md +++ b/README.md @@ -467,13 +467,16 @@ Now we can mock the dependencies and test only the work of method `BetterJSAlter **[⬆ back to top](#table-of-contents)** ### Don't use flags as function parameters + Flags tell your user that this function does more than one thing. Functions should do one thing. Split out your functions if they are following different code paths based on a boolean. **Bad:** + ```php -function createFile($name, $temp = false) { +function createFile($name, $temp = false) +{ if ($temp) { touch('./temp/'.$name); } else { @@ -483,15 +486,19 @@ function createFile($name, $temp = false) { ``` **Good**: + ```php -function createFile($name) { +function createFile($name) +{ touch($name); } -function createTempFile($name) { +function createTempFile($name) +{ touch('./temp/'.$name); } ``` + **[⬆ back to top](#table-of-contents)** ### Avoid Side Effects From 068bf035f9ee9814ed5206ec6de2c9f0c208dfcd Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 18:40:18 +0300 Subject: [PATCH 22/35] use PSR CS --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4897765..5d51c2b 100644 --- a/README.md +++ b/README.md @@ -495,6 +495,7 @@ function createTempFile($name) { **[⬆ back to top](#table-of-contents)** ### Avoid Side Effects + A function produces a side effect if it does anything other than take a value in and return another value or values. A side effect could be writing to a file, modifying some global variable, or accidentally wiring all your money to a stranger. @@ -510,12 +511,14 @@ centralizing where your side effects occur. If you can do this, you will be happ than the vast majority of other programmers. **Bad:** + ```php // Global variable referenced by following function. // If we had another function that used this name, now it'd be an array and it could break it. $name = 'Ryan McDermott'; -function splitIntoFirstAndLastName() { +function splitIntoFirstAndLastName() +{ global $name; $name = preg_split('/ /', $name); @@ -526,9 +529,11 @@ splitIntoFirstAndLastName(); var_dump($name); // ['Ryan', 'McDermott']; ``` -**Good**: +**Good:** + ```php -function splitIntoFirstAndLastName($name) { +function splitIntoFirstAndLastName($name) +{ return preg_split('/ /', $name); } @@ -538,6 +543,7 @@ $newName = splitIntoFirstAndLastName($name); var_dump($name); // 'Ryan McDermott'; var_dump($newName); // ['Ryan', 'McDermott']; ``` + **[⬆ back to top](#table-of-contents)** ### Don't write to global functions From fcdb1bb68ae51413c78a86789798d612048a980f Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 18:49:07 +0300 Subject: [PATCH 23/35] use PSR CS --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4897765..9bd6d41 100644 --- a/README.md +++ b/README.md @@ -673,19 +673,24 @@ if ($article->isPublished()) { ### Avoid negative conditionals **Bad:** + ```php -function isDOMNodeNotPresent($node) { +function isDOMNodeNotPresent($node) +{ // ... } -if (!isDOMNodeNotPresent($node)) { +if (!isDOMNodeNotPresent($node)) +{ // ... } ``` -**Good**: +**Good:** + ```php -function isDOMNodePresent($node) { +function isDOMNodePresent($node) +{ // ... } @@ -693,6 +698,7 @@ if (isDOMNodePresent($node)) { // ... } ``` + **[⬆ back to top](#table-of-contents)** ### Avoid conditionals From 46a7f3710457b16ff767749456f3433ad1f82fdf Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 18:51:33 +0300 Subject: [PATCH 24/35] use PSR CS --- README.md | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4897765..b9273ee 100644 --- a/README.md +++ b/README.md @@ -696,6 +696,7 @@ if (isDOMNodePresent($node)) { **[⬆ back to top](#table-of-contents)** ### Avoid conditionals + This seems like an impossible task. Upon first hearing this, most people say, "how am I supposed to do anything without an `if` statement?" The answer is that you can use polymorphism to achieve the same task in many cases. The second @@ -706,10 +707,14 @@ are telling your user that your function does more than one thing. Remember, just do one thing. **Bad:** + ```php -class Airplane { +class Airplane +{ // ... - public function getCruisingAltitude() { + + public function getCruisingAltitude() + { switch ($this->type) { case '777': return $this->getMaxAltitude() - $this->getPassengerCount(); @@ -722,33 +727,45 @@ class Airplane { } ``` -**Good**: +**Good:** + ```php -class Airplane { +class Airplane +{ // ... } -class Boeing777 extends Airplane { +class Boeing777 extends Airplane +{ // ... - public function getCruisingAltitude() { + + public function getCruisingAltitude() + { return $this->getMaxAltitude() - $this->getPassengerCount(); } } -class AirForceOne extends Airplane { +class AirForceOne extends Airplane +{ // ... - public function getCruisingAltitude() { + + public function getCruisingAltitude() + { return $this->getMaxAltitude(); } } -class Cessna extends Airplane { +class Cessna extends Airplane +{ // ... - public function getCruisingAltitude() { + + public function getCruisingAltitude() + { return $this->getMaxAltitude() - $this->getFuelExpenditure(); } } ``` + **[⬆ back to top](#table-of-contents)** ### Avoid type-checking (part 1) From b218f288c8a49da53f6eb7934d9f96eb5a3fa2b5 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 18:54:01 +0300 Subject: [PATCH 25/35] use PSR CS --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4897765..17763c0 100644 --- a/README.md +++ b/README.md @@ -819,34 +819,40 @@ function combine(int $val1, int $val2) **[⬆ back to top](#table-of-contents)** ### Remove dead code + Dead code is just as bad as duplicate code. There's no reason to keep it in your codebase. If it's not being called, get rid of it! It will still be safe in your version history if you still need it. **Bad:** + ```php -function oldRequestModule($url) { +function oldRequestModule($url) +{ // ... } -function newRequestModule($url) { +function newRequestModule($url) +{ // ... } $request = newRequestModule($requestUrl); inventoryTracker('apples', $request, 'www.inventory-awesome.io'); - ``` -**Good**: +**Good:** + ```php -function requestModule($url) { +function requestModule($url) +{ // ... } $request = requestModule($requestUrl); inventoryTracker('apples', $request, 'www.inventory-awesome.io'); ``` + **[⬆ back to top](#table-of-contents)** From 03af7a08961c1b011e6297ddf3f361700ad308b2 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 18:56:35 +0300 Subject: [PATCH 26/35] use PSR CS --- README.md | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4897765..707853e 100644 --- a/README.md +++ b/README.md @@ -852,6 +852,7 @@ inventoryTracker('apples', $request, 'www.inventory-awesome.io'); ## **Objects and Data Structures** ### Use getters and setters + In PHP you can set `public`, `protected` and `private` keywords for methods. Using it, you can control properties modification on an object. @@ -868,8 +869,10 @@ Additionally, this is part of Open/Closed principle, from object-oriented design principles. **Bad:** + ```php -class BankAccount { +class BankAccount +{ public $balance = 1000; } @@ -879,27 +882,34 @@ $bankAccount = new BankAccount(); $bankAccount->balance -= 100; ``` -**Good**: +**Good:** + ```php -class BankAccount { +class BankAccount +{ private $balance; - - public function __construct($balance = 1000) { + + public function __construct($balance = 1000) + { $this->balance = $balance; } - - public function withdrawBalance($amount) { + + public function withdrawBalance($amount) + { if ($amount > $this->balance) { throw new \Exception('Amount greater than available balance.'); } + $this->balance -= $amount; } - - public function depositBalance($amount) { + + public function depositBalance($amount) + { $this->balance += $amount; } - - public function getBalance() { + + public function getBalance() + { return $this->balance; } } @@ -911,10 +921,9 @@ $bankAccount->withdrawBalance($shoesPrice); // Get balance $balance = $bankAccount->getBalance(); - ``` -**[⬆ back to top](#table-of-contents)** +**[⬆ back to top](#table-of-contents)** ### Make objects have private/protected members From bf037a3661603c9ba007765fce38b5aa276b0959 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 19:00:45 +0300 Subject: [PATCH 27/35] use PSR CS --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4897765..be8776c 100644 --- a/README.md +++ b/README.md @@ -919,11 +919,14 @@ $balance = $bankAccount->getBalance(); ### Make objects have private/protected members **Bad:** + ```php -class Employee { +class Employee +{ public $name; - - public function __construct($name) { + + public function __construct($name) + { $this->name = $name; } } @@ -932,12 +935,15 @@ $employee = new Employee('John Doe'); echo 'Employee name: '.$employee->name; // Employee name: John Doe ``` -**Good**: +**Good:** + ```php -class Employee { - protected $name; +class Employee +{ + private $name; - public function __construct($name) { + public function __construct($name) + { $this->name = $name; } @@ -949,6 +955,7 @@ class Employee { $employee = new Employee('John Doe'); echo 'Employee name: '.$employee->getName(); // Employee name: John Doe ``` + **[⬆ back to top](#table-of-contents)** From 2a9cef35718463b1d3a0f3b668c70adc89af7e37 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 19:43:35 +0300 Subject: [PATCH 28/35] remove invalid comment --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 49fb881..d89bf87 100644 --- a/README.md +++ b/README.md @@ -1447,8 +1447,6 @@ class SuperWorker implements Worker class Manager { - /** @var WorkerInterface $worker **/ - private $worker; public function __construct(Worker $worker) From 6f59430697b13bb6f40cb9bdf633cdcf3378df1b Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 5 Sep 2017 21:43:43 +0300 Subject: [PATCH 29/35] rename classes and interface --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d89bf87..7b3b471 100644 --- a/README.md +++ b/README.md @@ -1389,7 +1389,7 @@ it makes your code hard to refactor. **Bad:** ```php -class Worker +class Employee { public function work() { @@ -1397,7 +1397,7 @@ class Worker } } -class SuperWorker extends Worker +class Robot extends Employee { public function work() { @@ -1407,16 +1407,16 @@ class SuperWorker extends Worker class Manager { - private $worker; + private $employee; - public function __construct(Worker $worker) + public function __construct(Employee $employee) { - $this->worker = $worker; + $this->employee = $employee; } public function manage() { - $this->worker->work(); + $this->employee->work(); } } ``` @@ -1424,12 +1424,12 @@ class Manager **Good:** ```php -interface Worker +interface Employee { public function work(); } -class SumeWorker implements Worker +class Human implements Employee { public function work() { @@ -1437,7 +1437,7 @@ class SumeWorker implements Worker } } -class SuperWorker implements Worker +class Robot implements Employee { public function work() { @@ -1447,16 +1447,16 @@ class SuperWorker implements Worker class Manager { - private $worker; + private $employee; - public function __construct(Worker $worker) + public function __construct(Employee $employee) { - $this->worker = $worker; + $this->employee = $employee; } public function manage() { - $this->worker->work(); + $this->employee->work(); } } ``` From e1d22a8ed772df967ac6e58bfaaf59fe868093ab Mon Sep 17 00:00:00 2001 From: zouyi Date: Wed, 6 Sep 2017 09:42:10 +0800 Subject: [PATCH 30/35] Update README.md add #table-of-contents --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf68a53..9029150 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ 4. [I: Interface Segregation Principle (ISP)](#interface-segregation-principle-isp) 5. [D: Dependency Inversion Principle (DIP)](#dependency-inversion-principle-dip) 6. [Don’t repeat yourself (DRY)](#dont-repeat-yourself-dry) + 7. [Tanslations](#Translations) ## Introduction @@ -1731,7 +1732,7 @@ function showList($employees) -## Translation +## Translations This is also available in other languages: - ![cn](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png) **Chinese**: From b9d4c3025134ffeaadd4f64252323be29792a8f5 Mon Sep 17 00:00:00 2001 From: zouyi Date: Wed, 6 Sep 2017 09:44:07 +0800 Subject: [PATCH 31/35] Update README.md use lower case --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9029150..7bca6fb 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ 4. [I: Interface Segregation Principle (ISP)](#interface-segregation-principle-isp) 5. [D: Dependency Inversion Principle (DIP)](#dependency-inversion-principle-dip) 6. [Don’t repeat yourself (DRY)](#dont-repeat-yourself-dry) - 7. [Tanslations](#Translations) + 7. [Tanslations](#translations) ## Introduction From b82c80d371c306b2608de20181cec235e16cfe8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emin=20=C5=9Een?= Date: Wed, 6 Sep 2017 09:20:12 +0300 Subject: [PATCH 32/35] Correct CS in objects --- README.md | 186 +++++++++++++++++++++++++++++------------------------- 1 file changed, 99 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index bf69a48..32af8d5 100644 --- a/README.md +++ b/README.md @@ -1041,20 +1041,24 @@ your codebase. **Bad:** ```php -class UserSettings { +class UserSettings +{ private $user; - public function __construct($user) { + public function __construct($user) + { $this->user = $user; } - public function changeSettings($settings) { + public function changeSettings($settings) + { if ($this->verifyCredentials()) { // ... } } - private function verifyCredentials() { + private function verifyCredentials() + { // ... } } @@ -1062,28 +1066,35 @@ class UserSettings { **Good:** ```php -class UserAuth { +class UserAuth +{ private $user; - public function __construct($user) { + public function __construct($user) + { $this->user = $user; } - public function verifyCredentials() { + public function verifyCredentials() + { // ... } } -class UserSettings { +class UserSettings +{ private $user; + private $auth; - public function __construct($user) { + public function __construct($user) + { $this->user = $user; $this->auth = new UserAuth($user); } - - public function changeSettings($settings) { + + public function changeSettings($settings) + { if ($this->auth->verifyCredentials()) { // ... } @@ -1117,6 +1128,7 @@ class AjaxAdapter extends Adapter public function __construct() { parent::__construct(); + $this->name = 'ajaxAdapter'; } } @@ -1126,6 +1138,7 @@ class NodeAdapter extends Adapter public function __construct() { parent::__construct(); + $this->name = 'nodeAdapter'; } } @@ -1138,7 +1151,7 @@ class HttpRequester { $this->adapter = $adapter; } - + public function fetch($url) { $adapterName = $this->adapter->getName(); @@ -1149,12 +1162,12 @@ class HttpRequester return $this->makeHttpCall($url); } } - + protected function makeAjaxCall($url) { // request and return promise } - + protected function makeHttpCall($url) { // request and return promise @@ -1224,14 +1237,8 @@ get into trouble. ```php class Rectangle { - protected $width; - protected $height; - - public function __construct() - { - $this->width = 0; - $this->height = 0; - } + protected $width = 0; + protected $height = 0; public function render($area) { @@ -1286,8 +1293,8 @@ renderLargeRectangles($rectangles); ```php abstract class Shape { - protected $width; - protected $height; + protected $width = 0; + protected $height = 0; abstract public function getArea(); @@ -1299,13 +1306,6 @@ abstract class Shape class Rectangle extends Shape { - public function __construct() - { - parent::__construct(); - $this->width = 0; - $this->height = 0; - } - public function setWidth($width) { $this->width = $width; @@ -1324,11 +1324,7 @@ class Rectangle extends Shape class Square extends Shape { - public function __construct() - { - parent::__construct(); - $this->length = 0; - } + protected $length = 0; public function setLength($length) { @@ -1554,28 +1550,29 @@ and you can chain further class methods onto it. **Bad:** ```php -class Car { - private $make, $model, $color; - - public function __construct() { - $this->make = 'Honda'; - $this->model = 'Accord'; - $this->color = 'white'; - } - - public function setMake($make) { +class Car +{ + private $make = 'Honda'; + private $model = 'Accord'; + private $color = 'white'; + + public function setMake($make) + { $this->make = $make; } - - public function setModel($model) { + + public function setModel($model) + { $this->model = $model; } - - public function setColor($color) { + + public function setColor($color) + { $this->color = $color; } - - public function dump() { + + public function dump() + { var_dump($this->make, $this->model, $this->color); } } @@ -1589,37 +1586,38 @@ $car->dump(); **Good:** ```php -class Car { - private $make, $model, $color; - - public function __construct() { - $this->make = 'Honda'; - $this->model = 'Accord'; - $this->color = 'white'; - } - - public function setMake($make) { +class Car +{ + private $make = 'Honda'; + private $model = 'Accord'; + private $color = 'white'; + + public function setMake($make) + { $this->make = $make; // NOTE: Returning this for chaining return $this; } - - public function setModel($model) { + + public function setModel($model) + { $this->model = $model; - + // NOTE: Returning this for chaining return $this; } - - public function setColor($color) { + + public function setColor($color) + { $this->color = $color; - + // NOTE: Returning this for chaining return $this; } - - public function dump() { + + public function dump() + { var_dump($this->make, $this->model, $this->color); } } @@ -1652,54 +1650,68 @@ relationship (Human->Animal vs. User->UserDetails). **Bad:** ```php -class Employee { - private $name, $email; +class Employee +{ + private $name; + private $email; - public function __construct($name, $email) { + public function __construct($name, $email) + { $this->name = $name; $this->email = $email; } - + // ... } // Bad because Employees "have" tax data. // EmployeeTaxData is not a type of Employee -class EmployeeTaxData extends Employee { - private $ssn, $salary; +class EmployeeTaxData extends Employee +{ + private $ssn; + private $salary; - public function __construct($name, $email, $ssn, $salary) { + public function __construct($name, $email, $ssn, $salary) + { parent::__construct($name, $email); + $this->ssn = $ssn; $this->salary = $salary; } - + // ... } ``` **Good:** ```php -class EmployeeTaxData { - private $ssn, $salary; +class EmployeeTaxData +{ + private $ssn; + private $salary; - public function __construct($ssn, $salary) { + public function __construct($ssn, $salary) + { $this->ssn = $ssn; $this->salary = $salary; } - + // ... } -class Employee { - private $name, $email, $taxData; - - public function __construct($name, $email) { +class Employee +{ + private $name; + private $email; + private $taxData; + + public function __construct($name, $email) + { $this->name = $name; $this->email = $email; } - + public function setTaxData($ssn, $salary) { $this->taxData = new EmployeeTaxData($ssn, $salary); } From 4da91b55098eb5b5c312f523dcccc4593b04acd7 Mon Sep 17 00:00:00 2001 From: Amit Merchant Date: Wed, 6 Sep 2017 12:24:09 +0530 Subject: [PATCH 33/35] Fixed a typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf69a48..3c28274 100644 --- a/README.md +++ b/README.md @@ -627,7 +627,7 @@ And now you must use instance of `Configuration` in your application. **[⬆ back to top](#table-of-contents)** ### Don't use a Singleton pattern -Singleton is a [anti-pattern](https://en.wikipedia.org/wiki/Singleton_pattern). +Singleton is an [anti-pattern](https://en.wikipedia.org/wiki/Singleton_pattern). **Bad:** From 4b4808c0d633c1ac153e5ce023cf1e0780e7eb19 Mon Sep 17 00:00:00 2001 From: Matan Noam Shavit Date: Wed, 6 Sep 2017 08:33:05 -0400 Subject: [PATCH 34/35] spelling correction Tanslations -> Translations --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf69a48..f949444 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ 4. [I: Interface Segregation Principle (ISP)](#interface-segregation-principle-isp) 5. [D: Dependency Inversion Principle (DIP)](#dependency-inversion-principle-dip) 6. [Don’t repeat yourself (DRY)](#dont-repeat-yourself-dry) - 7. [Tanslations](#translations) + 7. [Translations](#translations) ## Introduction From 7ec6881e560e85557b80b122a5621e01bdcaecd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Votruba?= Date: Wed, 6 Sep 2017 22:02:54 +0200 Subject: [PATCH 35/35] README: make human headline --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b942048..ff06378 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# clean-code-php +# Clean Code PHP ## Table of Contents 1. [Introduction](#introduction)