-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat!: preserve the type of booleans, floats, scientific notations and integers when transforming back and forth between PostgreSQL and PHP #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…k and forth between PostgreSQL and PHP
WalkthroughThis pull request refactors code related to array transformations. In the Doctrine DBAL types, a redundant string conversion is removed by storing the string representation in a variable, while in the DataStructure class, conversion methods for PostgreSQL arrays are refactored with added helper methods, improved error handling, and modular logic. A new Changes
Sequence Diagram(s)Possibly related PRs
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/MartinGeorgiev/Utils/DataStructure.php (1)
109-124: Numeric detection logicThe approach of stripping
'e'for scientific notation works for simpler exponent forms like1.23e4. However, consider extending coverage to handle plus signs (e.g.,1.23e+4) if needed.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArray.php(1 hunks)src/MartinGeorgiev/Utils/DataStructure.php(1 hunks)tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php(2 hunks)tests/MartinGeorgiev/Utils/DataStructureTest.php(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArray.php (3)
src/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArray.php (2)
getMinValue(22-25)getMaxValue(27-30)src/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArray.php (2)
getMinValue(22-25)getMaxValue(27-30)src/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArray.php (2)
getMinValue(22-25)getMaxValue(27-30)
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
src/MartinGeorgiev/Utils/DataStructure.php
[failure] 88-88:
Cannot cast mixed to string.
[failure] 49-49:
Parameter #2 $array of function array_map expects array, mixed given.
🔇 Additional comments (21)
tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php (2)
77-78: Increased coverage with mixed numeric dataAdding both a float (
3.4) and a string float ('5.6') helps ensure transformations handle different numeric representations. Great addition to test coverage!
89-89: Consistency with new numeric itemsThe updated PostgreSQL value string correctly reflects the addition of
3.4and"5.6". This maintains consistency between the test input and expected output.src/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArray.php (1)
50-53: Improved readability by extracting string valueDefining
$stringValueand conducting the numeric checks against it promotes clarity. This helps avoid repeated casts and ensures the code is more maintainable.tests/MartinGeorgiev/Utils/DataStructureTest.php (12)
47-55: Preserving string integersEnforcing the distinction between string integers and numeric integers ensures correct data typing. This test scenario nicely highlights that behavior.
56-62: Checking numeric integersThis case validates integer conversions without quotes. Good coverage for purely numeric inputs.
65-65: Testing decimal numbers as stringsPreserving decimals as strings tests the difference from true floats. This clarifies behavior for textual float representations.
Also applies to: 72-73
74-80: Validation of decimal float handlingIncluding these decimal floats validates that they are recognized as numeric and not quoted.
83-83: Documenting special charactersRenaming or clarifying this data set helps in reading the test scenario. It's important to validate transformation with special characters.
93-93: Covering empty string edge casesThis test ensures that empty strings do not get misinterpreted as null values.
100-100: Validating empty array handlingConfirming the mapping of an empty PHP array to
{}in Postgres is crucial for single-dimension arrays.
104-107: Handling simple scientific notation in stringsTesting scientific notation ensures the transformation logic can handle exponent forms. This is a valuable addition to numeric coverage.
108-111: Extending coverage to negative exponentsNegative exponents can be trickier to parse, so it's great to see them tested here.
112-115: Distinguishing whole floats from integersDemonstrating how floats with trailing zeros are stored helps confirm the precise behavior for numeric transformations.
116-123: Testing extremely large integersThis scenario highlights how values outside PHP’s integer range are preserved as strings, preventing overflow or unexpected behavior.
124-135: Comprehensive test for numeric format variationsCombining floats, strings, scientific notation, and large integers in one array solidifies confidence in the transformation logic across multiple numeric representations.
src/MartinGeorgiev/Utils/DataStructure.php (6)
16-16: Introduction of descriptive constantsUsing class constants for
'{}'and'null'clarifies intent and eliminates magic strings across the code.Also applies to: 18-18
26-29: Refined logic for single-dimension PostgreSQL arrays
- Checking for empty or
'null'inputs ensures an empty array is returned appropriately.- Early detection of multi-dimensional arrays via
str_containsworks for simple bracket scanning.- Converting to JSON and then decoding is a concise approach, though it depends on valid quoting in the input.
- Mapping strings with
unescapeString()finalizes the array items neatly.Overall, a neat and maintainable solution!
Also applies to: 32-34, 36-38, 40-40, 42-45, 47-50
59-61: Simplifying the PHP array to Postgres text array transformation
- Returning
'{}'for empty arrays aligns with PostgreSQL conventions.- Rejecting nested arrays at an early stage enforces single-dimension usage.
- Mapping values with
formatValue()centralizes the escaping logic, promoting consistency.Also applies to: 63-65, 67-70
72-74: Clear docblockWell-documented intent for the newly introduced
formatValuemethod. This ensures developers understand its usage constraints.
75-107: Centralized value formatting for PostgreSQL arraysThis method handles null, numeric, or string inputs with distinct logic, ensuring consistent quoting and escaping. It's a solid improvement for maintainability and clarity.
🧰 Tools
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 88-88:
Cannot cast mixed to string.
126-129: String unescaping with placeholdersReplacing quotes and backslashes with placeholders, then restoring them, effectively avoids collisions with partial replacements. Clever technique for cleaning up escaped strings.
Also applies to: 131-142
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/MartinGeorgiev/Utils/DataStructure.php(1 hunks)tests/MartinGeorgiev/Utils/DataStructureTest.php(2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
tests/MartinGeorgiev/Utils/DataStructureTest.php (9)
tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php (1)
provideValidTransformations(62-93)tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php (1)
provideValidTransformations(60-91)tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbTest.php (1)
provideValidTransformations(62-104)tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseArrayTest.php (1)
provideValidTransformations(65-81)tests/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php (1)
provideValidTransformations(37-49)tests/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php (1)
provideValidTransformations(40-52)tests/MartinGeorgiev/Doctrine/DBAL/Types/BooleanArrayTest.php (1)
provideValidTransformations(71-90)tests/MartinGeorgiev/Doctrine/DBAL/Types/SmallIntArrayTest.php (1)
provideValidTransformations(37-49)tests/MartinGeorgiev/Doctrine/DBAL/Types/BaseIntegerArrayTestCase.php (1)
provideValidTransformations(66-66)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
- GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
- GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest
- GitHub Check: sloth
🔇 Additional comments (16)
tests/MartinGeorgiev/Utils/DataStructureTest.php (11)
37-37: Improved type annotation clarityThe return type annotation has been updated to be more specific, using a strongly-typed array shape instead of a generic array. This provides better type safety and makes the expected return structure clearer.
42-50: LGTM: Clear test case naming with appropriate assertionsThe test case has been renamed from a simple indexed array to a descriptive name "simple integer strings as strings are preserved as strings", making the test's purpose immediately clear. The expected PostgreSQL value properly includes quotes to preserve the string type.
51-59: LGTM: Integer type preservation testThis test case properly verifies that numeric integers in PHP are correctly transformed to unquoted values in PostgreSQL arrays.
60-68: LGTM: String decimal preservation testGood test case that ensures decimal strings maintain their string type during transformation, with proper quoting in the PostgreSQL representation.
69-77: LGTM: Numeric float preservation testThis test case properly verifies that PHP float values are correctly transformed to unquoted decimal values in PostgreSQL arrays.
78-87: LGTM: Comprehensive mixed content testThe test case effectively validates handling of diverse content including special characters, escaping, and numeric values.
88-94: LGTM: Edge cases correctly handledThese test cases correctly verify the handling of empty strings and empty arrays, which are important edge cases.
Also applies to: 95-98
99-102: Good addition of scientific notation test casesThe addition of test cases for scientific notation with both positive and negative exponents is valuable. These cases ensure that scientific notation is preserved as strings during transformation, which is critical for numeric precision.
Also applies to: 103-106
107-110: LGTM: Whole floats preservation testThis test case correctly verifies that floating-point numbers with only zeros after the decimal point maintain their string representation, preserving the decimal nature of the values.
111-118: Important test case for large integersExcellent addition of a test case for integers that exceed PHP_INT_MAX. This ensures that extremely large integers are correctly preserved as strings, preventing potential data loss during transformation.
119-130: Comprehensive mixed numeric formats testThis is a valuable test case that covers a wide range of numeric representations in a single array, including regular floats, float strings, scientific notation, whole floats, and large integers. It ensures that the type preservation works correctly across all these formats.
src/MartinGeorgiev/Utils/DataStructure.php (5)
16-19: Good use of constants for PostgreSQL valuesUsing constants for PostgreSQL empty arrays and null values improves code readability and maintainability by centralizing these special values in one place.
26-52: Improved PostgreSQL to PHP array transformation implementationThe rewritten method provides several improvements:
- Better handling of edge cases (empty strings, null values)
- Clear validation for unsupported multi-dimensional arrays
- Using JSON decoding with
JSON_BIGINT_AS_STRINGensures large integers are preserved- Improved error handling with detailed error messages
- Modular approach with helper methods
This implementation properly preserves numeric types while ensuring compatibility with PostgreSQL arrays.
60-75: Cleaner PHP to PostgreSQL array transformationThe implementation has been simplified and improved by:
- Using constants for better readability
- Proper validation of input
- Using
array_mapwith a dedicated formatting method for better code organization- Clear separation of concerns between transformation and value formatting
This refactoring makes the code more maintainable while ensuring type preservation.
77-133: Well-structured formatValue helper methodThis new helper method is comprehensive and handles:
- Null values
- Numeric types (preserving type information)
- Booleans
- Objects with __toString implementation
- Other types with appropriate fallbacks
- Special handling for empty strings
- Type-checking with assertions
- Proper escaping of values
The implementationis thorough and accounts for various edge cases, making the type preservation robust.
135-150: Effective numeric type detection helperThe
isNumericSimplemethod provides efficient handling of:
- Fast path for obvious non-numeric strings
- Scientific notation detection
- Proper numeric validation
This helper ensures accurate identification of numeric strings, which is crucial for maintaining type consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/MartinGeorgiev/Utils/ArrayDataTransformer.php (2)
38-44: Consider more robust array parsing approachThe current implementation uses JSON functions by wrapping the PostgreSQL array content in square brackets. While the test cases cover various scenarios, this approach could be fragile for certain edge cases.
Consider implementing a more robust parsing method specific to PostgreSQL array format, or adding more detailed error messages to help diagnose parsing issues.
150-163: Clever string unescaping, but consider edge casesThe unescaping method uses temporary placeholders (
___QUOTE___and___DBLBACK___) which works well but could cause issues if these exact strings appear in the original data.While unlikely, consider using even more unique placeholders or a different approach to avoid potential conflicts with input data.
tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php (1)
1-250: Consider adding tests for additional edge casesWhile the test coverage is excellent, consider adding tests for:
- Arrays containing null values (different from null arrays)
- Objects without __toString() method
- Edge cases with floating point precision
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/MartinGeorgiev/Doctrine/DBAL/Types/TextArray.php(3 hunks)src/MartinGeorgiev/Utils/ArrayDataTransformer.php(1 hunks)tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php(1 hunks)tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php
🧰 Additional context used
🧬 Code Definitions (2)
src/MartinGeorgiev/Utils/ArrayDataTransformer.php (1)
tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php (1)
__toString(137-140)
tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php (2)
src/MartinGeorgiev/Utils/ArrayDataTransformer.php (3)
ArrayDataTransformer(12-164)transformPHPArrayToPostgresTextArray(56-73)transformPostgresTextArrayToPHPArray(22-50)tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php (3)
can_transform_from_php_value(41-44)can_transform_to_php_value(51-54)provideValidTransformations(62-93)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest
- GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
- GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1
- GitHub Check: sloth
🔇 Additional comments (13)
src/MartinGeorgiev/Doctrine/DBAL/Types/TextArray.php (3)
7-8: Import update looks good!Appropriate replacement of the
DataStructureimport with the new specializedArrayDataTransformerclass.
45-45: Method replacement looks good!Properly refactored to use the new
ArrayDataTransformer::transformPHPArrayToPostgresTextArraymethod.
68-68: Method replacement looks good!Properly refactored to use the new
ArrayDataTransformer::transformPostgresTextArrayToPHPArraymethod.src/MartinGeorgiev/Utils/ArrayDataTransformer.php (6)
12-17: Well-structured class with clear constants!Good choice of clear constant names for PostgreSQL empty array and null values.
22-50: Good implementation with proper error handling!The
transformPostgresTextArrayToPHPArraymethod has good handling of edge cases and error conditions:
- Empty/null strings return empty arrays
- Multi-dimensional arrays are rejected with a clear exception
- JSON parsing errors are caught with informative messages
- String values are properly unescaped
56-73: Good implementation of array transformation!The
transformPHPArrayToPostgresTextArraymethod properly:
- Handles empty arrays
- Rejects multi-dimensional arrays
- Maps values through a detailed formatting function
- Creates the correct PostgreSQL array format
78-131: Excellent value formatting with comprehensive type handling!The
formatValuemethod handles all data types thoroughly:
- Nulls are converted to PostgreSQL NULL
- Numbers (int/float) are handled natively
- Booleans are formatted correctly
- Objects with
__toString()are handled properly- Resources are handled gracefully
- String escaping is comprehensive
95-110: Good object handling with fallback for non-string-convertible objectsThe handling of objects is well-done, with special handling for objects implementing
__toString()and a fallback for other objects.
133-148: Clever numeric detection with performance optimization!The
isNumericSimplemethod has a fast path for obvious cases and special handling for scientific notation.tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php (4)
10-35: Well-structured test class with thorough testing approach!The test class properly tests transformation in both directions (PHP to PostgreSQL and vice versa), using a comprehensive data provider.
39-153: Excellent test data provider with comprehensive test cases!The
provideValidTransformationsmethod covers a wide range of scenarios:
- Different numeric formats (integers, floats, scientific notation)
- Preservation of string vs. numeric types
- Special characters and escaping
- Empty strings and arrays
- Large integers beyond PHP_INT_MAX
- Unicode characters
- Objects with __toString
221-234: Good test for numeric string type preservation!This test ensures that different numeric representations maintain their original type after a round-trip transformation, which is a key goal of this PR.
239-248: Good resource handling with proper cleanup!The test properly creates, uses, and closes a resource, ensuring no resource leaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/MartinGeorgiev/Utils/ArrayDataTransformer.php (2)
139-154: Consider preserving the original value inisNumericSimple.The function modifies the
$valueparameter when handling scientific notation, which could lead to unexpected behavior if the function is extended in the future.private static function isNumericSimple(string $value): bool { // Fast path for obvious numeric strings if ($value === '' || $value[0] === '"') { return false; } // Handle scientific notation $lower = \strtolower($value); if (\str_contains($lower, 'e')) { - $value = \str_replace('e', '', $lower); + $numericCheck = \str_replace('e', '', $lower); + return \is_numeric($numericCheck); } // Use built-in numeric check return \is_numeric($value); }
118-118: Be aware that assertions may be disabled in production.While the assert statement provides a good runtime type check during development, assertions might be disabled in production environments. Consider adding a fallback validation if this check is critical.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/MartinGeorgiev/Utils/ArrayDataTransformer.php(1 hunks)src/MartinGeorgiev/Utils/Exception/InvalidArrayFormatException.php(1 hunks)tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php
🧰 Additional context used
🧬 Code Definitions (1)
src/MartinGeorgiev/Utils/ArrayDataTransformer.php (2)
src/MartinGeorgiev/Utils/Exception/InvalidArrayFormatException.php (3)
InvalidArrayFormatException(7-23)multiDimensionalArrayNotSupported(9-12)invalidFormat(14-22)tests/MartinGeorgiev/Utils/ArrayDataTransformerTest.php (1)
__toString(138-141)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest
- GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest
- GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
- GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
- GitHub Check: sloth
🔇 Additional comments (5)
src/MartinGeorgiev/Utils/Exception/InvalidArrayFormatException.php (1)
7-23: Well-designed exception class with clear static factory methods.This new exception class is well-structured and follows good practices. The static factory methods provide clear, specific error messages for different invalid array scenarios.
src/MartinGeorgiev/Utils/ArrayDataTransformer.php (4)
26-54: Comprehensive transformation from PostgreSQL text array to PHP array.The implementation handles edge cases well (empty strings, null values, empty arrays) and properly throws exceptions for unsupported formats. The JSON-based approach for parsing is elegant.
62-79: Solid implementation of PHP array to PostgreSQL text array conversion.The method properly handles empty arrays and prevents multi-dimensional arrays. The formatting approach ensures proper escaping and type preservation.
84-137: Thorough value formatting with proper type handling.The method handles different data types appropriately, preserving numeric types and properly escaping strings. Good handling of objects with __toString() method.
156-169:✅ Verification successful
Verify that placeholder strings won't conflict with actual content.
The method uses
___QUOTE___and___DBLBACK___as temporary placeholders during the unescaping process. While unlikely, there's a small risk these could conflict with actual string content.
🏁 Script executed:
#!/bin/bash # Check if any string literals in the codebase already contain the placeholder strings echo "Checking for potential placeholder conflicts..." rg -l "___QUOTE___" --type php rg -l "___DBLBACK___" --type phpLength of output: 268
Final Verification: No External Conflicts Found
The search confirms that both placeholder strings (
___QUOTE___and___DBLBACK___) appear only withinsrc/MartinGeorgiev/Utils/ArrayDataTransformer.php, specifically in theunescapeStringmethod. There’s no evidence of these strings being present in other parts of the codebase, so the likelihood of conflict with actual content is minimal.
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 17182 ## Changes to type handling
This PR significantly improves how numeric types and booleans are preserved when transforming data between PostgreSQL arrays and PHP. Previously, type information could be lost during transformation, resulting in unexpected behavior when retrieving data.
### Numbers handling
**Before:**
- Numbers could lose their original type during transformation
- Float values might be converted to integers (e.g., `1.0` → `1`)
- String representation of numbers could be converted to actual numbers
**After:**
- Type information is carefully preserved in both directions
- Integers stay as integers: `1` → `1`
- Floats stay as floats: `1.5` → `1.5`
- Numeric strings stay as strings: `'1.0'` → `'1.0'`
### Examples
#### Integer/float preservation
```php
// Before
$phpArray = [1, 2.5, '3.0'];
// After transformation back from PostgreSQL:
// [1, 2, 3] (types and precision could be lost)
// After
$phpArray = [1, 2.5, '3.0'];
// After transformation back from PostgreSQL:
// [1, 2.5, '3.0'] (original types preserved)Boolean handling// Before
$phpArray = [true, false];
// Might be inconsistently handled
// After
$phpArray = [true, false];
// Properly converted to PostgreSQL 'true'/'false' and back
// Returns [true, false] with correct boolean typesLarge integers and scientific notation// Before
$phpArray = ['9223372036854775808', '1.23e5'];
// After transformation:
// Potential loss of precision or conversion to different types
// After
$phpArray = ['9223372036854775808', '1.23e5'];
// After transformation:
// ['9223372036854775808', '1.23e5'] (preserved exactly)Benefits
Learnt from: martin-georgiev Timestamp: 2025-03-26T02:46:11.769Z #!/bin/bash Look at the old DataStructure implementationecho "--- Old Implementation (DataStructure.php) ---" echo "\n\n--- New Implementation (ArrayDataTransformer.php) ---" echo "\n\n--- Test cases demonstrating the behavior ---" Boolean handling// Before
$phpArray = [true, false];
// Might be inconsistently handled
// After
$phpArray = [true, false];
// Properly converted to PostgreSQL 'true'/'false' and back
// Returns [true, false] with correct boolean typesLarge integers and scientific notation// Before
$phpArray = ['9223372036854775808', '1.23e5'];
// After transformation:
// Potential loss of precision or conversion to different types
// After
$phpArray = ['9223372036854775808', '1.23e5'];
// After transformation:
// ['9223372036854775808', '1.23e5'] (preserved exactly)Benefits
Learnt from: martin-georgiev Timestamp: 2025-03-26T02:46:11.769Z |
Changes to type handling
This PR significantly improves how numeric types and booleans are preserved when transforming data between PostgreSQL arrays and PHP. Previously, type information could be lost during transformation, resulting in unexpected behavior when retrieving data.
Numbers handling
Before:
1.0→1)After:
1→11.5→1.5'1.0'→'1.0'Examples
Integer/float preservation
Boolean
Large integers and scientific notation
Summary by CodeRabbit
Refactor
Tests
ArrayDataTransformerclass.