Skip to content

Commit ed9289b

Browse files
authored
Merge pull request #3 from cassiosantos/variables
Adds $ in variable names. Fixes Object Operator (in PHP it is -> instead of .)
2 parents 6d1ab2a + 6b900ea commit ed9289b

1 file changed

Lines changed: 36 additions & 33 deletions

File tree

‎README.md‎

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ $cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/';
9696
preg_match($cityZipCodeRegex, $address, $matches);
9797

9898
list(, $city, $zipCode) = $matchers;
99-
saveCityZipCode(city, zipCode);
99+
saveCityZipCode($city, $zipCode);
100100
```
101101
**[⬆ back to top](#table-of-contents)**
102102

@@ -132,7 +132,7 @@ foreach($i=0; $i<count($locations); $i++) {
132132
// ...
133133
// ...
134134
// ...
135-
dispatch(location);
135+
dispatch($location);
136136
});
137137
```
138138
**[⬆ back to top](#table-of-contents)**
@@ -241,7 +241,7 @@ of many developers.
241241
function emailClients($clients) {
242242
foreach ($clients as $client) {
243243
$clientRecord = $db->find($client);
244-
if($clientRecord->isActive()) {
244+
if ($clientRecord->isActive()) {
245245
email($client);
246246
}
247247
}
@@ -337,7 +337,7 @@ function tokenize($code) {
337337
});
338338
});
339339

340-
return tokens;
340+
return $tokens;
341341
}
342342

343343
function lexer($tokens) {
@@ -346,7 +346,7 @@ function lexer($tokens) {
346346
$ast[] = /* ... */;
347347
});
348348

349-
return ast;
349+
return $ast;
350350
}
351351

