original_string: protected static function swapCallable(&$optional, &$callable, $default = null, $callable_required = true)
      {
          $is_swapped = false;
          if (is_callable($optional)) {
              $callable = $optional;
              $optional = $default;
              $is_swapped  = true;
          }
          if ($callable_required && !$callable) {
              throw new Exceptions\InvalidArgumentException(
                  "A callable object is required."
              );
          }
          
          return $is_swapped;
      }
code: protected static function swapCallable(&$optional, &$callable, $default = null, $callable_required = true)
      {
          $is_swapped = false;
          if (is_callable($optional)) {
              $callable = $optional;
              $optional = $default;
              $is_swapped  = true;
          }
          if ($callable_required && !$callable) {
              throw new Exceptions\InvalidArgumentException(
                  "A callable object is required."
              );
          }
          
          return $is_swapped;
      }
code_tokens: protected static function swapCallable ( & $ optional , & $ callable , $ default = null , $ callable_required = true ) { $ is_swapped = false ; if ( is_callable ( $ optional ) ) { $ callable = $ optional ; $ optional = $ default ; $ is_swapped = true ; } if ( $ callable_required && ! $ callable ) { throw new Exceptions \ InvalidArgumentException ( "A callable object is required." ) ; } return $ is_swapped ; }
docstring: Swaps two variables when the second is a callable object
  
  Used to create functions/methods which have callbacks as the final argument, and
  it's desirable to make middle argument optional, while the callback remains the
  final argument.
  
  Throws an exception when $callable_required is true, and the callable object is
  empty.
  
  Returns true if the arguments were swapped, false if not.
  
  Examples:
  ```php
  public function joinArray(array $values, $separator, callable $callback = null)
  {
  $this->swapCallable($separator, $callback, "-");
  $values = array_map($callback, $values);
  return join($separator, $values);
  }
  
  // The function above may be called normally, like this:
  $values = ["headzoo", "joe"];
  $this->joinArray($values, "-", 'Headzoo\Core\String::quote');
  
  // Or the middle argument may be omitted, and called like this:
  $this->joinArray($values, 'Headzoo\Core\String::quote');
  ```
  
  @param  mixed $optional          The optional argument
  @param  mixed $callable          Possibly a callable object
  @param  mixed $default           The optional argument default value
  @param  bool  $callable_required Whether the callable object is required (cannot be empty)
  @throws Exceptions\InvalidArgumentException When the callable is required and empty
  
  @return bool
docstring_tokens: Swaps two variables when the second is a callable object