From 03a82e35c2a9bb0fb3389b82f22c5689517ef5a7 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 30 Aug 2017 19:18:03 +0300 Subject: [PATCH] correct examples of don't add unneeded context --- README.md | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4455b29..c0525be 100644 --- a/README.md +++ b/README.md @@ -151,34 +151,36 @@ foreach ($locations as $location) { ### Don't add unneeded context + If your class/object name tells you something, don't repeat that in your variable name. **Bad:** -```php -$car = [ - 'carMake' => 'Honda', - 'carModel' => 'Accord', - 'carColor' => 'Blue', -]; -function paintCar(&$car) { - $car['carColor'] = 'Red'; +```php +class Car +{ + public $carMake; + public $carModel; + public $carColor; + + //... } ``` **Good**: -```php -$car = [ - 'make' => 'Honda', - 'model' => 'Accord', - 'color' => 'Blue', -]; -function paintCar(&$car) { - $car['color'] = 'Red'; +```php +class Car +{ + public $make; + public $model; + public $color; + + //... } ``` + **[⬆ back to top](#table-of-contents)** ### Use default arguments instead of short circuiting or conditionals