Skip to content

Fix conditional checks for meta and link tags#15

Merged
LukeTowers merged 1 commit intowintercms:mainfrom
Quendi6:patch-1
Dec 4, 2025
Merged

Fix conditional checks for meta and link tags#15
LukeTowers merged 1 commit intowintercms:mainfrom
Quendi6:patch-1

Conversation

@Quendi6
Copy link
Copy Markdown
Contributor

@Quendi6 Quendi6 commented Nov 20, 2025

If the meta_tags or link_tags keys do not exist, an empty array will be returned by default. However, if a null value is stored, the following foreach loop will generate an error.

Bonus: inside the following two foreach loops, the parentheses were not correctly placed, I have fixed it.

This fix is ​​necessary because, without it, it is impossible to save plugin settings without adding at least one meta tag AND one link tag, which is not always what we want to do.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed conditional logic for meta tag and link tag validation to correctly identify missing values
    • Improved default handling for meta and link tag settings

✏️ Tip: You can customize this high-level summary in your review settings.

If the meta_tags or link_tags keys do not exist, an empty array will be returned by default. However, if a null value is stored, the following foreach loop will generate an error.

Bonus: inside the following two foreach loops, the parentheses were not correctly placed, I have fixed it.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 20, 2025

Walkthrough

Plugin.php is refactored to fix operator precedence bugs in conditional checks for meta and link tags iteration, and default fallback patterns are standardized using Elvis coalescing to empty arrays for safer defaults.

Changes

Cohort / File(s) Change Summary
Bug fix: Conditional operator precedence
Plugin.php
Fixed logical condition in metaTags iteration from empty($data['name'] || empty($data['value'])) to empty($data['name']) || empty($data['value']) to correctly evaluate both fields. Applied identical fix to linkTags iteration for rel and href fields.
Refactor: Default fallback patterns
Plugin.php
Replaced Settings::get() with Elvis coalescing fallback patterns (?: []) for meta_tags and link_tags to provide consistent empty array defaults.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Specific areas requiring attention:
    • Verify the operator precedence fix correctly evaluates both conditions (the original logic may have inadvertently grouped the OR operator with the first empty() call)
    • Confirm Elvis coalescing behavior aligns with previous Settings::get() default handling across both meta_tags and link_tags assignments

Poem

🐰 A rabbit hops through logic's maze,
Where operators daze in operator's haze,
Empty checks now grouped just right,
Elvis coalesces with pure delight!
Safer defaults, cleaner code,
Hop hop hop down correction's road!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix conditional checks for meta and link tags' directly and clearly summarizes the main changes in the pull request, which involve fixing conditional logic for meta_tags and link_tags iteration.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89b5c62 and 32d54f9.

📒 Files selected for processing (1)
  • Plugin.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Plugin.php (2)
models/Settings.php (1)
  • Settings (9-55)
classes/TagContainer.php (1)
  • get (45-48)
🔇 Additional comments (3)
Plugin.php (3)

249-250: LGTM! Null-safe defaults prevent foreach errors.

The Elvis operator correctly handles the case where null is explicitly stored in settings, ensuring the foreach loops receive an array rather than null.


253-253: Critical fix: Corrected operator precedence in validation logic.

The previous logic empty($data['name'] || empty($data['value'])) incorrectly evaluated the inner boolean expression first, then checked if that result was empty, leading to inverted/unpredictable behavior. The corrected logic properly validates that both fields are non-empty before processing.


262-262: Critical fix: Corrected operator precedence in validation logic.

Same issue as Line 253 - the previous logic empty($data['rel'] || empty($data['href'])) had incorrect operator precedence. The fix ensures both fields are properly validated before processing link tags.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

@LukeTowers LukeTowers merged commit e882679 into wintercms:main Dec 4, 2025
5 checks passed
@LukeTowers
Copy link
Copy Markdown
Member

Thanks for the PR @Quendi6, apologies for the delay; I missed this in my notifications.

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.

2 participants