Verified Commit a73384d8 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3437286 by immaculatexavier, longwave: Use argument unpacking in...

Issue #3437286 by immaculatexavier, longwave: Use argument unpacking in FieldItemList::delegateMethod()
parent 5274b41a
Loading
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -220,19 +220,14 @@ public function deleteRevision() {
   *
   * @param string $method
   *   The name of the method to be invoked.
   * @param mixed ...$args
   *   Any arguments to be forwarded to the invoked method.
   *
   * @return array
   *   An array of results keyed by delta.
   */
  protected function delegateMethod($method) {
    $result = [];
    $args = array_slice(func_get_args(), 1);
    foreach ($this->list as $delta => $item) {
      // call_user_func_array() is way slower than a direct call so we avoid
      // using it if have no parameters.
      $result[$delta] = $args ? call_user_func_array([$item, $method], $args) : $item->{$method}();
    }
    return $result;
  protected function delegateMethod($method, ...$args) {
    return array_map(fn($item) => $item->{$method}(...$args), $this->list);
  }

  /**