Skip to content

Use array key first/last functions#2696

Merged
Crabcyborg merged 3 commits into
masterfrom
use_array_key_first_last_functions
Dec 30, 2025
Merged

Use array key first/last functions#2696
Crabcyborg merged 3 commits into
masterfrom
use_array_key_first_last_functions

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

These are polyfilled in WP 5.9+. Since we're targeting 6.3+ now, this should be safe.

@coderabbitai

coderabbitai Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This PR refactors array key retrieval operations by replacing deprecated iterator-based methods (end()/reset()/key()) with modern PHP array functions (array_key_last()/array_key_first()), and enables the previously-disabled ArrayKeyFirstLastRector rule in the rector configuration.

Changes

Cohort / File(s) Change Summary
Array Key Retrieval Refactoring
classes/controllers/FrmXMLController.php, classes/models/FrmEntryValidate.php, classes/models/fields/FrmFieldType.php
Replaced deprecated iterator manipulation (end(), reset(), key()) with modern PHP array functions: array_key_last() and array_key_first(). No behavioral changes; logic and control flow remain equivalent.
Rector Configuration Update
rector.php
Removed import and skip declaration for ArrayKeyFirstLastRector, effectively enabling the rule to guide future array key retrieval refactoring.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing end()/key() patterns with array_key_first() and array_key_last() functions across multiple files.
Description check ✅ Passed The description is related to the changeset, providing context about WordPress version targeting and the safety of using these polyfilled functions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbfad08 and a259c26.

📒 Files selected for processing (4)
  • classes/controllers/FrmXMLController.php
  • classes/models/FrmEntryValidate.php
  • classes/models/fields/FrmFieldType.php
  • rector.php
💤 Files with no reviewable changes (1)
  • rector.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). (2)
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: Cypress
🔇 Additional comments (3)
classes/models/FrmEntryValidate.php (1)

1011-1011: LGTM! Clean refactor to modern array function.

The change from end()/key() to array_key_last() is a good modernization that eliminates side effects on the array's internal pointer and improves code clarity.

classes/models/fields/FrmFieldType.php (1)

1560-1560: LGTM! Improved accessibility code with modern array function.

Replacing reset()/key() with array_key_first() provides a cleaner way to determine the ordering of ARIA descriptors without side effects. The comparison logic remains functionally equivalent.

classes/controllers/FrmXMLController.php (1)

89-89: LGTM! Clean refactor for retrieving last form ID.

The change to array_key_last() is a good modernization that avoids modifying the array's internal pointer. The logic for redirecting to the last imported form remains functionally equivalent.


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

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

@Crabcyborg
Crabcyborg merged commit b7a4970 into master Dec 30, 2025
16 checks passed
@Crabcyborg
Crabcyborg deleted the use_array_key_first_last_functions branch December 30, 2025 15:59
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…ctions

Use array key first/last functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant