Skip to content

Fix #20766: Fix @param annotation for $offset in yii\db\ArrayExpression::offsetSet(), fix yii\db\ArrayExpression::offsetSet() to append when $offset is null - #20766

Merged
samdark merged 16 commits into
yiisoft:masterfrom
WarLikeLaux:add-ArrayExpressionTest
Oct 28, 2026

Conversation

@WarLikeLaux

@WarLikeLaux WarLikeLaux commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Is bugfix? ✔️
New feature? ❌
Tests added? ✔️
Breaks BC? ❌
Fixed issues

What does this PR do?

Adds ArrayExpressionTest - unit tests for yii\db\ArrayExpression.

The tests exercise $expr[] = ... (append), which makes PHP call offsetSet(null, ...). The method's @param int|string $offset did not allow null, so this PR widens it to int|string|null to match the actual ArrayAccess contract.

Coverage

28 tests, 47 assertions. Line coverage: 19/19 (100%). MSI: 100% (18/18).

@codecov

codecov Bot commented Mar 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.90%. Comparing base (79b6d5f) to head (6aec600).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
framework/db/ArrayExpression.php 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #20766      +/-   ##
============================================
- Coverage     81.91%   81.90%   -0.01%     
- Complexity    11560    11562       +2     
============================================
  Files           374      374              
  Lines         30305    30307       +2     
============================================
  Hits          24824    24824              
- Misses         5481     5483       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 358701dc-3c7b-4370-997c-c80ca7b08464

📥 Commits

Reviewing files that changed from the base of the PR and between b2bb5f2 and cacecfc.

📒 Files selected for processing (2)
  • framework/CHANGELOG.md
  • framework/db/ArrayExpression.php

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (63)
  • GitHub Check: MariaDB tests / PHP 8.3-mysql-latest
  • GitHub Check: MariaDB tests / PHP 8.0-mysql-latest
  • GitHub Check: MariaDB tests / PHP 8.1-mysql-latest
  • GitHub Check: MariaDB tests / PHP 8.2-mysql-latest
  • GitHub Check: MariaDB tests with coverage / PHP 7.4-mysql-latest
  • GitHub Check: phpstan-7x / PHP 7.4-ubuntu-latest
  • GitHub Check: MariaDB tests with coverage / PHP 8.5-mysql-latest
  • GitHub Check: MariaDB tests / PHP 8.4-mysql-latest
  • GitHub Check: MariaDB tests with coverage / PHP 7.4-mysql-10.4
  • GitHub Check: MariaDB tests with coverage / PHP 8.5-mysql-10.4
  • GitHub Check: MSSQL tests / PHP 8.0-mssql-2022-latest
  • GitHub Check: MSSQL tests / PHP 8.2-mssql-2022-latest
  • GitHub Check: phpstan / PHP 8.5-ubuntu-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-16
  • GitHub Check: MSSQL tests with coverage / PHP 8.5-mssql-2019-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-14
  • GitHub Check: MSSQL tests / PHP 8.4-mssql-2022-latest
  • GitHub Check: MSSQL tests / PHP 8.1-mssql-2022-latest
  • GitHub Check: MSSQL tests with coverage / PHP 8.5-mssql-2022-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-15
  • GitHub Check: PostgreSQL tests / PHP 8.2-pgsql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-17
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-15
  • GitHub Check: MSSQL tests / PHP 8.3-mssql-2022-latest
  • GitHub Check: MSSQL tests with coverage / PHP 7.4-mssql-2022-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-14
  • GitHub Check: MSSQL tests with coverage / PHP 7.4-mssql-2019-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-10
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-12
  • GitHub Check: PostgreSQL tests / PHP 8.0-pgsql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-12
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-11
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-17
  • GitHub Check: PostgreSQL tests / PHP 8.1-pgsql-latest
  • GitHub Check: MySQL tests / PHP 8.1-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-11
  • GitHub Check: MySQL tests / PHP 8.0-mysql-latest
  • GitHub Check: PostgreSQL tests with coverage / PHP 8.5-pgsql-13
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-13
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-10
  • GitHub Check: MySQL tests with coverage / PHP 8.5-mysql-5.7
  • GitHub Check: PostgreSQL tests with coverage / PHP 7.4-pgsql-16
  • GitHub Check: PostgreSQL tests / PHP 8.4-pgsql-latest
  • GitHub Check: PostgreSQL tests / PHP 8.3-pgsql-latest
  • GitHub Check: MySQL tests / PHP 8.4-mysql-latest
  • GitHub Check: MySQL tests with coverage / PHP 8.5-mysql-latest
  • GitHub Check: MySQL tests with coverage / PHP 7.4-mysql-latest
  • GitHub Check: MySQL tests / PHP 8.3-mysql-latest
  • GitHub Check: MySQL tests / PHP 8.2-mysql-latest
  • GitHub Check: MySQL tests with coverage / PHP 7.4-mysql-5.7
  • GitHub Check: Oracle tests with coverage / PHP 8.5-oracle-slim-faststart
  • GitHub Check: Oracle tests with coverage / PHP 7.4-oracle-slim-faststart
  • GitHub Check: rector / PHP 8.5-ubuntu-latest
  • GitHub Check: PHP 8.5
  • GitHub Check: PHP 8.1
  • GitHub Check: PHP 8.3
  • GitHub Check: PHP 8
  • GitHub Check: PHP 7.4
  • GitHub Check: PHP 8.4
  • GitHub Check: PHP 8.2
  • GitHub Check: PHP 8.6
