8000 Block, Menu, Date traits pipefail by nsineok · Pull Request #421 · drevops/behat-steps · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Block, Menu, Date traits pipefail #421

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

Merged
merged 1 commit into from
May 29, 2025
Merged

Block, Menu, Date traits pipefail #421

merged 1 commit into from
May 29, 2025

Conversation

nsineok
Copy link
Contributor
@nsineok nsineok commented May 29, 2025

Reference: link

 ------ ----------------------------------------------------------------------- 
  Line   src/DateTrait.php (in context of class                                 
         DrevOps\BehatSteps\Tests\DateTraitTestImplementation)                  
 ------ ----------------------------------------------------------------------- 
  59     Parameter #1 $table of class Behat\Gherkin\Node\TableNode constructor  
         expects array<int, list<string>>, list<array<int<0, max>, string>>     
         given.                                                                 
         🪪 argument.type                                                       
         💡 array<int<0, max>, string> might not be a list.                     
 ------ ----------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   src/DateTrait.php (in context of class FeatureContext)                 
 ------ ----------------------------------------------------------------------- 
  59     Parameter #1 $table of class Behat\Gherkin\Node\TableNode constructor  
         expects array<int, list<string>>, list<array<int<0, max>, string>>     
         given.                                                                 
         🪪 argument.type                                                       
         💡 array<int<0, max>, string> might not be a list.                     
 ------ ----------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   src/Drupal/BlockTrait.php (in context of class FeatureContext)         
 ------ ----------------------------------------------------------------------- 
  144    Parameter #1 $region of method Drupal\block\Entity\Block::setRegion()  
         expects string, list<string>|string given.                             
         🪪 argument.type                                                       
 ------ ----------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------- 
  Line   src/Drupal/MenuTrait.php (in context of class FeatureContext)        
 ------ --------------------------------------------------------------------- 
  139    Cannot access offset 'uri' on int|string.                            
         🪪 offsetAccess.nonOffsetAccessible                                  
  143    Parameter #1 $title of method FeatureContext::loadMenuLinkByTitle()  
         expects string, array<string, int|string|null>|int<min, -1>|int<1,   
         max>|string given.                                                   
         🪪 argument.type                                                     
 ------ --------------------------------------------------------------------- 

 [ERROR] Found 5 errors     

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and validation when configuring block regions, ensuring only valid string values are accepted.
    • Enhanced robustness in menu link creation by adding checks for optional or malformed input data, preventing errors with missing or invalid fields.
  • Refactor
    • Updated internal data handling for date transformation to use indexed arrays, streamlining row processing.

Copy link
coderabbitai bot commented May 29, 2025

Walkthrough

Type checks and error handling were added to methods in BlockTrait and MenuTrait to ensure input data is validated before processing. The iteration logic in DateTrait was updated to produce indexed arrays instead of associative arrays. No public method signatures were changed.

Changes

File(s) Change Summary
src/DateTrait.php Changed table row iteration in dateRelativeTransformTable to produce indexed arrays instead of associative.
src/Drupal/BlockTrait.php Added type check and exception for 'region' field in blockConfigure method.
src/Drupal/MenuTrait.php Improved type safety and conditional checks for link and parent in menuLinksCreate method.

Poem

🐇
I checked your types and watched your keys,
With careful hops through PHP trees.
No region wrong, no parent lost,
Each menu link now double-crossed.
Arrays in rows, exceptions thrown—
A safer code, a happy home!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f2fa7b and b472b09.

📒 Files selected for processing (3)
  • src/DateTrait.php (1 hunks)
  • src/Drupal/BlockTrait.php (1 hunks)
  • src/Drupal/MenuTrait.php (1 hunks)
🔇 Additional comments (4)
src/DateTrait.php (1)

53-54:

✅ Verification successful

Good fix for TableNode type compatibility.

The change from associative to indexed arrays correctly addresses the type mismatch where TableNode constructor expects array<int, list<string>>. However, this is a behavioral change that loses the original column keys.

Verify that downstream code doesn't rely on column keys from transformed tables:


🏁 Script executed:

#!/bin/bash
# Description: Search for code that might access transformed table data by column keys
# Expected: Find usages that might be affected by the loss of column keys

# Search for table transformation usage
rg -A 10 -B 5 "dateRelativeTransformTable|Transform table"

# Search for potential column key access patterns  
rg -A 5 "getRowsHash|getHash" --type php

Length of output: 6981


No loss of header keys; numeric indices only

The dateRelativeTransformTable() method operates on $table->getRows(), which returns a list-of-lists with numeric indices. Switching from

foreach ($hash as $key => $cell) {
  $row[$key] = ...
}

to

foreach ($hash as $cell) {
  $row[] = ...
}

preserves the order and values exactly, and there are no string-keyed columns involved. This safely fixes the TableNode type mismatch without changing behavior. Approved.

src/Drupal/BlockTrait.php (1)

144-149: Excellent type safety improvement.

The added type checking for the 'region' field correctly addresses the type mismatch issue. The implementation properly validates that the value is a string before calling setRegion(), and provides a clear error message for invalid types.

src/Drupal/MenuTrait.php (2)

139-143: Robust URI handling improvement.

The added isset() check prevents accessing undefined 'uri' offset and explicitly initializes the 'link' array. This fixes the type error where 'uri' offset was being accessed on int|string variables.


145-145: Excellent parent validation logic.

The enhanced parent property handling correctly validates that the parent is a non-empty string and the parent link exists as a MenuLinkContent instance before setting the parent UUID format. Invalid parent values are properly unset, preventing type mismatches in loadMenuLinkByTitle().

Also applies to: 147-152

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.34%. Comparing base (9f2fa7b) to head (b472b09).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/Drupal/BlockTrait.php 66.66% 1 Missing ⚠️
src/Drupal/MenuTrait.php 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
- Coverage   80.38%   80.34%   -0.05%     
==========================================
  Files          29       29              
  Lines        2004     2010       +6     
==========================================
+ Hits         1611     1615       +4     
- Misses        393      395       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nsineok nsineok requested a review from AlexSkrypnyk May 29, 2025 08:22
@nsineok nsineok added the PR: Needs review Pull request needs a review from assigned developers label May 29, 2025
@AlexSkrypnyk AlexSkrypnyk merged commit e27cb24 into main May 29, 2025
6 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the fix/traits-pipefail branch May 29, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Needs review Pull request needs a review from assigned developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0