Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#2182] Minor logic cleanup
Browse files Browse the repository at this point in the history
- Return early, and don't put the work of a method within a conditional
- Typehints in docblocks resolve based on current namespace and imports
  • Loading branch information
weierophinney committed Aug 17, 2012
1 parent ef94e97 commit b273434
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/Adapter/DbSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DbSelect implements AdapterInterface
/**
* Database query
*
* @var \Zend\Db\Sql\Select
* @var Select
*/
protected $select = null;

Expand All @@ -51,7 +51,9 @@ class DbSelect implements AdapterInterface
/**
* Constructor.
*
* @param \Zend\Db\Sql\Select $select The select query
* @param Select $select The select query
* @param Adapter|Sql $adapterOrSqlObject DB adapter or Sql object
* @param null|ResultSetInterface $resultSetPrototype
*/
public function __construct(Select $select, $adapterOrSqlObject, ResultSetInterface $resultSetPrototype = null)
{
Expand All @@ -67,7 +69,7 @@ public function __construct(Select $select, $adapterOrSqlObject, ResultSetInterf
);
}

$this->sql = $adapterOrSqlObject;
$this->sql = $adapterOrSqlObject;
$this->resultSetPrototype = ($resultSetPrototype) ?: new ResultSet;
}

Expand All @@ -85,7 +87,7 @@ public function getItems($offset, $itemCountPerPage)
$select->limit($itemCountPerPage);

$statement = $this->sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$result = $statement->execute();

$resultSet = clone $this->resultSetPrototype;
$resultSet->initialize($result);
Expand All @@ -100,22 +102,23 @@ public function getItems($offset, $itemCountPerPage)
*/
public function count()
{
if ($this->rowCount === null) {
$select = clone $this->select;
$select->reset(Select::COLUMNS);
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);
if ($this->rowCount !== null) {
return $this->rowCount;
}

$select->columns(array('c' => new Expression('COUNT(1)')));
$select = clone $this->select;
$select->reset(Select::COLUMNS);
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);

$statement = $this->sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$row = $result->current();
$select->columns(array('c' => new Expression('COUNT(1)')));

$this->rowCount = $row['c'];
}
$statement = $this->sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$row = $result->current();

$this->rowCount = $row['c'];

return $this->rowCount;
}

}

0 comments on commit b273434

Please sign in to comment.