- case AvroSchema::NULL_TYPE:
- if ( !is_null( $datum ) ) {
- return self::wrongType( 'null', $datum );
- }
- return array();
- case AvroSchema::BOOLEAN_TYPE:
- if ( !is_bool( $datum ) ) {
- return self::wrongType( 'boolean', $datum );
- }
- return array();
- case AvroSchema::STRING_TYPE:
- case AvroSchema::BYTES_TYPE:
- if ( !is_string( $datum ) ) {
- return self::wrongType( 'string', $datum );
- }
- return array();
- case AvroSchema::INT_TYPE:
- if ( !is_int( $datum ) ) {
- return self::wrongType( 'integer', $datum );
- }
- if ( AvroSchema::INT_MIN_VALUE > $datum
- || $datum > AvroSchema::INT_MAX_VALUE
- ) {
- return self::outOfRange(
- AvroSchema::INT_MIN_VALUE,
- AvroSchema::INT_MAX_VALUE,
- $datum
- );
- }
- return array();
- case AvroSchema::LONG_TYPE:
- if ( !is_int( $datum ) ) {
- return self::wrongType( 'integer', $datum );
- }
- if ( AvroSchema::LONG_MIN_VALUE > $datum
- || $datum > AvroSchema::LONG_MAX_VALUE
- ) {
- return self::outOfRange(
- AvroSchema::LONG_MIN_VALUE,
- AvroSchema::LONG_MAX_VALUE,
- $datum
- );
- }
- return array();
- case AvroSchema::FLOAT_TYPE:
- case AvroSchema::DOUBLE_TYPE:
- if ( !is_float( $datum ) && !is_int( $datum ) ) {
- return self::wrongType( 'float or integer', $datum );
- }
- return array();
- case AvroSchema::ARRAY_SCHEMA:
- if ( !is_array( $datum ) ) {
- return self::wrongType( 'array', $datum );
- }
- $errors = array();
- foreach ( $datum as $d ) {
- $result = self::getErrors( $schema->items(), $d );
- if ( $result ) {
+ case AvroSchema::NULL_TYPE:
+ if ( !is_null( $datum ) ) {
+ return self::wrongType( 'null', $datum );
+ }
+ return [];
+ case AvroSchema::BOOLEAN_TYPE:
+ if ( !is_bool( $datum ) ) {
+ return self::wrongType( 'boolean', $datum );
+ }
+ return [];
+ case AvroSchema::STRING_TYPE:
+ case AvroSchema::BYTES_TYPE:
+ if ( !is_string( $datum ) ) {
+ return self::wrongType( 'string', $datum );
+ }
+ return [];
+ case AvroSchema::INT_TYPE:
+ if ( !is_int( $datum ) ) {
+ return self::wrongType( 'integer', $datum );
+ }
+ if ( AvroSchema::INT_MIN_VALUE > $datum
+ || $datum > AvroSchema::INT_MAX_VALUE
+ ) {
+ return self::outOfRange(
+ AvroSchema::INT_MIN_VALUE,
+ AvroSchema::INT_MAX_VALUE,
+ $datum
+ );
+ }
+ return [];
+ case AvroSchema::LONG_TYPE:
+ if ( !is_int( $datum ) ) {
+ return self::wrongType( 'integer', $datum );
+ }
+ if ( AvroSchema::LONG_MIN_VALUE > $datum
+ || $datum > AvroSchema::LONG_MAX_VALUE
+ ) {
+ return self::outOfRange(
+ AvroSchema::LONG_MIN_VALUE,
+ AvroSchema::LONG_MAX_VALUE,
+ $datum
+ );
+ }
+ return [];
+ case AvroSchema::FLOAT_TYPE:
+ case AvroSchema::DOUBLE_TYPE:
+ if ( !is_float( $datum ) && !is_int( $datum ) ) {
+ return self::wrongType( 'float or integer', $datum );
+ }
+ return [];
+ case AvroSchema::ARRAY_SCHEMA:
+ if ( !is_array( $datum ) ) {
+ return self::wrongType( 'array', $datum );
+ }
+ $errors = [];
+ foreach ( $datum as $d ) {
+ $result = self::getErrors( $schema->items(), $d );
+ if ( $result ) {
+ $errors[] = $result;
+ }
+ }
+ return $errors;
+ case AvroSchema::MAP_SCHEMA:
+ if ( !is_array( $datum ) ) {
+ return self::wrongType( 'array', $datum );
+ }
+ $errors = [];
+ foreach ( $datum as $k => $v ) {
+ if ( !is_string( $k ) ) {
+ $errors[] = self::wrongType( 'string key', $k );
+ }
+ $result = self::getErrors( $schema->values(), $v );
+ if ( $result ) {
+ $errors[$k] = $result;
+ }
+ }
+ return $errors;
+ case AvroSchema::UNION_SCHEMA:
+ $errors = [];
+ foreach ( $schema->schemas() as $schema ) {
+ $result = self::getErrors( $schema, $datum );
+ if ( !$result ) {
+ return [];
+ }