File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
484437Flags tell your user that this function does more than one thing. Functions should
485438do one thing. Split out your functions if they are following different code paths
You can’t perform that action at this time.
0 commit comments