Skip to content

Analyser false positive possible-method-access-on-null #836

@djschilling

Description

@djschilling

Description

I have this Code snippet:

return [
    'name' => t($field->getName(), true),
    'format' => $field->getFieldType()
        ? DBFieldExportMapping::MAPPING[$field->getFieldType()->getInternCode()]
        : ExportGenerator::FORMAT_TEXT,
];

This results in this error:

error[possible-method-access-on-null]: Attempting to call a method on `null`.
   ┌─ system/src/Domain/Group/Export/GroupExportDataProvider.php:68:53
   │
68 │                     ? DBFieldExportMapping::MAPPING[$field->getFieldType()->getInternCode()]
   │                                                     ^^^^^^^^^^^^^^^^^^^^^^ This expression can be `null`
   │
   = Help: Use the nullsafe operator (`?->`) if `null` is an expected value.

$field->getFieldType() cannot be null because of the check before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugAn issue causing unintended or problematic behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions