rspec/rules/S1186/php/rule.adoc

68 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
:operationName: function
include::../description.adoc[]
2020-06-30 12:47:33 +02:00
=== Exceptions
This rule doesn't raise an issue on empty methods in abstract classes.
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2020-06-30 12:47:33 +02:00
----
abstract class Animal {
public function speak() {} // default implementation ignored
2020-06-30 12:47:33 +02:00
}
----
== How to fix it
2020-06-30 12:47:33 +02:00
=== Code examples
==== Noncompliant code example
[source,php,diff-id=1,diff-type=noncompliant]
2020-06-30 12:47:33 +02:00
----
public function shouldNotBeEmpty() { // Noncompliant - method is empty
2020-06-30 12:47:33 +02:00
}
public function notImplemented() { // Noncompliant - method is empty
2020-06-30 12:47:33 +02:00
}
public function emptyOnPurpose() { // Noncompliant - method is empty
}
----
2020-06-30 12:47:33 +02:00
==== Compliant solution
[source,php,diff-id=1,diff-type=compliant]
2020-06-30 12:47:33 +02:00
----
public function shouldNotBeEmpty() {
doSomething();
}
public function notImplemented() {
throw new Exception('notImplemented() cannot be performed because ...');
}
public function emptyOnPurpose() {
// comment explaining why the method is empty
2020-06-30 12:47:33 +02:00
}
----
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[]