Skip to content

Comments

Update Driver.php#30

Open
TDannhauer wants to merge 1 commit intoFRAMEWORK_6_0from
TDannhauer-patch-ActiveSyncDriver1
Open

Update Driver.php#30
TDannhauer wants to merge 1 commit intoFRAMEWORK_6_0from
TDannhauer-patch-ActiveSyncDriver1

Conversation

@TDannhauer
Copy link
Contributor

Handles access to Collections properties more defensive as they are optional according Protocol (..stated the internet... ;) )

Handles access to Collections properties more defensive as they are optional according Protocol (..stated the internet... ;)  )
@TDannhauer TDannhauer requested a review from Copilot January 14, 2026 10:41
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

This PR adds defensive checks for optional properties in the $collection array when accessing bodyprefs and mimesupport fields. The changes prevent potential undefined index errors by using !empty() checks with appropriate default values.

Changes:

  • Added !empty() checks for bodyprefs and mimesupport collection properties across calendar, contacts, tasks, notes, and mail export functions
  • Standardized truncation handling for tasks and notes to match the pattern used in calendar and contacts
  • Updated error logging to include the same defensive checks for consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TDannhauer
Copy link
Contributor Author

@amulet1 : can you review this PR? Does it make sense?

@amulet1
Copy link
Contributor

amulet1 commented Feb 20, 2026

I am not a fan of empty() after I discovered that it considers string '0' (or number 0) to be empty.

This can potentially cause serious issues (maybe not in this particular case though).

I think the idea here is to suppress warnings if some of the parameters were not defined by replacing them with default values. If so, I think isset() is a better option to use than empty().

(1) 'bodyprefs' => !empty($collection['bodyprefs']) ? $collection['bodyprefs'] : []
can then be written as
(2) 'bodyprefs' => isset($collection['bodyprefs']) ? $collection['bodyprefs'] : []

The difference is that (1) would convert '0' (or 0 or empty string) to empty array. In general case this is probably undesired. (2) would leave them intact and only use empty array for undefined values or null values, which looks more reasonable.

There is an even cleaner way. Use null coalescing operator and it becomes this:
(3) 'bodyprefs' => $collection['bodyprefs']) ?? []

I think (3) is what we should use going forward as a preferred way to fix potential issues with undefined variables.

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