rspec/rules/S107/pli/rule.adoc

53 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 10:16:44 +02:00
Procedures with excessive parameters are difficult to use, as one needs to figure out what each parameter is.
2021-02-02 15:02:10 +01:00
2020-06-30 10:16:44 +02:00
In many cases, the procedure can either be split into several smaller ones, or a better data structure can be found.
2021-02-02 15:02:10 +01:00
2020-06-30 10:16:44 +02:00
This rule verifies that each procedure has at most the given number of parameters.
=== Noncompliant code example
2020-06-30 10:16:44 +02:00
2022-02-04 17:28:24 +01:00
[source,pli]
2020-06-30 10:16:44 +02:00
----
foo: proc options(main);
declare myArray (9) fixed decimal init (1, 2, 3, 4, 5, 6, 7, 8, 9);
put list (mySum(myArray(1), myArray(2), myArray(3), myArray(4), myArray(5), myArray(6), myArray(7), myArray(8), myArray(9)));
end;
mySum: proc (a1, a2, a3, a4, a5, a6, a7, a8, a9) returns (fixed decimal); /* Non-Compliant - too many parameters */
declare (a1, a2, a3, a4, a5, a6, a7, a8, a9) fixed decimal;
return (a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9);
end;
----
=== Compliant solution
2020-06-30 10:16:44 +02:00
2022-02-04 17:28:24 +01:00
[source,pli]
2020-06-30 10:16:44 +02:00
----
foo: proc options(main);
declare myArray (9) fixed decimal init (1, 2, 3, 4, 5, 6, 7, 8, 9);
put list (sum(myArray)); /* Compliant - uses the built-in sum() function which works on an array */
end;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::parameters.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]