From 0eb9d0405be18aa0c369777324176923586ab792 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 28 Sep 2017 17:39:57 +0300 Subject: [PATCH 1/4] zipCode is required --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 96757f2..348c1c6 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ if ($user->access & User::ACCESS_UPDATE) { ```php $address = 'One Infinite Loop, Cupertino 95014'; -$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/'; +$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})$/'; preg_match($cityZipCodeRegex, $address, $matches); saveCityZipCode($matches[1], $matches[2]); @@ -163,7 +163,7 @@ It's better, but we are still heavily dependent on regex. ```php $address = 'One Infinite Loop, Cupertino 95014'; -$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/'; +$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})$/'; preg_match($cityZipCodeRegex, $address, $matches); [, $city, $zipCode] = $matches; @@ -176,7 +176,7 @@ Decrease dependence on regex by naming subpatterns. ```php $address = 'One Infinite Loop, Cupertino 95014'; -$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(?.+?)\s*(?\d{5})?$/'; +$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(?.+?)\s*(?\d{5})$/'; preg_match($cityZipCodeRegex, $address, $matches); saveCityZipCode($matches['city'], $matches['zipCode']); From dc125f02c93f2be4f25109b19c481f6cba909a46 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 28 Sep 2017 17:41:05 +0300 Subject: [PATCH 2/4] optimize cityZipCodeRegex --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 348c1c6..d767792 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ if ($user->access & User::ACCESS_UPDATE) { ```php $address = 'One Infinite Loop, Cupertino 95014'; -$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})$/'; +$cityZipCodeRegex = '/^[^,]+,\s*(.+?)\s*(\d{5})$/'; preg_match($cityZipCodeRegex, $address, $matches); saveCityZipCode($matches[1], $matches[2]); @@ -163,7 +163,7 @@ It's better, but we are still heavily dependent on regex. ```php $address = 'One Infinite Loop, Cupertino 95014'; -$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})$/'; +$cityZipCodeRegex = '/^[^,]+,\s*(.+?)\s*(\d{5})$/'; preg_match($cityZipCodeRegex, $address, $matches); [, $city, $zipCode] = $matches; @@ -176,7 +176,7 @@ Decrease dependence on regex by naming subpatterns. ```php $address = 'One Infinite Loop, Cupertino 95014'; -$cityZipCodeRegex = '/^[^,\\]+[,\\\s]+(?.+?)\s*(?\d{5})$/'; +$cityZipCodeRegex = '/^[^,]+,\s*(?.+?)\s*(?\d{5})$/'; preg_match($cityZipCodeRegex, $address, $matches); saveCityZipCode($matches['city'], $matches['zipCode']); From 40ca2e5959264ce560bf0d93d47724c80666264c Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Fri, 6 Oct 2017 11:11:00 +0300 Subject: [PATCH 3/4] rename methods in BankAccount --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 96757f2..d762d93 100644 --- a/README.md +++ b/README.md @@ -1129,7 +1129,7 @@ class BankAccount $this->balance = $balance; } - public function withdrawBalance(int $amount): void + public function withdraw(int $amount): void { if ($amount > $this->balance) { throw new \Exception('Amount greater than available balance.'); @@ -1138,12 +1138,12 @@ class BankAccount $this->balance -= $amount; } - public function depositBalance(int $amount): void + public function deposit(int $amount): void { $this->balance += $amount; } - public function getBalance(): int + public function balance(): int { return $this->balance; } @@ -1152,10 +1152,10 @@ class BankAccount $bankAccount = new BankAccount(); // Buy shoes... -$bankAccount->withdrawBalance($shoesPrice); +$bankAccount->withdraw($shoesPrice); // Get balance -$balance = $bankAccount->getBalance(); +$balance = $bankAccount->balance(); ``` **[⬆ back to top](#table-of-contents)** From 27103f43efd4dee1fcaf5769071f7264ea75bb12 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Sat, 7 Oct 2017 09:48:29 +0300 Subject: [PATCH 4/4] Rename get balance method --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d762d93..62fd2dc 100644 --- a/README.md +++ b/README.md @@ -1143,7 +1143,7 @@ class BankAccount $this->balance += $amount; } - public function balance(): int +    public function getBalance(): int { return $this->balance; } @@ -1155,7 +1155,7 @@ $bankAccount = new BankAccount(); $bankAccount->withdraw($shoesPrice); // Get balance -$balance = $bankAccount->balance(); +$balance = $bankAccount->getBalance(); ``` **[⬆ back to top](#table-of-contents)**