Skip to content

Commit

Permalink
Deprecate “smart” getters and setters
Browse files Browse the repository at this point in the history
  • Loading branch information
stratedge committed Feb 4, 2018
1 parent 3d589fb commit ea0c554
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 63 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- No pending changes
### Changed
- Deprecated smart getters and setters

## [0.7.0] - 2018-02-03
### Added
Expand Down
10 changes: 5 additions & 5 deletions src/PDO/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public function exec($query)
*/
public function lastInsertId($name = null)
{
return $this->wye()
return $this->getWye()
->getLastStatement()
->result()
->lastInsertId();
->getResult()
->getLastInsertId();
}


Expand All @@ -112,7 +112,7 @@ public function lastInsertId($name = null)
*/
public function prepare($statement, $options = null)
{
return $this->wye()->makeStatement($statement, $options);
return $this->getWye()->makeStatement($statement, $options);
}


Expand All @@ -136,7 +136,7 @@ public function quote($string, $paramtype = null)
);
}

return $this->wye()->quote($string);
return $this->getWye()->quote($string);
}

/**
Expand Down
41 changes: 33 additions & 8 deletions src/PDO/PDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class PDOStatement extends BasePDOStatement
*/
public function __construct(Wye $wye, $statement, $options)
{
$this->wye($wye);
$this->statement($statement);
$this->options($options);
$this->setWye($wye);
$this->setStatement($statement);
$this->setOptions($options);

$this->bindings = $this->wye->makeBindingCollection();
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
*/
public function execute($params = null)
{
$this->wye()->executeStatement($this, $params);
$this->getWye()->executeStatement($this, $params);
return true;
}

Expand All @@ -140,14 +140,14 @@ public function execute($params = null)
public function fetch($how = null, $orientation = null, $offset = null)
{
if (is_null($how)) {
$defaults = $this->fetchMode();
$defaults = $this->getFetchMode();

$how = $defaults[0];
$orientation = !empty($defaults[1]) ? $defaults[1] : null;
$offset = !empty($defaults[2]) ? $defaults[2] : null;
}

return $this->result()->fetch($how, $orientation, $offset);
return $this->getResult()->fetch($how, $orientation, $offset);
}


Expand All @@ -163,14 +163,14 @@ public function fetch($how = null, $orientation = null, $offset = null)
public function fetchAll($how = null, $class_name = null, $ctor_args = null)
{
if (is_null($how)) {
$defaults = $this->fetchMode();
$defaults = $this->getFetchMode();

$how = $defaults[0];
$class_name = !empty($defaults[1]) ? $defaults[1] : null;
$ctor_args = !empty($defaults[2]) ? $defaults[2] : null;
}

return $this->result()->fetchAll($how, $class_name, $ctor_args);
return $this->getResult()->fetchAll($how, $class_name, $ctor_args);
}


Expand Down Expand Up @@ -279,8 +279,13 @@ public function setBindings(BindingCollectionInterface $bindings)
// STATEMENT
//**************************************************************************

/**
* @deprecated
*/
public function statement($statement = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($statement)) {
return $this->getStatement();
} else {
Expand All @@ -305,8 +310,13 @@ public function setStatement($statement)
// OPTIONS
//**************************************************************************

/**
* @deprecated
*/
public function options($options = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($options)) {
return $this->getOptions();
} else {
Expand All @@ -331,8 +341,13 @@ public function setOptions($options)
// RESULT
//**************************************************************************

/**
* @deprecated
*/
public function result($result = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($result)) {
return $this->getResult();
} else {
Expand All @@ -357,8 +372,13 @@ public function setResult(Result $result)
// FETCH_MODE
//**************************************************************************

/**
* @deprecated
*/
public function fetchMode(array $fetch_mode = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($fetch_mode)) {
return $this->getFetchMode();
} else {
Expand All @@ -376,8 +396,13 @@ public function getFetchMode()
// TRANSACTION
//**************************************************************************

/**
* @deprecated
*/
public function transaction(Transaction $transaction = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($transaction)) {
return $this->getTransaction();
} else {
Expand Down
29 changes: 22 additions & 7 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Result
*/
public function __construct(Wye $wye)
{
$this->wye($wye);
$this->setWye($wye);
}


Expand All @@ -67,7 +67,7 @@ public function __construct(Wye $wye)
*/
public function fetch($how, $orientation, $offset)
{
$rows = $this->rows();
$rows = $this->getRows();

if (!isset($rows[$this->current_index])) {
return false;
Expand All @@ -94,7 +94,7 @@ public function fetchAll($how, $class_name, $ctor_args)
{
$result = [];

foreach ($this->rows() as $row) {
foreach ($this->getRows() as $row) {
$result[] = $row->format($how, $class_name, $ctor_args);
}

Expand All @@ -107,8 +107,13 @@ public function fetchAll($how, $class_name, $ctor_args)
// COLUMNS
//**************************************************************************

/**
* @deprecated
*/
public function columns($columns = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($columns)) {
return $this->getColumns();
} else {
Expand Down Expand Up @@ -143,22 +148,27 @@ public function hasColumns()

public function getColumnAtIndex($index = 0)
{
$columns = $this->columns();
$columns = $this->getColumns();
return isset($columns[$index]) ? $columns[$index] : null;
}

public function countColumns()
{
return count($this->columns());
return count($this->getColumns());
}


//**************************************************************************
// LAST INSERT ID
//**************************************************************************

/**
* @deprecated
*/
public function lastInsertId($id = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($id)) {
return $this->getLastInsertId();
} else {
Expand Down Expand Up @@ -216,8 +226,13 @@ public function setNumRows($num_rows)
// ROWS
//**************************************************************************

/**
* @deprecated
*/
public function rows($rows = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($rows)) {
return $this->getRows();
} else {
Expand Down Expand Up @@ -256,7 +271,7 @@ public function addRow($row)
}
}

$row = $this->wye()->makeRow($row);
$row = $this->getWye()->makeRow($row);
}

$this->rows[] = $row;
Expand Down Expand Up @@ -284,7 +299,7 @@ public function addRows(array $rows)
*/
public function attach()
{
$this->wye()->addResult($this);
$this->getWye()->addResult($this);
return $this;
}

Expand Down
17 changes: 11 additions & 6 deletions src/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Row
*/
public function __construct(Wye $wye, array $data = null)
{
$this->wye($wye);
$this->setWye($wye);

if (!is_null($data)) {
$this->data($data);
$this->setData($data);
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function format($how, $class_name = "stdClass", $ctor_args = [])
*/
protected function formatAssoc()
{
return $this->data();
return $this->getData();
}


Expand All @@ -98,7 +98,7 @@ protected function formatBoth()
$data = [];
$index = 0;

foreach ($this->data() as $key => $value) {
foreach ($this->getData() as $key => $value) {
$data[$key] = $value;
$data[$index] = $value;
$index++;
Expand All @@ -121,7 +121,7 @@ protected function formatClass($class_name, $ctor_args)
$r = new ReflectionClass($class_name);
$data = $r->newInstanceArgs((array) $ctor_args);

foreach ($this->data() as $key => $value) {
foreach ($this->getData() as $key => $value) {
$data->$key = $value;
}

Expand All @@ -136,16 +136,21 @@ protected function formatClass($class_name, $ctor_args)
*/
protected function formatObj()
{
return (object) $this->data();
return (object) $this->getData();
}


//**************************************************************************
// DATA
//**************************************************************************

/**
* @deprecated
*/
public function data(array $data = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($data)) {
return $this->getData();
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/Traits/UsesWye.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ trait UsesWye
// WYE
//**************************************************************************

/**
* @deprecated
*/
public function wye(Wye $wye = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($wye)) {
return $this->getWye();
} else {
Expand Down
17 changes: 16 additions & 1 deletion src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ public function __construct($index = null)
// INDEX
//**************************************************************************

/**
* @deprecated
*/
public function index($index = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($index)) {
return $this->getIndex();
} else {
Expand All @@ -64,8 +69,13 @@ public function setIndex($index)
// COMMITTED
//**************************************************************************

/**
* @deprecated
*/
public function committed($committed = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($committed)) {
return $this->getCommitted();
} else {
Expand Down Expand Up @@ -114,8 +124,13 @@ public function setRolledBack($rolled_back)
// STATEMENTS
//**************************************************************************

/**
* @deprecated
*/
public function statements(array $statements = null)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED);

if (is_null($statements)) {
return $this->getStatements();
} else {
Expand All @@ -136,7 +151,7 @@ public function setStatements(array $statements)
public function addStatement(PDOStatement $statement)
{
//Add this transation to the statement
$statement->transaction($this);
$statement->setTransaction($this);

$this->statements[] = $statement;
}
Expand Down
Loading

0 comments on commit ea0c554

Please sign in to comment.