Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new JSON utility class to centralize JSON handling across the FlightPHP framework and addresses PHP Code Sniffer warnings by adding ignore comments for heredoc/nowdoc syntax issues.
- Adds a comprehensive Json utility class with encoding, decoding, validation, and error handling methods
- Updates the Engine class to use the new Json utility instead of direct json_encode calls
- Adds phpcs:ignore comments to suppress code style warnings for heredoc/nowdoc syntax
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| flight/util/Json.php | New utility class providing centralized JSON operations with consistent error handling |
| flight/Engine.php | Updated to use Json utility class and added phpcs:ignore comment |
| tests/JsonTest.php | Comprehensive test suite for the new Json utility class |
| tests/EngineTest.php | Updated tests to handle new Json utility behavior |
| flight/commands/AiGenerateInstructionsCommand.php | Added phpcs:ignore comment for heredoc syntax |
| tests/server/index.php | Added phpcs:ignore comment for heredoc syntax |
| tests/commands/RouteCommandTest.php | Added phpcs:ignore comments for heredoc syntax |
| tests/ViewTest.php | Added phpcs:ignore comments for heredoc syntax |
| tests/FlightTest.php | Added phpcs:ignore comment for heredoc syntax |
Comments suppressed due to low confidence (1)
tests/EngineTest.php:401
- The exception type has been changed from JsonException to Exception, but this makes the test less specific. The Json utility class wraps JsonException in Exception, so this change may be hiding the actual exception behavior that should be tested.
$this->expectException(Exception::class);
| public static function prettyPrint($data, int $additionalOptions = 0): string | ||
| { | ||
| $options = self::DEFAULT_ENCODE_OPTIONS | JSON_PRETTY_PRINT | $additionalOptions; | ||
| return self::encode($data, $options); |
There was a problem hiding this comment.
The prettyPrint method combines options using bitwise OR and then passes them to encode(), which will apply bitwise OR again with DEFAULT_ENCODE_OPTIONS. This could lead to unexpected behavior or option conflicts. Consider calling json_encode directly with the final options.
Suggested change
| return self::encode($data, $options); | |
| try { | |
| return json_encode($data, $options, 512); | |
| } catch (JsonException $e) { | |
| throw new Exception('JSON pretty print encoding failed: ' . $e->getMessage(), $e->getCode(), $e); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.