Skip to content

Add type check for DataObjectSearchResultItem#1941

Merged
martineiber merged 1 commit into
pimcore:2025.4from
sandeeep-prajapati:2025.4
Jul 7, 2026
Merged

Add type check for DataObjectSearchResultItem#1941
martineiber merged 1 commit into
pimcore:2025.4from
sandeeep-prajapati:2025.4

Conversation

@sandeeep-prajapati

Copy link
Copy Markdown
Contributor

Pull Request Overview

This PR fixes an issue in IconService::getClassIcon() where getClassDefinitionIcon() could be called on objects that do not support the method.

Changes

  • Added an instanceof DataObjectSearchResultItem check before accessing getClassDefinitionIcon().
  • Ensures the icon is only resolved for supported object types.
  • Prevents potential runtime errors caused by calling getClassDefinitionIcon() on unsupported objects.

Before

if ($dataObject->getClassDefinitionIcon() !== null) {

After

if (
    $dataObject instanceof DataObjectSearchResultItem &&
    $dataObject->getClassDefinitionIcon() !== null
) {

Why?

getClassIcon() may receive different object types, but getClassDefinitionIcon() is only available on DataObjectSearchResultItem. This guard ensures the method is invoked only when supported, making the service more robust and preventing unexpected errors.

@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@martineiber martineiber requested a review from Copilot July 7, 2026 05:01
@martineiber martineiber added this to the 2025.4.7 milestone Jul 7, 2026
@martineiber martineiber self-assigned this Jul 7, 2026
@martineiber martineiber added the Bug label Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens IconService::getClassIcon() by guarding the call to getClassDefinitionIcon() with an instanceof DataObjectSearchResultItem check. Since getClassIcon() accepts a DataObjectSearchResultItem|DataObject union, and getClassDefinitionIcon() is only defined on DataObjectSearchResultItem, invoking it on a plain DataObject (e.g. a Concrete object or folder that falls through the first branch) would trigger a runtime error. The short-circuiting && ensures the method is only reached for supported types, which is a correct and well-targeted fix that preserves existing behavior for search-result items.

Changes:

  • Added an instanceof DataObjectSearchResultItem guard before accessing getClassDefinitionIcon() in getClassIcon().

@martineiber martineiber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@martineiber martineiber merged commit 994d546 into pimcore:2025.4 Jul 7, 2026
13 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants