Skip to content

Conversation

@Steveb-p
Copy link
Contributor

🎫 Issue IBX-XXXXX

Description:

For QA:

Documentation:

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@Steveb-p Steveb-p requested a review from Copilot October 14, 2025 10:05
@Steveb-p Steveb-p marked this pull request as ready for review October 14, 2025 10:06
@Steveb-p Steveb-p requested a review from a team October 14, 2025 10:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Purpose: Regenerate and reorganize PHPStan baselines while introducing runtime checks and stricter typing/defensive code around DOM and cURL operations to eliminate previous baseline suppressions.

  • Added runtime validation and safer DOM node handling in DoctrineDatabase gateway.
  • Hardened cURL setup (error checks, non-empty URL assertions) in HTTPHandler and RemoteProvider; introduced new PHPStan baseline version segmentation.
  • Replaced multiple version‐specific baseline files with consolidated gte/lte variant logic and added a new gte-8.1 baseline.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php Added DOM query error handling and safer node removal logic to satisfy static analysis.
src/bundle/Core/URLChecker/Handler/HTTPHandler.php Added defensive checks around cURL initialization and URL validity; adjusted SSL option typing.
src/bundle/Core/Imagine/PlaceholderProvider/RemoteProvider.php Added validations and refactored cURL/file handling for static analysis compliance.
phpstan-baseline.neon.php Reworked inclusion logic for versioned baselines (added gte-8.1 include, removed per-minor explicit includes).
phpstan-baseline.neon Removed obsolete ignoreErrors entries now covered or no longer needed.
phpstan-baseline-gte-8.1.neon New baseline file for PHP ≥ 8.1.
phpstan-baseline-gte-8.0.neon Adjusted ignoreErrors to reflect updated return type guarantees.
phpstan-baseline-8.2.neon Removed legacy baseline file (superseded by new scheme).
phpstan-baseline-8.1.neon Removed legacy baseline file (superseded by new scheme).
phpstan-baseline-8.0.neon Removed legacy baseline file (superseded by new scheme).

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +41 to 62
$handler = \curl_init();
if ($handler === false) {
throw new RuntimeException('Unable to initialize cURL.');
}

$timeout = $options['timeout'];

curl_setopt_array($handler, [
CURLOPT_URL => $placeholderUrl, // non-empty-string
CURLOPT_FILE => $fp, // resource
CURLOPT_TIMEOUT => $timeout, // int
CURLOPT_FAILONERROR => true, // bool
]);

try {
if (curl_exec($handler) === false) {
throw new RuntimeException("Unable to download placeholder for {$value->id} ($placeholderUrl): " . curl_error($handler));
throw new RuntimeException(
"Unable to download placeholder for {$value->id} ({$placeholderUrl}): " . curl_error($handler)
);
}
} finally {
curl_close($handler);
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

Resource leak: if curl_init() fails (line 42 -> 43 throws) the previously opened file handle $fp (line 36) is never closed. Wrap from the fopen() onward in a try/finally (or close $fp immediately before throwing) to ensure fclose($fp) on every exceptional path.

Copilot uses AI. Check for mistakes.
throw new RuntimeException(
"Unable to download placeholder for {$value->id} ({$placeholderUrl}): " . curl_error($handler)
);
}
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

[nitpick] On download failure (lines 56–59) a partially written temp file is left on disk. Consider unlink($path) in the error path (before rethrow) to avoid leaving corrupt placeholders.

Suggested change
}
}
} catch (\Throwable $e) {
// Remove the partially written temp file on error
if (file_exists($path)) {
@unlink($path);
}
throw $e;

Copilot uses AI. Check for mistakes.

foreach ($relationItems as $relationItem) {
$relationItem->parentNode->removeChild($relationItem);
if ($relationItem instanceof DOMElement && $relationItem->parentNode !== null) {
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

[nitpick] The XPath expression selects elements, so each node should already be a DOMElement; the instanceof check adds redundant branching. Removing the instanceof (keeping only a parentNode null check) would simplify the loop without changing behavior.

Suggested change
if ($relationItem instanceof DOMElement && $relationItem->parentNode !== null) {
if ($relationItem->parentNode !== null) {

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +19
if (PHP_VERSION_ID >= 80100) {
$includes[] = __DIR__ . '/phpstan-baseline-gte-8.1.neon';
}

Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Given later conditions also include both gte-* and lte-* files for overlapping version ranges, PHP 8.1.x will load both gte-8.1 and lte-8.1 (and 8.2+ will layer multiple gte baselines). Consider clarifying or deduplicating inclusion order to avoid redundant ignoreErrors merging.

Copilot uses AI. Check for mistakes.
@mikadamczyk mikadamczyk requested a review from alongosz October 14, 2025 11:46
@adamwojs adamwojs merged commit 2a440c3 into 4.6 Oct 14, 2025
23 of 25 checks passed
@adamwojs adamwojs deleted the fixed-phpstan branch October 14, 2025 12:26
@adamwojs
Copy link
Member

You can merge up changes @Steveb-p

@Steveb-p
Copy link
Contributor Author

Merged up into main in 201cda6.

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.

6 participants