🧰 Additional context used
🪛 PHPMD (2.15.0)
framework/db/ArrayExpression.php

[error] 152-154: The method offsetSet uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. (undefined)

(ElseExpression)

🔇 Additional comments (2)
framework/db/ArrayExpression.php (1)

138-138: LGTM!

Also applies to: 150-154

framework/CHANGELOG.md (1)

40-41: LGTM!

📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Fixed array value assignment so that when no offset is provided, the value is appended to the end.
    • Clarified documentation that offsets can be nullable.
  • Tests

    • Added coverage for array expression construction, access, mutation, counting, iteration, and nested values.

This PR adds PHPUnit tests for yii\db\ArrayExpression. The tests cover construction, array access, counting, iteration, mutations, nested unwrapping, and interface implementation. offsetSet() now appends values when $offset is null, and its PHPDoc documents nullable offsets.

Changes: ArrayExpression behavior

Layer / File(s) Summary
Constructor input handling
tests/framework/db/ArrayExpressionTest.php
Tests cover array inputs, optional type and dimension parameters, nested ArrayExpression unwrapping, Query inputs, scalar values, and null values.
Offset mutation and count behavior
framework/db/ArrayExpression.php, tests/framework/db/ArrayExpressionTest.php, framework/CHANGELOG.md
offsetSet() now appends values for null offsets and documents nullable offsets. Tests cover keyed assignment, appending, removal, count changes, and mutation results. The changelog records the changes.
Iterator and interface behavior
tests/framework/db/ArrayExpressionTest.php
Tests verify ArrayIterator results, iteration over arrays and null values, Query iteration errors, and ExpressionInterface implementation.
Merge Risk: Minimal · up to cacec

Array append behavior is now supported and covered by focused tests, with no concrete merge-blocking risk identified. The change is ready to merge subject to normal project checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the added ArrayExpressionTest and the offsetSet() PHPDoc fix, which are the main changes.
Description check ✅ Passed The description directly explains the new tests, the offsetSet(null, ...) behavior, and the PHPDoc correction.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 2 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit taps a null-keyed row
And watches fresh values grow
ArrayExpression keeps count in sight
Its iterator hops through each byte
Tests trace the paths from start to end
Then the rabbit thumps: append, my friend!

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the status:code review The pull request needs review. label Jun 4, 2026
@WarLikeLaux WarLikeLaux changed the title Add ArrayExpressionTest Add ArrayExpressionTest and fix offsetSet() PHPDoc Jun 5, 2026
@samdark samdark changed the title Add ArrayExpressionTest and fix offsetSet() PHPDoc Fix #20766: Fix @param annotation for $offset in yii\db\ArrayExpression::offsetSet(), fix yii\db\ArrayExpression::offsetSet() to append when $offset is null Oct 28, 2026
@samdark
samdark merged commit df334f0 into yiisoft:master Oct 28, 2026
80 of 84 checks passed
@samdark

samdark commented Oct 28, 2026

Copy link
Copy Markdown
Member

👍

@coderabbitai coderabbitai Bot mentioned this pull request Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review. type:test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants