Skip to content

Commit

Permalink
type hinting models
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark authored and markstory committed Feb 26, 2012
1 parent 22452f6 commit 4511208
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 86 deletions.
8 changes: 4 additions & 4 deletions lib/Cake/Model/Behavior/AclBehavior.php
Expand Up @@ -44,7 +44,7 @@ class AclBehavior extends ModelBehavior {
* @param array $config
* @return void
*/
public function setup($model, $config = array()) {
public function setup(Model $model, $config = array()) {
if (isset($config[0])) {
$config['type'] = $config[0];
unset($config[0]);
Expand Down Expand Up @@ -74,7 +74,7 @@ public function setup($model, $config = array()) {
* @return array
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/acl.html#node
*/
public function node($model, $ref = null, $type = null) {
public function node(Model $model, $ref = null, $type = null) {
if (empty($type)) {
$type = $this->_typeMaps[$this->settings[$model->name]['type']];
if (is_array($type)) {
Expand All @@ -95,7 +95,7 @@ public function node($model, $ref = null, $type = null) {
* @param boolean $created True if this is a new record
* @return void
*/
public function afterSave($model, $created) {
public function afterSave(Model $model, $created) {
$types = $this->_typeMaps[$this->settings[$model->name]['type']];
if (!is_array($types)) {
$types = array($types);
Expand Down Expand Up @@ -125,7 +125,7 @@ public function afterSave($model, $created) {
* @param Model $model
* @return void
*/
public function afterDelete($model) {
public function afterDelete(Model $model) {
$types = $this->_typeMaps[$this->settings[$model->name]['type']];
if (!is_array($types)) {
$types = array($types);
Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Model/Behavior/ContainableBehavior.php
Expand Up @@ -61,7 +61,7 @@ class ContainableBehavior extends ModelBehavior {
* @param array $settings Settings to override for model.
* @return void
*/
public function setup($Model, $settings = array()) {
public function setup(Model $Model, $settings = array()) {
if (!isset($this->settings[$Model->alias])) {
$this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public function setup($Model, $settings = array()) {
* @param array $query Query parameters as set by cake
* @return array
*/
public function beforeFind($Model, $query) {
public function beforeFind(Model $Model, $query) {
$reset = (isset($query['reset']) ? $query['reset'] : true);
$noContain = (
(isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) ||
Expand Down Expand Up @@ -225,7 +225,7 @@ public function beforeFind($Model, $query) {
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-containable
*/
public function contain($Model) {
public function contain(Model $Model) {
$args = func_get_args();
$contain = call_user_func_array('am', array_slice($args, 1));
$this->runtime[$Model->alias]['contain'] = $contain;
Expand All @@ -239,7 +239,7 @@ public function contain($Model) {
* @param Model $Model Model on which to reset bindings
* @return void
*/
public function resetBindings($Model) {
public function resetBindings(Model $Model) {
if (!empty($Model->__backOriginalAssociation)) {
$Model->__backAssociation = $Model->__backOriginalAssociation;
unset($Model->__backOriginalAssociation);
Expand All @@ -263,7 +263,7 @@ public function resetBindings($Model) {
* @param boolean $throwErrors Whether non-existent bindings show throw errors
* @return array Containments
*/
public function containments($Model, $contain, $containments = array(), $throwErrors = null) {
public function containments(Model $Model, $contain, $containments = array(), $throwErrors = null) {
$options = array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery');
$keep = array();
if ($throwErrors === null) {
Expand Down Expand Up @@ -365,7 +365,7 @@ public function containments($Model, $contain, $containments = array(), $throwEr
* @param mixed $fields If array, fields to initially load, if false use $Model as primary model
* @return array Fields
*/
public function fieldDependencies($Model, $map, $fields = array()) {
public function fieldDependencies(Model $Model, $map, $fields = array()) {
if ($fields === false) {
foreach ($map as $parent => $children) {
foreach ($children as $type => $bindings) {
Expand Down
22 changes: 11 additions & 11 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -62,7 +62,7 @@ class TranslateBehavior extends ModelBehavior {
* @param array $config Array of configuration information.
* @return mixed
*/
public function setup($model, $config = array()) {
public function setup(Model $model, $config = array()) {
$db = ConnectionManager::getDataSource($model->useDbConfig);
if (!$db->connected) {
trigger_error(
Expand All @@ -84,7 +84,7 @@ public function setup($model, $config = array()) {
* @param Model $model Model being detached.
* @return void
*/
public function cleanup($model) {
public function cleanup(Model $model) {
$this->unbindTranslation($model);
unset($this->settings[$model->alias]);
unset($this->runtime[$model->alias]);
Expand All @@ -97,7 +97,7 @@ public function cleanup($model) {
* @param array $query Array of Query parameters.
* @return array Modified query
*/
public function beforeFind($model, $query) {
public function beforeFind(Model $model, $query) {
$this->runtime[$model->alias]['virtualFields'] = $model->virtualFields;
$locale = $this->_getLocale($model);
if (empty($locale)) {
Expand Down Expand Up @@ -263,7 +263,7 @@ protected function _addJoin(Model $model, $query, $field, $aliasField, $locale,
* @param boolean $primary Did the find originate on $model.
* @return array Modified results
*/
public function afterFind($model, $results, $primary) {
public function afterFind(Model $model, $results, $primary) {
$model->virtualFields = $this->runtime[$model->alias]['virtualFields'];
$this->runtime[$model->alias]['virtualFields'] = $this->runtime[$model->alias]['fields'] = array();
$locale = $this->_getLocale($model);
Expand Down Expand Up @@ -309,7 +309,7 @@ public function afterFind($model, $results, $primary) {
* @param Model $model Model invalidFields was called on.
* @return boolean
*/
public function beforeValidate($model) {
public function beforeValidate(Model $model) {
$locale = $this->_getLocale($model);
if (empty($locale)) {
return true;
Expand Down Expand Up @@ -343,7 +343,7 @@ public function beforeValidate($model) {
* @param boolean $created Whether or not the save created a record.
* @return void
*/
public function afterSave($model, $created) {
public function afterSave(Model $model, $created) {
if (!isset($this->runtime[$model->alias]['beforeSave'])) {
return true;
}
Expand Down Expand Up @@ -386,7 +386,7 @@ public function afterSave($model, $created) {
* @param Model $model Model the callback was run on.
* @return void
*/
public function afterDelete($model) {
public function afterDelete(Model $model) {
$RuntimeModel = $this->translateModel($model);
$conditions = array('model' => $model->alias, 'foreign_key' => $model->id);
$RuntimeModel->deleteAll($conditions);
Expand All @@ -398,7 +398,7 @@ public function afterDelete($model) {
* @param Model $model Model the locale needs to be set/get on.
* @return mixed string or false
*/
protected function _getLocale($model) {
protected function _getLocale(Model $model) {
if (!isset($model->locale) || is_null($model->locale)) {
$I18n = I18n::getInstance();
$I18n->l10n->get(Configure::read('Config.language'));
Expand All @@ -417,7 +417,7 @@ protected function _getLocale($model) {
* @param Model $model Model to get a translatemodel for.
* @return Model
*/
public function translateModel($model) {
public function translateModel(Model $model) {
if (!isset($this->runtime[$model->alias]['model'])) {
if (!isset($model->translateModel) || empty($model->translateModel)) {
$className = 'I18nModel';
Expand Down Expand Up @@ -447,7 +447,7 @@ public function translateModel($model) {
* @param boolean $reset
* @return boolean
*/
public function bindTranslation($model, $fields, $reset = true) {
public function bindTranslation(Model $model, $fields, $reset = true) {
if (is_string($fields)) {
$fields = array($fields);
}
Expand Down Expand Up @@ -525,7 +525,7 @@ public function bindTranslation($model, $fields, $reset = true) {
* unbind all original translations
* @return boolean
*/
public function unbindTranslation($model, $fields = null) {
public function unbindTranslation(Model $model, $fields = null) {
if (empty($fields) && empty($this->settings[$model->alias])) {
return false;
}
Expand Down
40 changes: 20 additions & 20 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -54,7 +54,7 @@ class TreeBehavior extends ModelBehavior {
* @param array $config array of configuration settings.
* @return void
*/
public function setup($Model, $config = array()) {
public function setup(Model $Model, $config = array()) {
if (isset($config[0])) {
$config['type'] = $config[0];
unset($config[0]);
Expand All @@ -80,7 +80,7 @@ public function setup($Model, $config = array()) {
* @param boolean $created indicates whether the node just saved was created or updated
* @return boolean true on success, false on failure
*/
public function afterSave($Model, $created) {
public function afterSave(Model $Model, $created) {
extract($this->settings[$Model->alias]);
if ($created) {
if ((isset($Model->data[$Model->alias][$parent])) && $Model->data[$Model->alias][$parent]) {
Expand All @@ -99,7 +99,7 @@ public function afterSave($Model, $created) {
* @param array $query Query parameters as set by cake
* @return array
*/
public function beforeFind($Model, $query) {
public function beforeFind(Model $Model, $query) {
if ($Model->findQueryType == 'threaded' && !isset($query['parent'])) {
$query['parent'] = $this->settings[$Model->alias]['parent'];
}
Expand All @@ -115,7 +115,7 @@ public function beforeFind($Model, $query) {
* @param boolean $cascade
* @return boolean true to continue, false to abort the delete
*/
public function beforeDelete($Model, $cascade = true) {
public function beforeDelete(Model $Model, $cascade = true) {
extract($this->settings[$Model->alias]);
$data = current($Model->find('first', array(
'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id),
Expand Down Expand Up @@ -149,7 +149,7 @@ public function beforeDelete($Model, $cascade = true) {
* @param Model $Model Model instance
* @return boolean true to continue, false to abort the save
*/
public function beforeSave($Model) {
public function beforeSave(Model $Model) {
extract($this->settings[$Model->alias]);

$this->_addToWhitelist($Model, array($left, $right));
Expand Down Expand Up @@ -219,7 +219,7 @@ public function beforeSave($Model) {
* @return integer number of child nodes
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::childCount
*/
public function childCount($Model, $id = null, $direct = false) {
public function childCount(Model $Model, $id = null, $direct = false) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public function childCount($Model, $id = null, $direct = false) {
* @return array Array of child nodes
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::children
*/
public function children($Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
public function children(Model $Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -322,7 +322,7 @@ public function children($Model, $id = null, $direct = false, $fields = null, $o
* @return array An associative array of records, where the id is the key, and the display field is the value
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::generateTreeList
*/
public function generateTreeList($Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
public function generateTreeList(Model $Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
$overrideRecursive = $recursive;
extract($this->settings[$Model->alias]);
if (!is_null($overrideRecursive)) {
Expand Down Expand Up @@ -378,7 +378,7 @@ public function generateTreeList($Model, $conditions = null, $keyPath = null, $v
* @return array|boolean Array of data for the parent node
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::getParentNode
*/
public function getParentNode($Model, $id = null, $fields = null, $recursive = null) {
public function getParentNode(Model $Model, $id = null, $fields = null, $recursive = null) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public function getParentNode($Model, $id = null, $fields = null, $recursive = n
* @return array Array of nodes from top most parent to current node
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::getPath
*/
public function getPath($Model, $id = null, $fields = null, $recursive = null) {
public function getPath(Model $Model, $id = null, $fields = null, $recursive = null) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -448,7 +448,7 @@ public function getPath($Model, $id = null, $fields = null, $recursive = null) {
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::moveDown
*/
public function moveDown($Model, $id = null, $number = 1) {
public function moveDown(Model $Model, $id = null, $number = 1) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -506,7 +506,7 @@ public function moveDown($Model, $id = null, $number = 1) {
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::moveUp
*/
public function moveUp($Model, $id = null, $number = 1) {
public function moveUp(Model $Model, $id = null, $number = 1) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -570,7 +570,7 @@ public function moveUp($Model, $id = null, $number = 1) {
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::recover
*/
public function recover($Model, $mode = 'parent', $missingParentAction = null) {
public function recover(Model $Model, $mode = 'parent', $missingParentAction = null) {
if (is_array($mode)) {
extract (array_merge(array('mode' => 'parent'), $mode));
}
Expand Down Expand Up @@ -649,7 +649,7 @@ public function recover($Model, $mode = 'parent', $missingParentAction = null) {
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::reorder
*/
public function reorder($Model, $options = array()) {
public function reorder(Model $Model, $options = array()) {
$options = array_merge(array('id' => null, 'field' => $Model->displayField, 'order' => 'ASC', 'verify' => true), $options);
extract($options);
if ($verify && !$this->verify($Model)) {
Expand Down Expand Up @@ -688,7 +688,7 @@ public function reorder($Model, $options = array()) {
* @return boolean true on success, false on failure
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::removeFromTree
*/
public function removeFromTree($Model, $id = null, $delete = false) {
public function removeFromTree(Model $Model, $id = null, $delete = false) {
if (is_array($id)) {
extract (array_merge(array('id' => null), $id));
}
Expand Down Expand Up @@ -759,7 +759,7 @@ public function removeFromTree($Model, $id = null, $delete = false) {
* [incorrect left/right index,node id], message)
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::verify
*/
public function verify($Model) {
public function verify(Model $Model) {
extract($this->settings[$Model->alias]);
if (!$Model->find('count', array('conditions' => $scope))) {
return true;
Expand Down Expand Up @@ -831,7 +831,7 @@ public function verify($Model) {
* @param boolean $created
* @return boolean true on success, false on failure
*/
protected function _setParent($Model, $parentId = null, $created = false) {
protected function _setParent(Model $Model, $parentId = null, $created = false) {
extract($this->settings[$Model->alias]);
list($node) = array_values($Model->find('first', array(
'conditions' => array($scope, $Model->escapeField() => $Model->id),
Expand Down Expand Up @@ -903,7 +903,7 @@ protected function _setParent($Model, $parentId = null, $created = false) {
* @param boolean $created
* @return integer
*/
protected function _getMax($Model, $scope, $right, $recursive = -1, $created = false) {
protected function _getMax(Model $Model, $scope, $right, $recursive = -1, $created = false) {
$db = ConnectionManager::getDataSource($Model->useDbConfig);
if ($created) {
if (is_string($scope)) {
Expand Down Expand Up @@ -931,7 +931,7 @@ protected function _getMax($Model, $scope, $right, $recursive = -1, $created = f
* @param integer $recursive
* @return integer
*/
protected function _getMin($Model, $scope, $left, $recursive = -1) {
protected function _getMin(Model $Model, $scope, $left, $recursive = -1) {
$db = ConnectionManager::getDataSource($Model->useDbConfig);
$name = $Model->alias . '.' . $left;
list($edge) = array_values($Model->find('first', array(
Expand All @@ -955,7 +955,7 @@ protected function _getMin($Model, $scope, $left, $recursive = -1) {
* @param string $field
* @return void
*/
protected function _sync($Model, $shift, $dir = '+', $conditions = array(), $created = false, $field = 'both') {
protected function _sync(Model $Model, $shift, $dir = '+', $conditions = array(), $created = false, $field = 'both') {
$ModelRecursive = $Model->recursive;
extract($this->settings[$Model->alias]);
$Model->recursive = $recursive;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -348,7 +348,7 @@ public function name($data) {
* @param boolean $quote
* @return array
*/
public function fields($model, $alias = null, $fields = array(), $quote = true) {
public function fields(Model $model, $alias = null, $fields = array(), $quote = true) {
if (empty($alias)) {
$alias = $model->alias;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -266,7 +266,7 @@ public function describe($model) {
* @param boolean $quote
* @return array
*/
public function fields($model, $alias = null, $fields = array(), $quote = true) {
public function fields(Model $model, $alias = null, $fields = array(), $quote = true) {
if (empty($alias)) {
$alias = $model->alias;
}
Expand Down

0 comments on commit 4511208

Please sign in to comment.