Skip to content

Conversation

@fogelito
Copy link
Contributor

@fogelito fogelito commented Jul 14, 2025

Summary by CodeRabbit

  • New Features

    • Added support for a new ID attribute type accommodating both integer and string formats.
    • Enhanced validation for ID and sequence attributes with stricter rules and handling of edge cases.
    • Updated collection schemas, document processing, and database adapters to fully integrate the new ID attribute type.
  • Bug Fixes

    • Improved type casting to ensure consistent handling of ID and sequence values across all database adapters.
  • Tests

    • Expanded test coverage for the new ID attribute type, including creation, querying, and validation scenarios.
    • Updated existing tests to reflect changes in ID attribute handling and validation.
  • Chores

    • Configured test runner to halt immediately on first failure for faster feedback.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Warning

Rate limit exceeded

@fogelito has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf59b5 and 5e53fba.

📒 Files selected for processing (1)
  • src/Database/Database.php (17 hunks)

"""

Walkthrough

This change introduces a new ID attribute type VAR_ID to the database schema, updates adapters and validators to handle IDs as either integers or strings depending on the adapter, and modifies internal casting and validation logic accordingly. Test suites are extended to cover these new types, including edge cases and validation scenarios.

Changes

Files/Paths Change Summary
src/Database/Database.php, src/Database/Validator/Structure.php, src/Database/Validator/Queries/Documents.php, src/Database/Validator/Query/Filter.php, src/Database/Validator/Sequence.php Added VAR_ID type; integrated into attribute definitions, validation, and casting; new Sequence validator class added.
src/Database/Adapter.php, src/Database/Adapter/Pool.php, src/Database/Adapter/SQL.php Added abstract method getIdAttributeType() to Adapter; implemented in Pool and SQL adapter returning ID type string.
src/Database/Adapter/MariaDB.php, src/Database/Adapter/Postgres.php, src/Database/Adapter/SQLite.php Added support for VAR_ID in SQL type mapping; removed integer casts on tenant; cast sequence fields to integer explicitly in SQLite createDocument.
src/Database/Document.php Changed Document::getSequence() return type from string to `int
tests/e2e/Adapter/Scopes/AttributeTests.php, tests/e2e/Adapter/Scopes/CollectionTests.php, tests/e2e/Adapter/Scopes/DocumentTests.php Extended tests to cover VAR_ID attributes, including creation, deletion, and edge cases such as null and zero values.
tests/unit/Validator/DocumentsQueriesTest.php, tests/unit/Validator/IndexedQueriesTest.php, tests/unit/Validator/QueriesTest.php, tests/unit/Validator/Query/FilterTest.php, tests/unit/Validator/QueryTest.php Updated validator tests to pass the new ID attribute type argument and include queries on the ID attribute.
tests/unit/Validator/StructureTest.php Added tests for ID attribute with integer and string validation modes; new test method for ID validation behavior.
phpunit.xml Changed PHPUnit configuration to stop test execution on first failure.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Database
    participant Adapter
    participant Validator

    Client->>Database: createDocument(data)
    Database->>Adapter: getIdAttributeType()
    Adapter-->>Database: 'int' or 'string'
    Database->>Validator: Structure(attributes, indexes, idType)
    Validator->>Validator: Validate attributes (including VAR_ID)
    Validator-->>Database: Validation result
    Database->>Adapter: Insert document
    Adapter-->>Database: Document with typed sequence/id
    Database-->>Client: Created Document
Loading

Possibly related PRs

  • Sequence func as int #607: Adds an abstract method getIdAttributeType() and changes internal handling of the $sequence attribute to integer type, directly related to this PR's changes to ID and sequence attribute typing.

Poem

In the warren of code, IDs now gleam,
Integer or string, they join the stream.
Sequence hops forward, never outdone,
Validators check each and every one.
With tests that burrow deep and wide,
The database grows with rabbit pride!
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
phpunit.xml (1)

10-10: Re-evaluate stopOnFailure="true" for CI runs

Halting on the first failure speeds up local troubleshooting, but in CI it can mask additional regressions and shrink the failure signal. Consider:

• Keeping stopOnFailure="false" in the committed config and passing --stop-on-failure locally/through a CI job matrix, or
• Supplying two configs (e.g., phpunit.ci.xml vs phpunit.dev.xml) and selecting via -c flag.

This preserves fast feedback for developers while still surfacing the full failure set in automated pipelines.

src/Database/Validator/Structure.php (1)

53-53: Remove the unclear comment.

The comment // ????? appears to be a leftover and should be removed for code clarity.

-            'type' => Database::VAR_INTEGER, // ?????
+            'type' => Database::VAR_INTEGER,
src/Database/Database.php (2)

170-172: Verify if VAR_SEQUENCE type needs validation

The $sequence attribute type was changed from VAR_STRING to VAR_SEQUENCE, but there's no validation case for VAR_SEQUENCE in the validateAttribute method. Should this new type have validation logic?

Would you like me to check if VAR_SEQUENCE type requires validation logic similar to other attribute types?


43-44: Consider adding comprehensive validation for new attribute types

With the introduction of VAR_ID and VAR_SEQUENCE types, ensure that:

  1. Both types have appropriate validation logic in validateAttribute()
  2. Default value validation in validateDefaultTypes() handles these new types
  3. Documentation is updated to explain when to use each type

Also applies to: 1792-1813

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb2f759 and 4515f21.

📒 Files selected for processing (20)
  • phpunit.xml (1 hunks)
  • src/Database/Adapter.php (1 hunks)
  • src/Database/Adapter/MariaDB.php (3 hunks)
  • src/Database/Adapter/Pool.php (1 hunks)
  • src/Database/Adapter/Postgres.php (1 hunks)
  • src/Database/Adapter/SQL.php (3 hunks)
  • src/Database/Database.php (14 hunks)
  • src/Database/Validator/Queries/Documents.php (3 hunks)
  • src/Database/Validator/Query/Filter.php (3 hunks)
  • src/Database/Validator/Sequence.php (1 hunks)
  • src/Database/Validator/Structure.php (4 hunks)
  • tests/e2e/Adapter/Scopes/AttributeTests.php (4 hunks)
  • tests/e2e/Adapter/Scopes/CollectionTests.php (3 hunks)
  • tests/e2e/Adapter/Scopes/DocumentTests.php (5 hunks)
  • tests/unit/Validator/DocumentsQueriesTest.php (4 hunks)
  • tests/unit/Validator/IndexedQueriesTest.php (3 hunks)
  • tests/unit/Validator/QueriesTest.php (1 hunks)
  • tests/unit/Validator/Query/FilterTest.php (1 hunks)
  • tests/unit/Validator/QueryTest.php (10 hunks)
  • tests/unit/Validator/StructureTest.php (23 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/Database/Adapter/Postgres.php (1)
Learnt from: ArnabChatterjee20k
PR: utopia-php/database#613
File: src/Database/Adapter/Postgres.php:1254-1319
Timestamp: 2025-07-01T11:31:37.438Z
Learning: In PostgreSQL adapter methods like getUpsertStatement, complexity for database-specific SQL generation is acceptable when the main business logic is properly separated in the parent SQL adapter class, following the adapter pattern where each database adapter handles its own SQL syntax requirements.
🧬 Code Graph Analysis (7)
src/Database/Adapter.php (2)
src/Database/Adapter/SQL.php (1)
  • getIdAttributeType (1588-1591)
src/Database/Adapter/Pool.php (1)
  • getIdAttributeType (493-496)
tests/unit/Validator/IndexedQueriesTest.php (1)
src/Database/Validator/Query/Filter.php (1)
  • Filter (15-299)
tests/unit/Validator/QueryTest.php (1)
src/Database/Validator/Queries/Documents.php (1)
  • Documents (16-76)
src/Database/Adapter/SQL.php (3)
src/Database/Database.php (1)
  • Database (35-6807)
src/Database/Adapter/Pool.php (1)
  • getIdAttributeType (493-496)
src/Database/Adapter.php (1)
  • getIdAttributeType (862-862)
src/Database/Adapter/MariaDB.php (1)
src/Database/Database.php (1)
  • Database (35-6807)
src/Database/Validator/Structure.php (2)
src/Database/Database.php (1)
  • Database (35-6807)
src/Database/Validator/Sequence.php (1)
  • Sequence (10-74)
tests/unit/Validator/QueriesTest.php (1)
src/Database/Validator/Query/Filter.php (1)
  • Filter (15-299)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Setup & Build Docker Image
🔇 Additional comments (49)
src/Database/Adapter/Pool.php (1)

493-496: LGTM! Clean delegation implementation.

The new getIdAttributeType() method follows the established delegation pattern used throughout the Pool class. The implementation correctly forwards the method call to the underlying adapter instance, maintaining consistency with the proxy design.

src/Database/Adapter.php (1)

857-862: LGTM! Well-documented abstract method.

The new getIdAttributeType() abstract method is properly documented and follows the established pattern for abstract methods in the Adapter class. The string return type is appropriate for type identifiers, and the method name clearly conveys its purpose.

tests/unit/Validator/IndexedQueriesTest.php (3)

83-83: LGTM! Correct constructor parameter addition.

The Filter validator constructor now requires an ID attribute type parameter. Adding 'int' as the second argument is correct and consistent with the new constructor signature.


146-146: LGTM! Consistent with other test method updates.

The Filter constructor call correctly includes the required ID attribute type parameter, maintaining consistency with the other test methods in this file.


199-199: LGTM! Properly updated constructor call.

The Filter validator instantiation correctly includes the required 'int' parameter for the ID attribute type, aligning with the updated constructor signature.

tests/unit/Validator/QueriesTest.php (1)

66-66: LGTM! Consistent test update.

The Filter validator constructor call correctly includes the required ID attribute type parameter 'int', matching the updated constructor signature and maintaining consistency with similar changes in other test files.

src/Database/Adapter/Postgres.php (1)

1820-1821: LGTM! Correct PostgreSQL type mapping for VAR_ID.

The mapping of Database::VAR_ID to PostgreSQL's bigint type is appropriate and follows the established pattern in the switch statement. This provides sufficient range for ID values while being consistent with PostgreSQL's type system (which doesn't support unsigned integers).

src/Database/Adapter/SQL.php (3)

1006-1009: LGTM: Correct attribute width allocation for new ID types.

The addition of VAR_SEQUENCE and VAR_ID cases with 8-byte allocation is appropriate for BIGINT storage in SQL databases. This aligns with the new attribute types introduced in the codebase.


372-372: LGTM: Proper type casting for sequence value.

The explicit casting of $sequence to (int) ensures consistency with the integer-based ID attribute type returned by getIdAttributeType(). This maintains type safety when mapping from the database _id field.


1585-1591: LGTM: Implementation of required abstract method.

The getIdAttributeType() method correctly implements the abstract method from the parent Adapter class and returns 'int' as expected for SQL adapters. This is consistent with the integer-based ID handling in SQL databases.

tests/unit/Validator/DocumentsQueriesTest.php (4)

79-89: LGTM: Comprehensive test coverage for new ID attribute type.

The addition of the 'id' attribute document with type Database::VAR_ID properly extends the test collection schema to include the new attribute type. The configuration is consistent with other attribute definitions in the test setup.


126-130: LGTM: Updated validator instantiation for ID attribute type support.

The addition of the third parameter 'int' to the Documents validator constructor is required for the new ID attribute type handling. This aligns with the updated constructor signature in the Documents validator class.


133-133: LGTM: Added test coverage for ID attribute queries.

The new test query Query::notEqual('id', '1000000') validates that the ID attribute can be properly queried, ensuring the new VAR_ID attribute type is fully integrated into the query validation system.


164-168: LGTM: Consistent validator instantiation in invalid queries test.

The update maintains consistency with the new Documents validator constructor signature across all test methods.

tests/unit/Validator/QueryTest.php (2)

111-111: LGTM: Consistent update to validator instantiation.

The addition of the third parameter 'int' to the Documents validator constructor is correctly applied. This change is consistent with the new constructor signature that requires the ID attribute type parameter.


141-141: LGTM: Comprehensive update across all test methods.

All instances of Documents validator instantiation have been consistently updated to include the 'int' parameter. This ensures all tests remain functional with the new constructor signature and validates the integer-based ID attribute type handling throughout the query validation system.

Also applies to: 157-157, 169-169, 180-180, 194-194, 208-208, 228-228, 258-258, 287-287

tests/e2e/Adapter/Scopes/CollectionTests.php (3)

110-118: LGTM - VAR_ID attribute definition follows correct pattern.

The new attribute definition for Database::VAR_ID type is well-structured and follows the existing pattern. The configuration with signed: false is appropriate for ID fields, which are typically unsigned.


143-149: LGTM - Index definition correctly targets the VAR_ID attribute.

The index definition properly references the new VAR_ID attribute and follows the standard index configuration pattern used in the test.


158-158: LGTM - Assertions correctly updated for the new attribute and index.

The assertion counts are properly updated from 3 to 4, and the new assertions verify that:

  • attribute4 has the correct ID and Database::VAR_ID type
  • index4 has the correct ID and Database::INDEX_KEY type

The test coverage is comprehensive and consistent with the existing test structure.

Also applies to: 165-166, 169-169, 176-177

src/Database/Adapter/MariaDB.php (3)

907-914: LGTM! Proper type casting for sequence values.

The integer cast ensures consistent type handling for sequence values returned by PDO.


1644-1647: LGTM! Consistent integer casting for document IDs.

The cast ensures document sequence values are integers when retrieving documents from the database.


1909-1911: LGTM! Appropriate SQL type for ID attributes.

Using bigint UNSIGNED provides a suitable range for auto-incrementing ID values.

tests/unit/Validator/Query/FilterTest.php (1)

21-48: LGTM! Test updated correctly for new Filter constructor.

The change properly adapts to the new Filter constructor signature that requires the ID attribute type parameter.

src/Database/Validator/Structure.php (2)

34-40: LGTM! Correct type for sequence attribute.

The change from VAR_STRING to VAR_SEQUENCE properly reflects the semantic type of the sequence attribute.


319-326: LGTM! Proper validation for new attribute types.

The new cases correctly handle VAR_SEQUENCE and VAR_ID types using the Sequence validator with appropriate primary flags.

src/Database/Validator/Queries/Documents.php (1)

23-75: LGTM! Consistent implementation of ID attribute type support.

The changes properly integrate the ID attribute type parameter and update the sequence attribute type to VAR_SEQUENCE, maintaining consistency with the broader changes.

tests/e2e/Adapter/Scopes/AttributeTests.php (4)

74-74: LGTM: Adding VAR_ID attribute type test coverage.

This addition tests the new VAR_ID attribute type, which is consistent with the PR objective of introducing primary attribute integer representation.


76-76: LGTM: Testing index creation on VAR_ID attribute.

The addition of an index on the id attribute provides comprehensive test coverage for the new attribute type's indexing capabilities.


82-82: LGTM: Attribute counts correctly updated.

The attribute counts are properly incremented to reflect the addition of the id attribute (from 8 to 9, 12 to 13, 17 to 18).

Also applies to: 92-92, 102-102


113-113: LGTM: Proper cleanup of test attribute.

The deletion of the id attribute follows the established test pattern and ensures proper cleanup.

tests/unit/Validator/StructureTest.php (4)

93-102: LGTM: Adding VAR_ID attribute to test collection.

The addition of the id attribute with type Database::VAR_ID is properly structured and follows the existing attribute pattern in the test collection.


134-137: LGTM: Consistent addition of ID attribute type parameter.

The second parameter 'int' (and 'string' in the new test) is consistently added to all Structure validator constructor calls, which aligns with the new validator signature.

Also applies to: 149-152, 161-164, 182-185, 202-205, 233-236, 255-258, 276-279, 295-298, 316-319, 377-380, 396-399, 415-418, 449-452, 507-510, 541-544, 575-578, 596-599, 617-620, 638-641, 657-660, 696-699


655-724: LGTM: Comprehensive testing of both ID attribute types.

The new testId() method provides excellent coverage for both integer and string ID types, validating the behavior differences between SQL and MongoDB-style IDs.


216-216: LGTM: Adding ID field to test document.

The addition of the id field in the test document provides appropriate test coverage for the new attribute type.

src/Database/Validator/Sequence.php (4)

10-27: LGTM: Well-structured validator class.

The class design is clean with appropriate private properties and a clear constructor signature. The getDescription() method provides a consistent error message.


29-41: LGTM: Proper type information methods.

The isArray() and getType() methods correctly indicate that sequences are not arrays and return the appropriate type based on the ID attribute type.


49-50: LGTM: Proper MongoDB ObjectId validation.

The regex pattern /^[a-f0-9]{24}$/i correctly validates 24-character hexadecimal strings, which is the standard format for MongoDB ObjectIds.


53-67: LGTM: Comprehensive integer validation.

The integer validation logic is well-structured:

  • Type check ensures the value is an integer
  • Uses the Integer validator for additional validation
  • Applies appropriate range validation with different start values for primary vs non-primary sequences
src/Database/Validator/Query/Filter.php (3)

9-9: LGTM: Import added for new validation logic.

The import of Sequence validator is correctly added to support the new VAR_SEQUENCE and VAR_ID attribute validation cases.


111-118: LGTM: New validation cases correctly implemented.

The validation logic for VAR_SEQUENCE and VAR_ID attribute types is correctly implemented:

  • Both use the Sequence validator with the injected $idAttributeType
  • The boolean parameter appropriately differentiates between sequence (true) and ID (false) types
  • Follows the same pattern as other validation cases

This aligns with the broader database schema changes to support integer representation of primary attributes.


29-30: All Filter constructor calls include the new parameters

Verified that every new Filter( instantiation now supplies both the required $attributes and the new $idAttributeType argument. No usages were found missing the updated signature in:

  • src/Database/Validator/Queries/Documents.php
  • tests/unit/Validator/QueriesTest.php
  • tests/unit/Validator/IndexedQueriesTest.php
  • tests/unit/Validator/Query/FilterTest.php

No further changes are required.

src/Database/Database.php (1)

3654-3657: Consistent implementation of configurable ID attribute type

The addition of $this->adapter->getIdAttributeType() parameter to all validator instantiations is implemented consistently throughout the file. This enables adapters to configure whether ID fields should be integers or strings.

Also applies to: 3743-3746, 4274-4277

tests/e2e/Adapter/Scopes/DocumentTests.php (7)

42-42: LGTM: VAR_ID attribute creation test

The test correctly creates a VAR_ID attribute, which aligns with the new functionality for integer ID representation.


70-70: LGTM: Integer value assignment for VAR_ID

The test correctly assigns an integer value (1000000) to the VAR_ID attribute, testing the core functionality.


94-95: LGTM: VAR_ID validation assertions

The assertions correctly verify that the VAR_ID attribute maintains its integer type and value after document creation.


150-150: LGTM: Default null value test

The test correctly verifies that when no value is provided for the VAR_ID attribute, it defaults to null.


215-235: LGTM: Sequence validation test

The test appropriately validates that invalid sequence values (like '0') are rejected with proper error handling.


237-268: LGTM: Comprehensive null value testing

The test block thoroughly validates VAR_ID behavior with explicit null values:

  • Document creation with null ID
  • Document retrieval maintains null value
  • Query functionality works with null values using Query::isNull()

This provides good coverage for the null value edge case.


269-302: LGTM: Zero value edge case testing

The test block comprehensively covers the zero value edge case for VAR_ID:

  • Document creation with zero ID value
  • Verifies the value is stored as integer 0 (not null)
  • Tests document retrieval and querying with zero values

This is important for distinguishing between null and zero values in integer ID fields.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4515f21 and 7657f7f.

📒 Files selected for processing (4)
  • src/Database/Adapter/Postgres.php (3 hunks)
  • src/Database/Database.php (14 hunks)
  • src/Database/Document.php (1 hunks)
  • tests/e2e/Adapter/Scopes/DocumentTests.php (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/e2e/Adapter/Scopes/DocumentTests.php
  • src/Database/Adapter/Postgres.php
  • src/Database/Database.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Adapter Tests (Mirror)
  • GitHub Check: Adapter Tests (SharedTables/MySQL)
  • GitHub Check: Adapter Tests (SQLite)
  • GitHub Check: Adapter Tests (Pool)
  • GitHub Check: Adapter Tests (Postgres)
  • GitHub Check: Adapter Tests (SharedTables/Postgres)
  • GitHub Check: Adapter Tests (MySQL)
  • GitHub Check: Adapter Tests (SharedTables/MariaDB)
  • GitHub Check: Adapter Tests (SharedTables/SQLite)
  • GitHub Check: Adapter Tests (MariaDB)
  • GitHub Check: Unit Test
🔇 Additional comments (1)
src/Database/Document.php (1)

69-69: Ensure getSequence() Null Safety After Removing Default
Without a default in getAttribute('$sequence'), getSequence() can now return null. Since sequence values are used for:

  • String concatenation in src/Database/Database.php (e.g. collection/junction naming)
  • Conditional checks and parameter binding in src/Database/Adapter/{SQLite,SQL,Postgres,MariaDB}.php
  • Test assertions in tests/e2e/Adapter/Scopes (e.g. assertNotEmpty, assertNotNull)

Please verify that every call site either:

  • Guarantees a non-null sequence before invoking getSequence()
  • Handles a null return value safely
  • Or update getSequence() to provide a fallback (for example: return $this->getAttribute('$sequence') ?? '';)

Comment on lines 65 to 67
* @return mixed
*/
public function getSequence(): string
public function getSequence(): mixed
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider backward compatibility implications of the return type change.

The return type change from string to mixed could break existing code that expects a string value. This change allows the method to return integers, strings, or null, which aligns with the new VAR_SEQUENCE attribute type but may require updates to consuming code.

Consider documenting the possible return types and their meanings in the method's PHPDoc comment.


🏁 Script executed:

#!/bin/bash
# Description: Find all usages of getSequence() method to assess backward compatibility impact
# Expected: Identify code that might assume string return type

echo "Searching for getSequence() method calls..."
rg -A 3 -B 1 "getSequence\(\)" --type php

echo -e "\nSearching for type-specific operations on sequence values..."
rg -A 2 -B 2 "->getSequence\(\)->" --type php
rg -A 2 -B 2 "strlen.*getSequence" --type php
rg -A 2 -B 2 "substr.*getSequence" --type php

Length of output: 14544


Refine getSequence() return type annotation and document nullability

The change from string to mixed is safe—no direct string-only operations were found (only concatenation and PDO binding, which handle int|string|null via PHP’s implicit casts). However, the method’s PHPDoc and signature can be more precise:

  • File: src/Database/Document.php (around the getSequence() declaration)
    • Update the @return tag from mixed to int|string|null
    • Document what each type means (e.g. integer for auto-increment adapters, string for UUIDs, null when unset)

Suggested diff:

     /**
-    * @return mixed
+    * @return int|string|null  Sequence value:
+    *                           - int:  auto-increment sequences
+    *                           - string: UUID or custom identifiers
+    *                           - null: when no sequence attribute is set
     */
-    public function getSequence(): mixed
+    public function getSequence(): int|string|null
🤖 Prompt for AI Agents
In src/Database/Document.php around lines 65 to 67, refine the getSequence()
method's PHPDoc and return type by changing the @return annotation from mixed to
int|string|null, and update the method signature to reflect this nullable union
type. Add documentation explaining that int represents auto-increment adapters,
string represents UUIDs, and null indicates the sequence is unset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants