Skip to content

Query->count() raises an error if webservice->execute() returns false #33

@alaxos

Description

@alaxos

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions