X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Futils%2FAvroValidator.php;h=554dda9d6d2bd29c852a6b61621e2216ef3dd3cb;hb=7a836958be6a698a61eef4d166d9fecd7a909e8d;hp=4f8e0b177bb3b4100490079089bf7f464ffbbaf7;hpb=f1a890c34cebd8744bf3a6277734275fb975575a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/utils/AvroValidator.php b/includes/utils/AvroValidator.php index 4f8e0b177b..554dda9d6d 100644 --- a/includes/utils/AvroValidator.php +++ b/includes/utils/AvroValidator.php @@ -36,25 +36,25 @@ class AvroValidator { * returned. */ public static function getErrors( AvroSchema $schema, $datum ) { - switch ( $schema->type) { + switch ( $schema->type ) { case AvroSchema::NULL_TYPE: - if ( !is_null($datum) ) { + if ( !is_null( $datum ) ) { return self::wrongType( 'null', $datum ); } - return array(); + return []; case AvroSchema::BOOLEAN_TYPE: - if ( !is_bool($datum) ) { + if ( !is_bool( $datum ) ) { return self::wrongType( 'boolean', $datum ); } - return array(); + return []; case AvroSchema::STRING_TYPE: case AvroSchema::BYTES_TYPE: - if ( !is_string($datum) ) { + if ( !is_string( $datum ) ) { return self::wrongType( 'string', $datum ); } - return array(); + return []; case AvroSchema::INT_TYPE: - if ( !is_int($datum) ) { + if ( !is_int( $datum ) ) { return self::wrongType( 'integer', $datum ); } if ( AvroSchema::INT_MIN_VALUE > $datum @@ -66,9 +66,9 @@ class AvroValidator { $datum ); } - return array(); + return []; case AvroSchema::LONG_TYPE: - if ( !is_int($datum) ) { + if ( !is_int( $datum ) ) { return self::wrongType( 'integer', $datum ); } if ( AvroSchema::LONG_MIN_VALUE > $datum @@ -80,35 +80,32 @@ class AvroValidator { $datum ); } - return array(); + return []; case AvroSchema::FLOAT_TYPE: case AvroSchema::DOUBLE_TYPE: - if ( !is_float($datum) && !is_int($datum) ) { + if ( !is_float( $datum ) && !is_int( $datum ) ) { return self::wrongType( 'float or integer', $datum ); } - return array(); + return []; case AvroSchema::ARRAY_SCHEMA: - if (!is_array($datum)) { + if ( !is_array( $datum ) ) { return self::wrongType( 'array', $datum ); } - $errors = array(); - foreach ($datum as $d) { - $result = $this->validate( $schema->items(), $d ); + $errors = []; + foreach ( $datum as $d ) { + $result = self::getErrors( $schema->items(), $d ); if ( $result ) { $errors[] = $result; } } - if ( $errors ) { - return $errors; - } - return array(); + return $errors; case AvroSchema::MAP_SCHEMA: - if (!is_array($datum)) { + if ( !is_array( $datum ) ) { return self::wrongType( 'array', $datum ); } - $errors = array(); - foreach ($datum as $k => $v) { - if ( !is_string($k) ) { + $errors = []; + foreach ( $datum as $k => $v ) { + if ( !is_string( $k ) ) { $errors[] = self::wrongType( 'string key', $k ); } $result = self::getErrors( $schema->values(), $v ); @@ -118,16 +115,16 @@ class AvroValidator { } return $errors; case AvroSchema::UNION_SCHEMA: - $errors = array(); - foreach ($schema->schemas() as $schema) { + $errors = []; + foreach ( $schema->schemas() as $schema ) { $result = self::getErrors( $schema, $datum ); if ( !$result ) { - return array(); + return []; } $errors[] = $result; } if ( $errors ) { - return array( "Expected any one of these to be true", $errors ); + return [ "Expected any one of these to be true", $errors ]; } return "No schemas provided to union"; case AvroSchema::ENUM_SCHEMA: @@ -135,7 +132,7 @@ class AvroValidator { $symbols = implode( ', ', $schema->symbols ); return "Expected one of $symbols but recieved $datum"; } - return array(); + return []; case AvroSchema::FIXED_SCHEMA: if ( !is_string( $datum ) ) { return self::wrongType( 'string', $datum ); @@ -145,14 +142,14 @@ class AvroValidator { return "Expected string of length {$schema->size()}, " . "but recieved one of length $len"; } - return array(); + return []; case AvroSchema::RECORD_SCHEMA: case AvroSchema::ERROR_SCHEMA: case AvroSchema::REQUEST_SCHEMA: if ( !is_array( $datum ) ) { return self::wrongType( 'array', $datum ); } - $errors = array(); + $errors = []; foreach ( $schema->fields() as $field ) { $name = $field->name(); if ( !array_key_exists( $name, $datum ) ) {