rspec/rules/S2004/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

58 lines
1.1 KiB
Plaintext

== Why is this an issue?
In PHP, nested functions are functions, which are defined inside other functions.
They have access to the variables of the enclosing functions.
Once the parent function declares the nested function, the nested function becomes available to the global scope.
Code that uses nested functions can become difficult to read, refactor and to maintain and should therefore be avoided.
=== Noncompliant code example
With the default threshold of 3 level:
[source,php,diff-id=1,diff-type=noncompliant]
----
function f () {
function f_inner () {
function f_inner_inner() {
function f_inner_inner_inner() { // Noncompliant
}
}
}
}
----
== Resources
=== Documentation
* https://www.php.net/manual/en/functions.user-defined.php[PHP Manual - User defined functions]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Refactor this code to not nest functions more than {n} levels deep.
=== Parameters
.max
****
----
3
----
Maximum allowed number of nested functions
****
endif::env-github,rspecator-view[]