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

35 lines
1.1 KiB
Plaintext

== Why is this an issue?
The ability to define default values for method arguments can make a method easier to use. Default argument values allow callers to specify as many or as few arguments as they want while getting the same functionality and minimizing boilerplate, wrapper code.
But all method arguments with default values should be declared after the method arguments without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values in order to "get to" the non-default arguments.
=== Noncompliant code example
[source,php]
----
function makeyogurt($type = "acidophilus", $flavor){...} // Noncompliant
makeyogurt("raspberry")}} // Runtime error: Missing argument 2 in call to makeyogurt()
----
=== Compliant solution
[source,php]
----
function makeyogurt($flavor, $type = "acidophilus", ){...}
makeyogurt("raspberry")}} // Works as expected
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
endif::env-github,rspecator-view[]