Skip to content

Commit

Permalink
Using static variables instead of instances properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
renan committed Dec 22, 2013
1 parent 9dca6b1 commit cbf8a02
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions Cake/Database/Schema/Table.php
Expand Up @@ -72,7 +72,7 @@ class Table {
*
* @var array
*/
protected $_columnKeys = [
protected static $_columnKeys = [
'type' => null,
'length' => null,
'precision' => null,
Expand All @@ -86,7 +86,7 @@ class Table {
*
* @var array
*/
protected $_columnExtras = [
protected static $_columnExtras = [
'string' => [
'fixed' => null,
],
Expand All @@ -110,7 +110,7 @@ class Table {
*
* @var array
*/
protected $_indexKeys = [
protected static $_indexKeys = [
'type' => null,
'columns' => [],
'length' => [],
Expand All @@ -124,7 +124,7 @@ class Table {
*
* @var array
*/
protected $_validIndexTypes = [
protected static $_validIndexTypes = [
self::INDEX_INDEX,
self::INDEX_FULLTEXT,
];
Expand All @@ -134,7 +134,7 @@ class Table {
*
* @var array
*/
protected $_validConstraintTypes = [
protected static $_validConstraintTypes = [
self::CONSTRAINT_PRIMARY,
self::CONSTRAINT_UNIQUE,
self::CONSTRAINT_FOREIGN,
Expand All @@ -145,7 +145,7 @@ class Table {
*
* @var array
*/
protected $_validForeignKeyActions = [
protected static $_validForeignKeyActions = [
self::ACTION_CASCADE,
self::ACTION_SET_NULL,
self::ACTION_NO_ACTION,
Expand Down Expand Up @@ -218,9 +218,9 @@ public function addColumn($name, $attrs) {
if (is_string($attrs)) {
$attrs = ['type' => $attrs];
}
$valid = $this->_columnKeys;
if (isset($this->_columnExtras[$attrs['type']])) {
$valid += $this->_columnExtras[$attrs['type']];
$valid = static::$_columnKeys;
if (isset(static::$_columnExtras[$attrs['type']])) {
$valid += static::$_columnExtras[$attrs['type']];
}
$attrs = array_intersect_key($attrs, $valid);
$this->_columns[$name] = $attrs + $valid;
Expand Down Expand Up @@ -282,11 +282,11 @@ public function addIndex($name, $attrs) {
if (is_string($attrs)) {
$attrs = ['type' => $attrs];
}
$attrs = array_intersect_key($attrs, $this->_indexKeys);
$attrs = $attrs + $this->_indexKeys;
$attrs = array_intersect_key($attrs, static::$_indexKeys);
$attrs = $attrs + static::$_indexKeys;
unset($attrs['references'], $attrs['update'], $attrs['delete']);

if (!in_array($attrs['type'], $this->_validIndexTypes, true)) {
if (!in_array($attrs['type'], static::$_validIndexTypes, true)) {
throw new Exception(__d('cake_dev', 'Invalid index type "%s"', $attrs['type']));
}
if (empty($attrs['columns'])) {
Expand Down Expand Up @@ -332,7 +332,7 @@ public function index($name) {
*/
public function primaryKey() {
foreach ($this->_constraints as $name => $data) {
if ($data['type'] === self::CONSTRAINT_PRIMARY) {
if ($data['type'] === static::CONSTRAINT_PRIMARY) {
return $data['columns'];
}
}
Expand Down Expand Up @@ -364,9 +364,9 @@ public function addConstraint($name, $attrs) {
if (is_string($attrs)) {
$attrs = ['type' => $attrs];
}
$attrs = array_intersect_key($attrs, $this->_indexKeys);
$attrs = $attrs + $this->_indexKeys;
if (!in_array($attrs['type'], $this->_validConstraintTypes, true)) {
$attrs = array_intersect_key($attrs, static::$_indexKeys);
$attrs = $attrs + static::$_indexKeys;
if (!in_array($attrs['type'], static::$_validConstraintTypes, true)) {
throw new Exception(__d('cake_dev', 'Invalid constraint type "%s"', $attrs['type']));
}
if (empty($attrs['columns'])) {
Expand Down Expand Up @@ -398,11 +398,11 @@ protected function _checkForeignKey($attrs) {
if (count($attrs['references']) < 2) {
throw new Exception(__d('cake_dev', 'References must contain a table and column.'));
}
if (!in_array($attrs['update'], $this->_validForeignKeyActions)) {
throw new Exception(__d('cake_dev', 'Update action is invalid. Must be one of %s', implode(',', $this->_validForeignKeyActions)));
if (!in_array($attrs['update'], static::$_validForeignKeyActions)) {
throw new Exception(__d('cake_dev', 'Update action is invalid. Must be one of %s', implode(',', static::$_validForeignKeyActions)));
}
if (!in_array($attrs['delete'], $this->_validForeignKeyActions)) {
throw new Exception(__d('cake_dev', 'Delete action is invalid. Must be one of %s', implode(',', $this->_validForeignKeyActions)));
if (!in_array($attrs['delete'], static::$_validForeignKeyActions)) {
throw new Exception(__d('cake_dev', 'Delete action is invalid. Must be one of %s', implode(',', static::$_validForeignKeyActions)));
}
return $attrs;
}
Expand Down

0 comments on commit cbf8a02

Please sign in to comment.