Query->count() raises an error if webservice->execute() returns false
Closed this issue · 1 comments
alaxos commented
The Query->count()
contains the following line:
return $this->__resultSet->total();
But the Query->_execute()
method assigns directly the result of the webservice request to $this->__resultSet
without checking the returned type:
return $this->__resultSet = $this->_webservice->execute($this);
and according to the doc, the WebserviceInterface->execute()
function may return a ResultSet, but also an integer or a boolean:
@return \Muffin\Webservice\ResultSet|int|bool
Therefore for example if the webservice request fails and returns false
, $this->__resultSet
does not have any total()
method and an error is raised.
A solution could be :
if(method_exists($this->__resultSet, 'total')) {
return $this->__resultSet->total();
} else {
return false;
}
or
if(is_a($this->__resultSet, '\Cake\Datasource\ResultSetInterface')) {
return $this->__resultSet->total();
} else {
return false;
}
ADmad commented
Checking that resultset is instance of \Cake\Datasource\ResultSetInterface
sounds good. Would you like to make a PR for it?