Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ public function count()
$this->_execute();
}

return $this->__resultSet->total();
if(is_a($this->__resultSet, '\Cake\Datasource\ResultSetInterface')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space needed after if. Use instanceof instead of is_a().

return $this->__resultSet->total();
} else {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this should return 0 and not false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the count() method is supposed to return integer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning 0 if something wrong happens during the query execution would let think it really did return 0 items. Is it something that we really want ? If the execute() method can return false, couldn't the count() method do the same ?

Copy link
Collaborator

@davidyell davidyell Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A count method implies a numerical return to me, I'd be confused if I asked for a count, expecting a integer and got a boolean.

The count method should not care if the query executed successfully or not, it's not it's responsibility. Remember the S in SOLID.

Copy link
Member

@ADmad ADmad Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alaxos When "something wrong happens" an exception should be thrown :)

}
}

/**
Expand Down