mirror of
https://github.com/jupeter/clean-code-php.git
synced 2025-09-26 14:08:59 +02:00
Merge pull request #34 from peter-gribanov/unneeded_context
Don't add unneeded context
This commit is contained in:
34
README.md
34
README.md
@@ -151,34 +151,36 @@ foreach ($locations as $location) {
|
|||||||
|
|
||||||
|
|
||||||
### Don't add unneeded context
|
### Don't add unneeded context
|
||||||
|
|
||||||
If your class/object name tells you something, don't repeat that in your
|
If your class/object name tells you something, don't repeat that in your
|
||||||
variable name.
|
variable name.
|
||||||
|
|
||||||
**Bad:**
|
**Bad:**
|
||||||
```php
|
|
||||||
$car = [
|
|
||||||
'carMake' => 'Honda',
|
|
||||||
'carModel' => 'Accord',
|
|
||||||
'carColor' => 'Blue',
|
|
||||||
];
|
|
||||||
|
|
||||||
function paintCar(&$car) {
|
```php
|
||||||
$car['carColor'] = 'Red';
|
class Car
|
||||||
|
{
|
||||||
|
public $carMake;
|
||||||
|
public $carModel;
|
||||||
|
public $carColor;
|
||||||
|
|
||||||
|
//...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Good**:
|
**Good**:
|
||||||
```php
|
|
||||||
$car = [
|
|
||||||
'make' => 'Honda',
|
|
||||||
'model' => 'Accord',
|
|
||||||
'color' => 'Blue',
|
|
||||||
];
|
|
||||||
|
|
||||||
function paintCar(&$car) {
|
```php
|
||||||
$car['color'] = 'Red';
|
class Car
|
||||||
|
{
|
||||||
|
public $make;
|
||||||
|
public $model;
|
||||||
|
public $color;
|
||||||
|
|
||||||
|
//...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**[⬆ back to top](#table-of-contents)**
|
**[⬆ back to top](#table-of-contents)**
|
||||||
|
|
||||||
### Use default arguments instead of short circuiting or conditionals
|
### Use default arguments instead of short circuiting or conditionals
|
||||||
|
Reference in New Issue
Block a user