Skip to content

[BUGFIX] TS settings may be empty#127

Merged
maikschneider merged 1 commit into
maikschneider:mainfrom
b13:bugfix/ts
Jun 1, 2026
Merged

[BUGFIX] TS settings may be empty#127
maikschneider merged 1 commit into
maikschneider:mainfrom
b13:bugfix/ts

Conversation

@achimfritz

@achimfritz achimfritz commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

e.g. when class is called in BE-Context

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced CAPTCHA form element to robustly handle missing configuration settings, preventing potential errors and improving overall system reliability during form initialization.

e.g. when class is called in BE-Context
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CaptchaElement::initializeFormElement() now defensively retrieves TypoScript settings using null-coalescing lookup instead of unconditional array indexing. The method returns early when the settings block is missing, preventing undefined-index errors before showRefresh and showAudio properties are assigned.

Changes

Settings Safety

Layer / File(s) Summary
Defensive TypoScript settings lookup
Classes/Domain/Model/FormElements/CaptchaElement.php
TypoScript settings retrieval uses null-coalescing and early return; prevents undefined-index errors when settings block is absent from resolved configuration.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A null-safe leap through TypoScript's way,
No more undefined indices fray,
Defensive checks dance with graceful care,
Settings retrieved with safety to spare! 🌿✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding defensive null-coalescing lookup for potentially empty TypoScript settings.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Classes/Domain/Model/FormElements/CaptchaElement.php`:
- Around line 33-38: The current assignment uses direct offsets on $settings
which can emit undefined-key warnings and drop defaults; update the logic in the
CaptchaElement code that sets showRefresh and showAudio to read each key with a
per-key fallback (e.g., use isset() or null coalescing on
$settings['refreshButton'] and $settings['audioButton']) and default them to
true when the keys are missing or null before calling
$this->setProperty('showRefresh', ...) and $this->setProperty('showAudio', ...).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8e405c5-8c31-4d75-8643-970a26d13715

📥 Commits

Reviewing files that changed from the base of the PR and between 8a49276 and 02234a4.

📒 Files selected for processing (1)
  • Classes/Domain/Model/FormElements/CaptchaElement.php

Comment on lines +33 to 38
$settings = $ts['plugin.']['tx_bwcaptcha.']['settings.'] ?? null;
if ($settings === null) {
return;
}
$this->setProperty('showRefresh', (bool)$settings['refreshButton']);
$this->setProperty('showAudio', (bool)$settings['audioButton']);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve default button behavior when settings are partially missing.

Line 37 and Line 38 still use direct offsets, so a present-but-partial settings. array can trigger undefined-key warnings and silently drop defaults (refreshButton / audioButton should default to enabled). Use per-key fallbacks during assignment.

Suggested fix
-        $settings = $ts['plugin.']['tx_bwcaptcha.']['settings.'] ?? null;
-        if ($settings === null) {
-            return;
-        }
-        $this->setProperty('showRefresh', (bool)$settings['refreshButton']);
-        $this->setProperty('showAudio', (bool)$settings['audioButton']);
+        $settings = $ts['plugin.']['tx_bwcaptcha.']['settings.'] ?? [];
+        $this->setProperty('showRefresh', (bool)($settings['refreshButton'] ?? true));
+        $this->setProperty('showAudio', (bool)($settings['audioButton'] ?? true));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$settings = $ts['plugin.']['tx_bwcaptcha.']['settings.'] ?? null;
if ($settings === null) {
return;
}
$this->setProperty('showRefresh', (bool)$settings['refreshButton']);
$this->setProperty('showAudio', (bool)$settings['audioButton']);
$settings = $ts['plugin.']['tx_bwcaptcha.']['settings.'] ?? [];
$this->setProperty('showRefresh', (bool)($settings['refreshButton'] ?? true));
$this->setProperty('showAudio', (bool)($settings['audioButton'] ?? true));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Classes/Domain/Model/FormElements/CaptchaElement.php` around lines 33 - 38,
The current assignment uses direct offsets on $settings which can emit
undefined-key warnings and drop defaults; update the logic in the CaptchaElement
code that sets showRefresh and showAudio to read each key with a per-key
fallback (e.g., use isset() or null coalescing on $settings['refreshButton'] and
$settings['audioButton']) and default them to true when the keys are missing or
null before calling $this->setProperty('showRefresh', ...) and
$this->setProperty('showAudio', ...).

@maikschneider maikschneider merged commit f5247ba into maikschneider:main Jun 1, 2026
3 of 4 checks passed
@maikschneider

Copy link
Copy Markdown
Owner

Hey @achimfritz, thanks!

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