From cbf8a027e3b86b715c4df9c3761a390fcb0848ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Sun, 22 Dec 2013 21:09:02 +0100 Subject: [PATCH] Using static variables instead of instances properties. --- Cake/Database/Schema/Table.php | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Cake/Database/Schema/Table.php b/Cake/Database/Schema/Table.php index d72789f1601..9abda03e369 100644 --- a/Cake/Database/Schema/Table.php +++ b/Cake/Database/Schema/Table.php @@ -72,7 +72,7 @@ class Table { * * @var array */ - protected $_columnKeys = [ + protected static $_columnKeys = [ 'type' => null, 'length' => null, 'precision' => null, @@ -86,7 +86,7 @@ class Table { * * @var array */ - protected $_columnExtras = [ + protected static $_columnExtras = [ 'string' => [ 'fixed' => null, ], @@ -110,7 +110,7 @@ class Table { * * @var array */ - protected $_indexKeys = [ + protected static $_indexKeys = [ 'type' => null, 'columns' => [], 'length' => [], @@ -124,7 +124,7 @@ class Table { * * @var array */ - protected $_validIndexTypes = [ + protected static $_validIndexTypes = [ self::INDEX_INDEX, self::INDEX_FULLTEXT, ]; @@ -134,7 +134,7 @@ class Table { * * @var array */ - protected $_validConstraintTypes = [ + protected static $_validConstraintTypes = [ self::CONSTRAINT_PRIMARY, self::CONSTRAINT_UNIQUE, self::CONSTRAINT_FOREIGN, @@ -145,7 +145,7 @@ class Table { * * @var array */ - protected $_validForeignKeyActions = [ + protected static $_validForeignKeyActions = [ self::ACTION_CASCADE, self::ACTION_SET_NULL, self::ACTION_NO_ACTION, @@ -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; @@ -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'])) { @@ -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']; } } @@ -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'])) { @@ -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; }