Skip to content

Commit

Permalink
Simplify BufferedStatement
Browse files Browse the repository at this point in the history
Don't implement methods that can be simple proxies. Add a typehint to
the constructor to catch improper decorator usage earlier.
  • Loading branch information
markstory committed May 29, 2018
1 parent 98f5419 commit 043df24
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions src/Database/Statement/BufferedStatement.php
Expand Up @@ -38,7 +38,7 @@ class BufferedStatement implements Iterator, StatementInterface
/**
* The decorated statement
*
* @var \Cake\Database\StatementInterface|\PDOStatement
* @var \Cake\Database\StatementInterface
*/
protected $statement;

Expand Down Expand Up @@ -76,7 +76,7 @@ class BufferedStatement implements Iterator, StatementInterface
* @param \Cake\Database\StatementInterface $statement Statement implementation such as PDOStatement
* @param \Cake\Database\Driver $driver Driver instance
*/
public function __construct($statement, $driver)
public function __construct(StatementInterface $statement, $driver)
{
$this->statement = $statement;
$this->_driver = $driver;
Expand Down Expand Up @@ -175,38 +175,15 @@ public function count()
*/
public function bind($params, $types)
{
if (empty($params)) {
return;
}

$anonymousParams = is_int(key($params)) ? true : false;
$offset = 1;
foreach ($params as $index => $value) {
$type = null;
if (isset($types[$index])) {
$type = $types[$index];
}
if ($anonymousParams) {
$index += $offset;
}
$this->bindValue($index, $value, $type);
}
$this->statement->bind($params, $types);
}

/**
* {@inheritDoc}
*/
public function lastInsertId($table = null, $column = null)
{
$row = null;
if ($column && $this->columnCount()) {
$row = $this->fetch(static::FETCH_TYPE_ASSOC);
}
if (isset($row[$column])) {
return $row[$column];
}

return $this->_driver->lastInsertId($table, $column);
return $this->_statement->lastInsertId($table, $column);
}

/**
Expand Down

0 comments on commit 043df24

Please sign in to comment.