PHP Warnings with getList
tsukasa-sama opened this issue · 2 comments
Describe the bug
Using the OData client, having a single select will throw PHP warnings:
Warning: count(): Parameter must be an array or an object that implements Countable ...
Warning: implode(): Invalid arguments passed in ...
To Reproduce
The query I am able to reproduce this on is:
$status = $odataClient->getList("EntityDefinitions(LogicalName='incident')/Attributes/Microsoft.Dynamics.CRM.StatusAttributeMetadata", [
'Select' => 'LogicalName',
'Filter' => "LogicalName eq 'statuscode'",
'Expand' => 'OptionSet'
] );
Expected behavior
Should convert the input to array or enforce array as the required type.
Additional context
The error is in the buildQueryURL method with $queryOptions. The code says it accepts an array but the higher level calls do not enforce this, see the getList method where it's $queryOptions does not have a type specified.
Looking at it some more, that may not work since it's a two dimensional array. I think each of the statements like
if ( isset( $queryOptions['Select'] ) && count( $queryOptions['Select'] ) )
should be
if ( isset( $queryOptions['Select'] ) ) {
if (is_array( $queryOptions['Select'] ) && count( $queryOptions['Select'] ) ) {
$queryParameters['$select'] = implode( ',', $queryOptions['Select'] );
} else {
$queryParameters['$select'] = $queryOptions['Select'];
}
}