
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
67 lines
1.7 KiB
Plaintext
67 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
|
|
|
It is recommended not to declare more than one property per statement for the sake of code readability and maintainability.
|
|
Declaring multiple properties in a single statement can make the code harder to understand and debug.
|
|
It also increases the risk of introducing errors or overlooking specific property assignments.
|
|
|
|
== How to fix it
|
|
|
|
By declaring one property per statement, developers can easily identify and modify individual properties, improving code clarity and reducing potential mistakes.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,php,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
<?php
|
|
class Foo
|
|
{
|
|
private $bar = 1, $bar2 = 2;
|
|
}
|
|
----
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
[source,php,diff-id=1,diff-type=compliant]
|
|
----
|
|
<?php
|
|
class Foo
|
|
{
|
|
private $bar1 = 1;
|
|
private $bar2 = 2;
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* https://www.php.net/manual/en/language.oop5.properties.php[PHP Manual - Properties]
|
|
* https://www.php.net/manual/en/language.operators.assignment.php[PHP Manual - Assignment Operators]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
{0} property declarations were found in this statement. Reformat the code to declare only one property per statement.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S122
|
|
|
|
=== on 27 May 2014, 11:32:54 Ann Campbell wrote:
|
|
\[~linda.martin] how is this different from the standard rule against having more than one statement per line?
|
|
|
|
=== on 27 May 2014, 15:18:18 Linda Martin wrote:
|
|
\[~ann.campbell.2] here we are talking about 2 property declarations in the same statement, so it won't be detected by the rule "one statement per line".
|
|
|
|
endif::env-github,rspecator-view[]
|