fields() public method

Merges defaults with defined field values to ensure all options exist for each field.
public fields ( ) : array
return array Defined fields plus all defaults for full array of all possible options
 /**
  * @param Generator $generator
  * @return array
  */
 public function guessColumnFormatters(Generator $generator)
 {
     $formatters = array();
     $nameGuesser = new Name($generator);
     $columnTypeGuesser = new ColumnTypeGuesser($generator);
     $fields = $this->mapper->fields();
     foreach ($fields as $fieldName => $field) {
         if ($field['primary'] === true) {
             continue;
         }
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($field)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     $entityName = $this->mapper->entity();
     $entity = $this->mapper->build([]);
     $relations = $entityName::relations($this->mapper, $entity);
     foreach ($relations as $relation) {
         // We don't need any other relation here.
         if ($relation instanceof BelongsTo) {
             $fieldName = $relation->localKey();
             $entityName = $relation->entityName();
             $field = $fields[$fieldName];
             $required = $field['required'];
             $locator = $this->locator;
             $formatters[$fieldName] = function ($inserted) use($required, $entityName, $locator) {
                 if (!empty($inserted[$entityName])) {
                     return $inserted[$entityName][mt_rand(0, count($inserted[$entityName]) - 1)]->getId();
                 } else {
                     if ($required && $this->useExistingData) {
                         // We did not add anything like this, but it's required,
                         // So let's find something existing in DB.
                         $mapper = $this->locator->mapper($entityName);
                         $records = $mapper->all()->limit(self::RELATED_FETCH_COUNT)->toArray();
                         if (empty($records)) {
                             return null;
                         }
                         $id = $records[mt_rand(0, count($records) - 1)]['id'];
                         return $id;
                     } else {
                         return null;
                     }
                 }
             };
         }
     }
     return $formatters;
 }