352352
function parseBetterJSAlternative($code) {
@@ -487,8 +487,8 @@ based on a boolean.
487487

488488
**Bad:**
489489
```php
490-
function createFile(name, temp = false) {
491-
if (temp) {
490+
function createFile($name, $temp = false) {
491+
if ($temp) {
492492
touch('./temp/'.$name);
493493
} else {
494494
touch($name);
@@ -547,7 +547,7 @@ function splitIntoFirstAndLastName($name) {
547547
}
548548

549549
$name = 'Ryan McDermott';
550-
$newName = splitIntoFirstAndLastName(name);
550+
$newName = splitIntoFirstAndLastName($name);
551551

552552
var_export($name); // 'Ryan McDermott';
553553
var_export($newName); // ['Ryan', 'McDermott'];
@@ -568,7 +568,7 @@ function config() {
568568
return [
569569
'foo': 'bar',
570570
]
571-
};
571+
}
572572
```
573573

574574
**Good:**
@@ -577,7 +577,7 @@ class Configuration {
577577
private static $instance;
578578
private function __construct($configuration) {/* */}
579579
public static function getInstance() {
580-
if(self::$instance === null) {
580+
if (self::$instance === null) {
581581
self::$instance = new Configuration();
582582
}
583583
return self::$instance;
@@ -602,7 +602,7 @@ if ($fsm->state === 'fetching' && is_empty($listNode)) {
602602
**Good**:
603603
```php
604604
function shouldShowSpinner($fsm, $listNode) {
605-
return $fsm->state === 'fetching' && is_empty(listNode);
605+
return $fsm->state === 'fetching' && is_empty($listNode);
606606
}
607607

608608
if (shouldShowSpinner($fsmInstance, $listNodeInstance)) {
@@ -730,8 +730,8 @@ type declaration or strict mode.
730730
**Bad:**
731731
```php
732732
function combine($val1, $val2) {
733-
if (is_numeric($val1) && is_numeric(val2)) {
734-
return val1 + val2;
733+
if (is_numeric($val1) && is_numeric($val2)) {
734+
return $val1 + $val2;
735735
}
736736

737737
throw new \Exception('Must be of type Number');
@@ -817,7 +817,7 @@ class BankAccount {
817817
}
818818

819819
public function withdrawBalance($amount) {
820-
if($amount > $this->balance) {
820+
if ($amount > $this->balance) {
821821
throw new \Exception('Amount greater than available balance.');
822822
}
823823
$this->balance -= $amount;
@@ -854,7 +854,7 @@ class Employee {
854854
public function __construct($name) {
855855
$this->name = $name;
856856
}
857-
};
857+
}
858858

859859
$employee = new Employee('John Doe');
860860
echo 'Employee name: '.$employee->name; // Employee name: John Doe
@@ -868,10 +868,11 @@ class Employee {
868868
public function __construct($name) {
869869
$this->name = $name;
870870
}
871+
871872
public function getName() {
872873
return $this->name;
873-
};
874-
};
874+
}
875+
}
875876

876877
$employee = new Employee('John Doe');
877878
echo 'Employee name: '.$employee->getName(); // Employee name: John Doe
@@ -900,9 +901,9 @@ class UserSettings {
900901
}
901902

902903
public function changeSettings($settings) {
903-
if ($this->verifyCredentials()) {
904-
// ...
905-
}
904+
if ($this->verifyCredentials()) {
905+
// ...
906+
}
906907
}
907908

908909
private function verifyCredentials() {
@@ -955,6 +956,7 @@ abstract class Adapter {
955956
return $this->name;
956957
}
957958
}
959+
958960
class AjaxAdapter extends Adapter {
959961
public function __construct() {
960962
parent::__construct();
@@ -984,11 +986,11 @@ class HttpRequester {
984986
}
985987
}
986988

987-
protected function makeAjaxCall(url) {
989+
protected function makeAjaxCall($url) {
988990
// request and return promise
989991
}
990992

991-
protected function makeHttpCall(url) {
993+
protected function makeHttpCall($url) {
992994
// request and return promise
993995
}
994996
}
@@ -1157,8 +1159,8 @@ class Square extends Shape {
11571159

11581160
function renderLargeRectangles($rectangles) {
11591161
foreach($rectangle in $rectangles) {
1160-
if($rectangle instanceof Square) {
1161-
$rextangle->setLength(5);
1162+
if ($rectangle instanceof Square) {
1163+
$rectangle->setLength(5);
11621164
} else if ($rectangle instanceof Rectangle) {
11631165
$rectangle->setWidth(4);
11641166
$rectangle->setHeight(5);
@@ -1346,7 +1348,7 @@ class Manager {
13461348
}
13471349

13481350
public void manage() {
1349-
$this->worker.work();
1351+
$this->worker->work();
13501352
}
13511353
}
13521354

@@ -1370,6 +1372,7 @@ class Car {
13701372
$this->model = 'Accord';
13711373
$this->color = 'white';
13721374
}
1375+
13731376
public function setMake($make) {
13741377
$this->make = $make;
13751378
}
@@ -1391,7 +1394,7 @@ $car = new Car();
13911394
$car->setColor('pink');
13921395
$car->setMake('Ford');
13931396
$car->setModel('F-150');
1394-
$car.dump();
1397+
$car->dump();
13951398
```
13961399

13971400
**Good:**
@@ -1409,21 +1412,21 @@ class Car {
14091412
$this->make = $make;
14101413

14111414
// NOTE: Returning this for chaining
1412-
return this;
1415+
return $this;
14131416
}
14141417

14151418
public function setModel($model) {
14161419
$this->model = $model;
14171420

14181421
// NOTE: Returning this for chaining
1419-
return this;
1422+
return $this;
14201423
}
14211424

14221425
public function setColor($color) {
14231426
$this->color = $color;
14241427

14251428
// NOTE: Returning this for chaining
1426-
return this;
1429+
return $this;
14271430
}
14281431

14291432
public function dump() {
@@ -1432,10 +1435,10 @@ class Car {
14321435
}
14331436

14341437
$car = (new Car())
1435-
.setColor('pink')
1436-
.setMake('Ford')
1437-
.setModel('F-150')
1438-
.dump();
1438+
->setColor('pink')
1439+
->setMake('Ford')
1440+
->setModel('F-150')
1441+
->dump();
14391442
```
14401443
**[⬆ back to top](#table-of-contents)**
14411444

0 commit comments

Comments
 (0)