Skip to content

Conversation

@spawnia
Copy link
Member

@spawnia spawnia commented Oct 10, 2025

  • Added automated tests
  • Documented for all relevant versions
  • Updated the changelog

Changes

Breaking changes

@spawnia spawnia requested a review from Copilot October 10, 2025 13:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new SafeCast utility class that provides safe type casting alternatives to PHP's native type casting operators. The utility validates input before casting and throws exceptions for invalid inputs instead of silently producing incorrect values.

  • Adds SafeCast class with methods for safe casting to int, float, string, and bool types
  • Includes comprehensive test coverage for all casting methods and edge cases
  • Updates documentation with usage examples and explanations

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/SafeCast.php Main implementation of the SafeCast utility class with validation logic
tests/SafeCastTest.php Comprehensive test suite covering all methods and edge cases
README.md Documentation update with usage examples for the new SafeCast utility
src/FluidXPlate/FluidXScanner.php Minor refactoring to use in_array() for better readability

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return (int) $value;
}

throw new \InvalidArgumentException('Float value "' . $value . '" cannot be safely cast to int (not a whole number or not finite)');
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message concatenates a float value directly into the string, which may produce inconsistent formatting (e.g., scientific notation). Consider using a more controlled string representation.

Suggested change
throw new \InvalidArgumentException('Float value "' . $value . '" cannot be safely cast to int (not a whole number or not finite)');
throw new \InvalidArgumentException('Float value "' . sprintf('%.10g', $value) . '" cannot be safely cast to int (not a whole number or not finite)');

Copilot uses AI. Check for mistakes.
* this method is strict and only accepts:
* - Booleans (returned as-is)
* - Integers 0 and 1
* - Strings "0", "1", "true", "false", "yes", "no" (case-insensitive)
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is incomplete - it mentions 'yes', 'no' but doesn't include 'on', 'off' which are actually supported in the implementation (lines 180, 184).

Suggested change
* - Strings "0", "1", "true", "false", "yes", "no" (case-insensitive)
* - Strings "0", "1", "true", "false", "yes", "no", "on", "off" (case-insensitive)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant