original_string: public function formatResults(callable $formatter = null, $mode = 0)
      {
          if ($mode === self::OVERWRITE) {
              $this->_formatters = [];
          }
          if ($formatter === null) {
              if ($mode !== self::OVERWRITE) {
                  deprecationWarning(
                      'Using QueryTrait::formatResults() as a getter is deprecated. ' .
                      'Use getResultFormatters() instead.'
                  );
              }
  
              return $this->_formatters;
          }
  
          if ($mode === self::PREPEND) {
              array_unshift($this->_formatters, $formatter);
  
              return $this;
          }
  
          $this->_formatters[] = $formatter;
  
          return $this;
      }
code: public function formatResults(callable $formatter = null, $mode = 0)
      {
          if ($mode === self::OVERWRITE) {
              $this->_formatters = [];
          }
          if ($formatter === null) {
              if ($mode !== self::OVERWRITE) {
                  deprecationWarning(
                      'Using QueryTrait::formatResults() as a getter is deprecated. ' .
                      'Use getResultFormatters() instead.'
                  );
              }
  
              return $this->_formatters;
          }
  
          if ($mode === self::PREPEND) {
              array_unshift($this->_formatters, $formatter);
  
              return $this;
          }
  
          $this->_formatters[] = $formatter;
  
          return $this;
      }
code_tokens: public function formatResults ( callable $ formatter = null , $ mode = 0 ) { if ( $ mode === self :: OVERWRITE ) { $ this -> _formatters = [ ] ; } if ( $ formatter === null ) { if ( $ mode !== self :: OVERWRITE ) { deprecationWarning ( 'Using QueryTrait::formatResults() as a getter is deprecated. ' . 'Use getResultFormatters() instead.' ) ; } return $ this -> _formatters ; } if ( $ mode === self :: PREPEND ) { array_unshift ( $ this -> _formatters , $ formatter ) ; return $ this ; } $ this -> _formatters [ ] = $ formatter ; return $ this ; }
docstring: Registers a new formatter callback function that is to be executed when trying
  to fetch the results from the database.
  
  Formatting callbacks will get a first parameter, an object implementing
  `\Cake\Collection\CollectionInterface`, that can be traversed and modified at will.
  
  Callbacks are required to return an iterator object, which will be used as
  the return value for this query's result. Formatter functions are applied
  after all the `MapReduce` routines for this query have been executed.
  
  If the first argument is set to null, it will return the list of previously
  registered format routines. This is deprecated as of 3.6.0 - use getResultFormatters() instead.
  
  If the second argument is set to true, it will erase previous formatters
  and replace them with the passed first argument.
  
  ### Example:
  
  ```
  // Return all results from the table indexed by id
  $query->select(['id', 'name'])->formatResults(function ($results) {
  return $results->indexBy('id');
  });
  
  // Add a new column to the ResultSet
  $query->select(['name', 'birth_date'])->formatResults(function ($results) {
  return $results->map(function ($row) {
  $row['age'] = $row['birth_date']->diff(new DateTime)->y;
  return $row;
  });
  });
  ```
  
  @param callable|null $formatter The formatting callable.
  @param bool|int $mode Whether or not to overwrite, append or prepend the formatter.
  @return $this|array
docstring_tokens: Registers a new formatter callback function that is to be executed when trying to fetch the results from the database .