Copilot commented on code in PR #3528:
URL: https://github.com/apache/avro/pull/3528#discussion_r2466372470
##########
lang/php/lib/Schema/AvroRecordSchema.php:
##########
@@ -109,22 +100,20 @@ public static function parseFields($field_data,
$default_namespace, &$schemata)
)
) {
$is_schema_from_schemata = true;
+ } else if (is_string($type) && self::isPrimitiveType($type)) {
Review Comment:
[nitpick] Use `elseif` instead of `else if` for consistency with PHP coding
standards. While functionally equivalent, `elseif` is the preferred form in
modern PHP code.
```suggestion
} elseif (is_string($type) && self::isPrimitiveType($type)) {
```
##########
lang/php/test/SchemaTest.php:
##########
@@ -22,29 +23,23 @@
use Apache\Avro\AvroException;
use Apache\Avro\Schema\AvroSchema;
use Apache\Avro\Schema\AvroSchemaParseException;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class SchemaExample
{
- public $schema_string;
- public $is_valid;
public $name;
- public $comment;
public $normalized_schema_string;
public function __construct(
- $schema_string,
- $is_valid,
+ public $schema_string,
+ public $is_valid,
$normalized_schema_string = null,
$name = null,
- $comment = null
+ public $comment = null
) {
- $this->schema_string = $schema_string;
- $this->is_valid = $is_valid;
- $this->name = $name ? $name : $schema_string;
- $this->normalized_schema_string = $normalized_schema_string
- ? $normalized_schema_string :
json_encode(json_decode($schema_string, true));
- $this->comment = $comment;
+ $this->name = $name ?: $this->schema_string;
+ $this->normalized_schema_string = $normalized_schema_string ?:
json_encode(json_decode((string) $this->schema_string, true));
Review Comment:
The cast to `(string)` is unnecessary here since `$this->schema_string` is
already a string. Additionally, `json_decode` with `true` as the second
parameter requires the `JSON_THROW_ON_ERROR` flag to handle errors properly
when used with `json_encode`, otherwise errors may be silently ignored.
```suggestion
$this->normalized_schema_string = $normalized_schema_string ?:
json_encode(json_decode($this->schema_string, true, 512, JSON_THROW_ON_ERROR));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]