/** * Allow the chained calling of methods */ public function __call($method, $arguments) { // Get correct class $class = Dispatch::toClass($this->subject); // Check for unchainable methods if (Method::isUnchainable($class, $method)) { throw new BadMethodCallException('The method ' . $class . '::' . $method . ' can\'t be chained'); } // Prepend subject to arguments and call the method if (!Method::isSubjectless($method)) { array_unshift($arguments, $this->subject); } $result = $class::__callStatic($method, $arguments); // If the method is a breaker, return just the result if (Method::isBreaker($method)) { return $result; } else { $this->subject = $result; } return $this; }
public function testCantChainCertainMethods() { $method = Method::isUnchainable('Arrays', 'range'); $this->assertTrue($method); }