rspec/rules/S1186/php/rule.adoc
2022-02-04 16:28:24 +00:00

55 lines
1.1 KiB
Plaintext

There are several reasons for a method not to have a method body:
* It is an unintentional omission and should be fixed to prevent unexpected behavior in production.
* It is not yet, or never will be, supported. In this case an ``++UnsupportedOperationException++`` should be thrown.
* The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.
== Noncompliant Code Example
[source,php]
----
public function doSomething() {
}
public function doSomethingElse() {
}
----
== Compliant Solution
[source,php]
----
public function doSomething() {
// Do nothing because of X and Y.
}
public function doSomethingElse() {
throw new UnsupportedOperationException();
}
----
== Exceptions
Empty methods in abstract classes
----
abstract class Animal {
public function speak() {} // default implementation ignored
}
----
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[]