Skip to content

Commit 3c98453

Browse files
fix errors and correct CS
1 parent 961e006 commit 3c98453

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

README.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,31 +307,34 @@ addMonthToDate(1, $date);
307307
**[⬆ back to top](#table-of-contents)**
308308

309309
### Functions should only be one level of abstraction
310+
310311
When you have more than one level of abstraction your function is usually
311312
doing too much. Splitting up functions leads to reusability and easier
312313
testing.
313314

314315
**Bad:**
316+
315317
```php
316-
function parseBetterJSAlternative($code) {
318+
function parseBetterJSAlternative($code)
319+
{
317320
$regexes = [
318321
// ...
319322
];
320323

321324
$statements = split(' ', $code);
322325
$tokens = [];
323-
foreach($regexes as $regex) {
324-
foreach($statements as $statement) {
326+
foreach ($regexes as $regex) {
327+
foreach ($statements as $statement) {
325328
// ...
326329
}
327330
}
328331

329332
$ast = [];
330-
foreach($tokens as $token) {
333+
foreach ($tokens as $token) {
331334
// lex...
332335
}
333336

334-
foreach($ast as $node) {
337+
foreach ($ast as $node) {
335338
// parse...
336339
}
337340
}
@@ -340,39 +343,43 @@ function parseBetterJSAlternative($code) {
340343
**Good:**
341344

342345
```php
343-
function tokenize($code) {
346+
function tokenize($code)
347+
{
344348
$regexes = [
345349
// ...
346350
];
347351

348352
$statements = split(' ', $code);
349353
$tokens = [];
350-
foreach($regexes as $regex) {
351-
foreach($statements as $statement) {
354+
foreach ($regexes as $regex) {
355+
foreach ($statements as $statement) {
352356
$tokens[] = /* ... */;
353-
});
354-
});
357+
}
358+
}
355359

356360
return $tokens;
357361
}
358362

359-
function lexer($tokens) {
363+
function lexer($tokens)
364+
{
360365
$ast = [];
361-
foreach($tokens as $token) {
366+
foreach ($tokens as $token) {
362367
$ast[] = /* ... */;
363-
});
368+
}
364369

365370
return $ast;
366371
}
367372

368-
function parseBetterJSAlternative($code) {
373+
function parseBetterJSAlternative($code)
374+
{
369375
$tokens = tokenize($code);
370376
$ast = lexer($tokens);
371-
foreach($ast as $node) {
377+
foreach ($ast as $node) {
372378
// parse...
373-
});
379+
}
374380
}
375381
```
382+
376383
**[⬆ back to top](#table-of-contents)**
377384

378385
### Remove duplicate code

0 commit comments

Comments
 (0)