concept statement in category design

appears as: statements, statement, statements
Object Design Style Guide

This is an excerpt from Manning's book Object Design Style Guide.

  • Return statements and exceptions— Returning a value from a method, throwing an exception inside a method, catching exceptions, and defining custom exception classes (section 1.9).
  • 1.9. Return statements and exceptions

    When you call a method, it will normally be executed statement by statement from the top until a return statement is encountered, or the end of the method is reached. If at some point you want to prevent further execution of a method, you can insert a return statement, making sure that the rest of the method will be skipped.

  • Improve the arrangement of statements in the following method:
    public function pop(): Element
    {
        if (count(this.elements)) > 0) {
            lastElement = array_pop(this.elements);
    
            return lastElement;
        } else {
            throw new RuntimeException('There are no more elements');
        }
    }