original_string: protected function _convertFieldsToType(array $fields, $direction)
      {
          if (!in_array($direction, ['toPHP', 'toDatabase'])) {
              throw new InvalidArgumentException(sprintf('Cannot convert type, Cake\Database\Type::%s does not exist', $direction));
          }
  
          $driver = $this->_table->getConnection()->getDriver();
          foreach ($fields as $field => $content) {
              $column = $this->_table->getSchema()->getColumn($field);
              $type = Type::build($column['type']);
  
              $fields[$field] = $type->{$direction}($content, $driver);
          }
  
          return $fields;
      }
code: protected function _convertFieldsToType(array $fields, $direction)
      {
          if (!in_array($direction, ['toPHP', 'toDatabase'])) {
              throw new InvalidArgumentException(sprintf('Cannot convert type, Cake\Database\Type::%s does not exist', $direction));
          }
  
          $driver = $this->_table->getConnection()->getDriver();
          foreach ($fields as $field => $content) {
              $column = $this->_table->getSchema()->getColumn($field);
              $type = Type::build($column['type']);
  
              $fields[$field] = $type->{$direction}($content, $driver);
          }
  
          return $fields;
      }
code_tokens: protected function _convertFieldsToType ( array $ fields , $ direction ) { if ( ! in_array ( $ direction , [ 'toPHP' , 'toDatabase' ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Cannot convert type, Cake\Database\Type::%s does not exist' , $ direction ) ) ; } $ driver = $ this -> _table -> getConnection ( ) -> getDriver ( ) ; foreach ( $ fields as $ field => $ content ) { $ column = $ this -> _table -> getSchema ( ) -> getColumn ( $ field ) ; $ type = Type :: build ( $ column [ 'type' ] ) ; $ fields [ $ field ] = $ type -> { $ direction } ( $ content , $ driver ) ; } return $ fields ; }
docstring: Converts fields to the appropriate type to be stored in the version, and
  to be converted from the version record to the entity
  
  @param array $fields Fields to convert
  @param string $direction Direction (toPHP or toDatabase)
  @return array
docstring_tokens: Converts fields to the appropriate type to be stored in the version and to be converted from the version record to the entity