rspec/rules/S2681/php/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

70 lines
1.4 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,php]
----
if ($condition)
firstActionInBlock();
secondAction(); // Noncompliant; executed unconditionally
thirdAction();
if($condition) firstActionInBlock(); secondAction(); // Noncompliant; secondAction executed unconditionally
if($condition) firstActionInBlock(); // Noncompliant
secondAction(); // Executed unconditionally
$str = null;
for ($i = 0; $i < count($array); $i++)
$str = $array[$i];
doTheThing($str); // Noncompliant; executed only on last array element
----
=== Compliant solution
[source,php]
----
if ($condition) {
firstActionInBlock();
secondAction();
}
thirdAction();
if($condition) { firstActionInBlock(); secondAction(); }
if($condition) {
firstActionInBlock();
secondAction();
}
$str = null;
for ($i = 0; $i < count($array); $i++) {
$str = $array[$i];
doTheThing($str);
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
This statement will not be executed [conditionally|in a loop]; only the first statement of this n-statement block will be. The rest will execute [only once|unconditionally].
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]