From 7909ca8bee68636892fe85161996b59480303031 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Tue, 9 Jan 2018 11:12:39 +0300 Subject: [PATCH 1/8] format Comparison section --- README.md | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f18eb8e..5edf958 100644 --- a/README.md +++ b/README.md @@ -390,34 +390,38 @@ function createMicrobrewery(string $breweryName = 'Hipster Brew Co.'): void ## Comparison -**[⬆ back to top](#table-of-contents)** - ### Use [identical comparison](http://php.net/manual/en/language.operators.comparison.php) **Not good:** +The simple comparison will convert the string in an integer. + ```php $a = '42'; $b = 42; -Use the simple comparison will convert the string in an int -if( $a != $b ) { - //The expression will always passes +if ($a != $b) { + // The expression will always passes } - ``` -The comparison $a != $b return false but in fact it's true ! -The string '42' is different than the int 42 + +The comparison `$a != $b` return `FALSE` but in fact it's `TRUE`! +The string `42` is different than the integer `42`. **Good:** -Use the identical comparison will compare type and value -```php -if( $a !== $b ) { - //The expression is verified -} +The identical comparison will compare type and value. + +```php +$a = '42'; +$b = 42; + +if ($a !== $b) { + // The expression is verified +} ``` -The comparison $a !== $b return true. + +The comparison `$a !== $b` return `TRUE`. **[⬆ back to top](#table-of-contents)** From 858d5f12e38434e21a764c0decbe7e2914c0a0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B9i=20Vi=E1=BA=BFt=20H=C6=B0=E1=BB=9Bng?= Date: Mon, 15 Jan 2018 14:24:42 +0700 Subject: [PATCH 2/8] Update README.md Add translate for Vietnamese --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f18eb8e..d2a88da 100644 --- a/README.md +++ b/README.md @@ -2085,6 +2085,7 @@ This is also available in other languages: * :thailand: **Thai:** * [panuwizzle/clean-code-php](https://github.com/panuwizzle/clean-code-php) * :fr: **French:** - * [errorname/clean-code-php](https://github.com/errorname/clean-code-php) + * [viethuongdev/clean-code-php](https://github.com/viethuongdev/clean-code-php) +* :vi: **Vietnamese** **[⬆ back to top](#table-of-contents)** From aa7a7ebec5bde33ddc8591842cda1f93b951b638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B9i=20Vi=E1=BA=BFt=20H=C6=B0=E1=BB=9Bng?= Date: Mon, 15 Jan 2018 14:27:48 +0700 Subject: [PATCH 3/8] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2a88da..09dfadf 100644 --- a/README.md +++ b/README.md @@ -2085,7 +2085,8 @@ This is also available in other languages: * :thailand: **Thai:** * [panuwizzle/clean-code-php](https://github.com/panuwizzle/clean-code-php) * :fr: **French:** - * [viethuongdev/clean-code-php](https://github.com/viethuongdev/clean-code-php) + * [errorname/clean-code-php](https://github.com/errorname/clean-code-php) * :vi: **Vietnamese** + * [viethuongdev/clean-code-php](https://github.com/viethuongdev/clean-code-php) **[⬆ back to top](#table-of-contents)** From 3b30f1eb35384bdd279c39386f21d834d3c19604 Mon Sep 17 00:00:00 2001 From: Borislav Kosun Date: Mon, 29 Jan 2018 02:59:00 +0200 Subject: [PATCH 4/8] Fixed a link in the menu (Comparison) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f18eb8e..b069279 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ * [Avoid Mental Mapping](#avoid-mental-mapping) * [Don't add unneeded context](#dont-add-unneeded-context) * [Use default arguments instead of short circuiting or conditionals](#use-default-arguments-instead-of-short-circuiting-or-conditionals) - 3. [Comparaison](#comparaison) + 3. [Comparison](#comparison) * [Use identical comparison](#identical_comparison) 4. [Functions](#functions) * [Function arguments (2 or fewer ideally)](#function-arguments-2-or-fewer-ideally) From 6ca513892b40e39ea9e34839570487f4dde6425c Mon Sep 17 00:00:00 2001 From: Borislav Kosun Date: Mon, 29 Jan 2018 03:00:45 +0200 Subject: [PATCH 5/8] Fixed a link in the menu (Use identical compar...) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b069279..0e26786 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ * [Don't add unneeded context](#dont-add-unneeded-context) * [Use default arguments instead of short circuiting or conditionals](#use-default-arguments-instead-of-short-circuiting-or-conditionals) 3. [Comparison](#comparison) - * [Use identical comparison](#identical_comparison) + * [Use identical comparison](#use-identical-comparison) 4. [Functions](#functions) * [Function arguments (2 or fewer ideally)](#function-arguments-2-or-fewer-ideally) * [Functions should do one thing](#functions-should-do-one-thing) From 46a388272160e29f7a4154b48174e5e6ebdc9a74 Mon Sep 17 00:00:00 2001 From: Michael Millar Date: Mon, 29 Jan 2018 22:08:34 +0100 Subject: [PATCH 6/8] fixed some typos and inconsistencies --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f18eb8e..ee1d5ea 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Clean Code PHP +# Clean Code PHP ## Table of Contents @@ -14,7 +14,7 @@ * [Avoid Mental Mapping](#avoid-mental-mapping) * [Don't add unneeded context](#dont-add-unneeded-context) * [Use default arguments instead of short circuiting or conditionals](#use-default-arguments-instead-of-short-circuiting-or-conditionals) - 3. [Comparaison](#comparaison) + 3. [Comparison](#comparison) * [Use identical comparison](#identical_comparison) 4. [Functions](#functions) * [Function arguments (2 or fewer ideally)](#function-arguments-2-or-fewer-ideally) @@ -57,7 +57,7 @@ Not every principle herein has to be strictly followed, and even fewer will be u agreed upon. These are guidelines and nothing more, but they are ones codified over many years of collective experience by the authors of *Clean Code*. -Inspired from [clean-code-javascript](https://github.com/ryanmcdermott/clean-code-javascript) +Inspired from [clean-code-javascript](https://github.com/ryanmcdermott/clean-code-javascript). Although many developers still use PHP 5, most of the examples in this article only work with PHP 7.1+. @@ -188,7 +188,7 @@ saveCityZipCode($matches['city'], $matches['zipCode']); ### Avoid nesting too deeply and return early (part 1) -Too many if else statements can make your code hard to follow. Explicit is better +Too many if-else statements can make your code hard to follow. Explicit is better than implicit. **Bad:** @@ -406,8 +406,8 @@ if( $a != $b ) { } ``` -The comparison $a != $b return false but in fact it's true ! -The string '42' is different than the int 42 +The comparison $a != $b returns false but in fact it's true! +The string '42' is different than the int 42. **Good:** Use the identical comparison will compare type and value @@ -417,7 +417,7 @@ if( $a !== $b ) { } ``` -The comparison $a !== $b return true. +The comparison $a !== $b returns true. **[⬆ back to top](#table-of-contents)** @@ -783,7 +783,7 @@ var_dump($newName); // ['Ryan', 'McDermott']; Polluting globals is a bad practice in many languages because you could clash with another library and the user of your API would be none-the-wiser until they get an exception in -production. Let's think about an example: what if you wanted to have configuration array. +production. Let's think about an example: what if you wanted to have configuration array? You could write global function like `config()`, but it could clash with another library that tried to do the same thing. @@ -1356,10 +1356,10 @@ pattern reduces the verbosity of the code (for example the [PHPUnit Mock Builder or the [Doctrine Query Builder](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/query-builder.html)), more often it comes at some costs: -1. Breaks [Encapsulation](https://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29) -2. Breaks [Decorators](https://en.wikipedia.org/wiki/Decorator_pattern) -3. Is harder to [mock](https://en.wikipedia.org/wiki/Mock_object) in a test suite -4. Makes diffs of commits harder to read +1. Breaks [Encapsulation](https://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29). +2. Breaks [Decorators](https://en.wikipedia.org/wiki/Decorator_pattern). +3. Is harder to [mock](https://en.wikipedia.org/wiki/Mock_object) in a test suite. +4. Makes diffs of commits harder to read. For more informations you can read the full [blog post](https://ocramius.github.io/blog/fluent-interfaces-are-evil/) on this topic written by [Marco Pivetta](https://github.com/Ocramius). @@ -1792,7 +1792,7 @@ ISP states that "Clients should not be forced to depend upon interfaces that they do not use." A good example to look at that demonstrates this principle is for -classes that require large settings objects. Not requiring clients to setup +classes that require large settings objects. Not requiring clients to set up huge amounts of options is beneficial, because most of the time they won't need all of the settings. Making them optional helps prevent having a "fat interface". @@ -1982,7 +1982,7 @@ tomatoes, onions, garlic, spices, etc. If you have multiple lists that you keep this on, then all have to be updated when you serve a dish with tomatoes in them. If you only have one list, there's only one place to update! -Oftentimes you have duplicate code because you have two or more slightly +Often you have duplicate code because you have two or more slightly different things, that share a lot in common, but their differences force you to have two or more separate functions that do much of the same things. Removing duplicate code means creating an abstraction that can handle this set of different @@ -1992,7 +1992,7 @@ Getting the abstraction right is critical, that's why you should follow the SOLID principles laid out in the [Classes](#classes) section. Bad abstractions can be worse than duplicate code, so be careful! Having said this, if you can make a good abstraction, do it! Don't repeat yourself, otherwise you'll find yourself -updating multiple places anytime you want to change one thing. +updating multiple places any time you want to change one thing. **Bad:** From e90be29ff38a9a40901591cf339e1a8e2d3aa1b0 Mon Sep 17 00:00:00 2001 From: jopacicdev Date: Fri, 16 Feb 2018 22:35:08 +0100 Subject: [PATCH 7/8] Wording adjustment --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f18eb8e..077d658 100644 --- a/README.md +++ b/README.md @@ -399,10 +399,10 @@ function createMicrobrewery(string $breweryName = 'Hipster Brew Co.'): void ```php $a = '42'; $b = 42; -Use the simple comparison will convert the string in an int +// Use the simple comparison that will convert the string in an int if( $a != $b ) { - //The expression will always passes + // The expression will always pass } ``` From 9ae7bbf8f634c4ad370e5ea73b1b48ff65db8cf7 Mon Sep 17 00:00:00 2001 From: yujinee Date: Mon, 26 Feb 2018 03:24:39 +0900 Subject: [PATCH 8/8] add Korean translation I wrote the korean translation for this guide. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f18eb8e..40b5d90 100644 --- a/README.md +++ b/README.md @@ -2086,5 +2086,7 @@ This is also available in other languages: * [panuwizzle/clean-code-php](https://github.com/panuwizzle/clean-code-php) * :fr: **French:** * [errorname/clean-code-php](https://github.com/errorname/clean-code-php) - +* 🇰🇷 **Korean:** + * [yujineeee/clean-code-php](https://github.com/yujineeee/clean-code-php) + **[⬆ back to top](#table-of-contents)**