original_string: public static function field($descriptor, $name = null)
      {
          if (is_a($descriptor, 'frictionlessdata\\tableschema\\Fields\\BaseField')) {
              return $descriptor;
          } else {
              if (Utils::isJsonString($descriptor)) {
                  $descriptor = json_decode($descriptor);
              } elseif (is_array($descriptor)) {
                  $descriptor = json_decode(json_encode($descriptor));
              }
              if (!isset($descriptor->name) && !is_null($name)) {
                  $descriptor->name = $name;
              }
              foreach (static::$fieldClasses as $fieldClass) {
                  /** @var BaseField $fieldClass */
                  if ($field = $fieldClass::inferDescriptor($descriptor)) {
                      return $field;
                  }
              }
              throw new FieldValidationException([
                  new SchemaValidationError(
                      SchemaValidationError::SCHEMA_VIOLATION,
                      'Could not find a valid field for descriptor: '.json_encode($descriptor)),
              ]);
          }
      }
code: public static function field($descriptor, $name = null)
      {
          if (is_a($descriptor, 'frictionlessdata\\tableschema\\Fields\\BaseField')) {
              return $descriptor;
          } else {
              if (Utils::isJsonString($descriptor)) {
                  $descriptor = json_decode($descriptor);
              } elseif (is_array($descriptor)) {
                  $descriptor = json_decode(json_encode($descriptor));
              }
              if (!isset($descriptor->name) && !is_null($name)) {
                  $descriptor->name = $name;
              }
              foreach (static::$fieldClasses as $fieldClass) {
                  /** @var BaseField $fieldClass */
                  if ($field = $fieldClass::inferDescriptor($descriptor)) {
                      return $field;
                  }
              }
              throw new FieldValidationException([
                  new SchemaValidationError(
                      SchemaValidationError::SCHEMA_VIOLATION,
                      'Could not find a valid field for descriptor: '.json_encode($descriptor)),
              ]);
          }
      }
code_tokens: public static function field ( $ descriptor , $ name = null ) { if ( is_a ( $ descriptor , 'frictionlessdata\\tableschema\\Fields\\BaseField' ) ) { return $ descriptor ; } else { if ( Utils :: isJsonString ( $ descriptor ) ) { $ descriptor = json_decode ( $ descriptor ) ; } elseif ( is_array ( $ descriptor ) ) { $ descriptor = json_decode ( json_encode ( $ descriptor ) ) ; } if ( ! isset ( $ descriptor -> name ) && ! is_null ( $ name ) ) { $ descriptor -> name = $ name ; } foreach ( static :: $ fieldClasses as $ fieldClass ) { /** @var BaseField $fieldClass */ if ( $ field = $ fieldClass :: inferDescriptor ( $ descriptor ) ) { return $ field ; } } throw new FieldValidationException ( [ new SchemaValidationError ( SchemaValidationError :: SCHEMA_VIOLATION , 'Could not find a valid field for descriptor: ' . json_encode ( $ descriptor ) ) , ] ) ; } }
docstring: get a new field object in the correct type according to the descriptor.
  
  @param object|array $descriptor
  
  @return BaseField
  
  @throws \Exception
docstring_tokens: get a new field object in the correct type according to the descriptor .