Skip to content

Commit b1a55d1

Browse files
authored
Merge pull request #5 from cassiosantos/object-assign
Remove Object.assign section
2 parents c9d3572 + 53e07b4 commit b1a55d1

1 file changed

Lines changed: 0 additions & 47 deletions

File tree

‎README.md‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -433,53 +433,6 @@ function showList($employees) {
433433
```
434434
**[⬆ back to top](#table-of-contents)**
435435

436-
### Set default objects with Object.assign
437-
438-
**Bad:**
439-
```php
440-
$menuConfig = [
441-
'title' => null,
442-
'body' => 'Bar',
443-
'buttonText' => null,
444-
'cancellable' => true,
445-
];
446-
447-
function createMenu(&$config) {
448-
$config['title'] = $config['title'] ?: 'Foo';
449-
$config['body'] = $config['body'] ?: 'Bar';
450-
$config['buttonText'] = $config['buttonText'] ?: 'Baz';
451-
$config['cancellable'] = $config['cancellable'] ?: true;
452-
}
453-
454-
createMenu($menuConfig);
455-
```
456-
457-
**Good**:
458-
```php
459-
$menuConfig = [
460-
'title' => 'Order',
461-
// User did not include 'body' key
462-
'buttonText' => 'Send',
463-
'cancellable' => true,
464-
];
465-
466-
function createMenu(&$config) {
467-
$config = array_merge([
468-
'title' => 'Foo',
469-
'body' => 'Bar',
470-
'buttonText' => 'Baz',
471-
'cancellable' => true,
472-
], $config);
473-
474-
// config now equals: {title: "Order", body: "Bar", buttonText: "Send", cancellable: true}
475-
// ...
476-
}
477-
478-
createMenu($menuConfig);
479-
```
480-
**[⬆ back to top](#table-of-contents)**
481-
482-
483436
### Don't use flags as function parameters
484437
Flags tell your user that this function does more than one thing. Functions should
485438
do one thing. Split out your functions if they are following different code paths

0 commit comments

Comments
 (0)