Skip to content

Commit 0c435d5

Browse files
author
Tomáš Votruba
authored
Merge pull request zedr#34 from peter-gribanov/unneeded_context
Don't add unneeded context
2 parents b8ce6ca + 03a82e3 commit 0c435d5

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,34 +151,36 @@ foreach ($locations as $location) {
151151

152152

153153
### Don't add unneeded context
154+
154155
If your class/object name tells you something, don't repeat that in your
155156
variable name.
156157

157158
**Bad:**
159+
158160
```php
159-
$car = [
160-
'carMake' => 'Honda',
161-
'carModel' => 'Accord',
162-
'carColor' => 'Blue',
163-
];
161+
class Car
162+
{
163+
public $carMake;
164+
public $carModel;
165+
public $carColor;
164166

165-
function paintCar(&$car) {
166-
$car['carColor'] = 'Red';
167+
//...
167168
}
168169
```
169170

170171
**Good**:
172+
171173
```php
172-
$car = [
173-
'make' => 'Honda',
174-
'model' => 'Accord',
175-
'color' => 'Blue',
176-
];
174+
class Car
175+
{
176+
public $make;
177+
public $model;
178+
public $color;
177179

178-
function paintCar(&$car) {
179-
$car['color'] = 'Red';
180+
//...
180181
}
181182
```
183+
182184
**[⬆ back to top](#table-of-contents)**
183185

184186
### Use default arguments instead of short circuiting or conditionals

0 commit comments

Comments
 (0)