
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
56 lines
1.6 KiB
Plaintext
56 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
||
|
||
The `empty()` function in PHP is specifically designed to check if a variable is empty, and it returns true if the variable is empty or evaluates to false. It handles various types of values, such as empty strings, zero, null, and arrays with no elements. This makes the code more readable because it clearly expresses the intention of checking for emptiness.
|
||
|
||
On the other hand, the `count()` function in PHP is primarily used to count the number of elements in an array or the properties of an object. It’s less explicit and may be less intuitive for someone reading the code.
|
||
|
||
=== What is the potential impact?
|
||
|
||
In terms of performance, `empty()` is generally faster than `count()` because it doesn’t need to iterate over all the elements in an array to count them. Instead, it directly checks if the variable is empty or evaluates to false. This can be advantageous when dealing with large arrays or performance-sensitive code.
|
||
|
||
== How to fix it
|
||
|
||
=== Code examples
|
||
|
||
==== Noncompliant code example
|
||
|
||
[source,php,diff-id=1,diff-type=noncompliant]
|
||
----
|
||
if (count($a) === 0) { // Noncompliant
|
||
echo $a[0];
|
||
}
|
||
----
|
||
|
||
==== Compliant solution
|
||
|
||
[source,php,diff-id=1,diff-type=compliant]
|
||
----
|
||
if (empty($a)) {
|
||
echo $a[0];
|
||
}
|
||
----
|
||
|
||
== Resources
|
||
|
||
=== Documentation
|
||
|
||
* https://www.php.net/manual/en/function.empty[PHP Manual - empty]
|
||
* https://www.php.net/manual/en/function.count.php[PHP Manual - count]
|
||
|
||
|
||
ifdef::env-github,rspecator-view[]
|
||
|
||
'''
|
||
== Implementation Specification
|
||
(visible only on this page)
|
||
|
||
include::../message.adoc[]
|
||
|
||
'''
|
||
== Comments And Links
|
||
(visible only on this page)
|
||
|
||
include::../comments-and-links.adoc[]
|
||
|
||
endif::env-github,rspecator-view[]
|