72 lines
1.2 KiB
Plaintext
72 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Exceptions
|
|
|
|
The usage of a code block after a `case` is allowed.
|
|
|
|
== How to fix it
|
|
|
|
The nested code blocks should be extracted into separate methods.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
public void Evaluate()
|
|
{
|
|
/* ... */
|
|
{ // Noncompliant - nested code block '{' ... '}'
|
|
int a = stack.pop();
|
|
int b = stack.pop();
|
|
int result = a + b;
|
|
stack.push(result);
|
|
}
|
|
/* ... */
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
public void Evaluate()
|
|
{
|
|
/* ... */
|
|
StackAdd();
|
|
/* ... */
|
|
}
|
|
|
|
private void StackAdd()
|
|
{
|
|
int a = stack.pop();
|
|
int b = stack.pop();
|
|
int result = a + b;
|
|
stack.push(result);
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
* Wikipedia - https://en.wikipedia.org/wiki/Single-responsibility_principle[Single Responsibility Principle]
|
|
|
|
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[]
|