Skip to content

Commit 8eaf033

Browse files
committed
[Contributing] [Conventions] Added entry for Yoda conditions
| Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.8+ | Fixed tickets |
1 parent 59569c0 commit 8eaf033

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

contributing/code/conventions.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ must be used instead (where ``XXX`` is the name of the related thing):
7777
"replaceXXX", on the other hand, cannot add new elements. If an unrecognized
7878
key is passed to "replaceXXX" it must throw an exception.
7979

80+
.. _contributing-code-conventions-conditions:
81+
82+
Conditions
83+
----------
84+
85+
Use `Yoda condition`_ when you need to check a variable against a value.
86+
The main goal with this syntax is to avoid an accidental assignment inside the
87+
condition statements:
88+
89+
instead of:
90+
91+
.. code-block:: php
92+
93+
if ($someVar === 'some string' && $otherVar === someFunction()) {
94+
// ...
95+
}
96+
97+
it should be:
98+
99+
.. code-block:: php
100+
101+
if ('some string' === $someVar && someFunction() === $otherVar) {
102+
// ...
103+
}
104+
80105
.. _contributing-code-conventions-deprecations:
81106

82107
Deprecations
@@ -104,3 +129,5 @@ the migration starting one or two minor versions before the version where the
104129
feature will be removed (depending on the criticality of the removal)::
105130

106131
trigger_error('XXX() is deprecated since version 2.X and will be removed in 2.Y. Use XXX instead.', E_USER_DEPRECATED);
132+
133+
.. _`Yoda condition`: https://en.wikipedia.org/wiki/Yoda_conditions

0 commit comments

Comments
 (0)