From 22452f61f8841dd10400fb48b2aeb8c6d9e0c52d Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 23 Feb 2012 15:06:25 +0100 Subject: [PATCH] type hinting controllers and views --- lib/Cake/Console/Command/Task/ModelTask.php | 10 +++++----- lib/Cake/Console/Command/Task/ViewTask.php | 2 +- lib/Cake/Controller/Component.php | 10 +++++----- .../Controller/Component/Acl/AclInterface.php | 2 +- lib/Cake/Controller/Component/Acl/DbAcl.php | 2 +- lib/Cake/Controller/Component/Acl/IniAcl.php | 2 +- lib/Cake/Controller/Component/Acl/PhpAcl.php | 2 +- .../Controller/Component/Auth/BaseAuthorize.php | 2 +- .../Component/Auth/ControllerAuthorize.php | 2 +- lib/Cake/Controller/Component/AuthComponent.php | 6 +++--- .../Controller/Component/CookieComponent.php | 2 +- lib/Cake/Controller/Component/EmailComponent.php | 2 +- .../Component/RequestHandlerComponent.php | 10 +++++----- .../Controller/Component/SecurityComponent.php | 16 ++++++++-------- .../Component/SecurityComponentTest.php | 2 +- lib/Cake/Test/Case/Controller/ComponentTest.php | 8 ++++---- lib/Cake/Test/Case/Controller/ControllerTest.php | 10 +++++----- .../Test/Case/Error/ExceptionRendererTest.php | 2 +- lib/Cake/View/JsonView.php | 2 +- lib/Cake/View/MediaView.php | 2 +- lib/Cake/View/View.php | 2 +- lib/Cake/View/XmlView.php | 2 +- 22 files changed, 50 insertions(+), 50 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 9f30eadacd4..82a92188bf5 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -534,7 +534,7 @@ public function doAssociations($model) { * @param array $associations Array of in progress associations * @return array $associations with belongsTo added in. */ - public function findBelongsTo($model, $associations) { + public function findBelongsTo(Model $model, $associations) { $fields = $model->schema(true); foreach ($fields as $fieldName => $field) { $offset = strpos($fieldName, '_id'); @@ -563,7 +563,7 @@ public function findBelongsTo($model, $associations) { * @param array $associations Array of in progress associations * @return array $associations with hasOne and hasMany added in. */ - public function findHasOneAndMany($model, $associations) { + public function findHasOneAndMany(Model $model, $associations) { $foreignKey = $this->_modelKey($model->name); foreach ($this->_tables as $otherTable) { $tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable); @@ -606,7 +606,7 @@ public function findHasOneAndMany($model, $associations) { * @param array $associations Array of in-progress associations * @return array $associations with hasAndBelongsToMany added in. */ - public function findHasAndBelongsToMany($model, $associations) { + public function findHasAndBelongsToMany(Model $model, $associations) { $foreignKey = $this->_modelKey($model->name); foreach ($this->_tables as $otherTable) { $tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable); @@ -646,7 +646,7 @@ public function findHasAndBelongsToMany($model, $associations) { * @param array $associations Array of associations to be confirmed. * @return array Array of confirmed associations */ - public function confirmAssociations($model, $associations) { + public function confirmAssociations(Model $model, $associations) { foreach ($associations as $type => $settings) { if (!empty($associations[$type])) { foreach ($associations[$type] as $i => $assoc) { @@ -672,7 +672,7 @@ public function confirmAssociations($model, $associations) { * @param array $associations Array of associations. * @return array Array of associations. */ - public function doMoreAssociations($model, $associations) { + public function doMoreAssociations(Model $model, $associations) { $prompt = __d('cake_console', 'Would you like to define some additional model associations?'); $wannaDoMoreAssoc = $this->in($prompt, array('y', 'n'), 'n'); $possibleKeys = $this->_generatePossibleKeys(); diff --git a/lib/Cake/Console/Command/Task/ViewTask.php b/lib/Cake/Console/Command/Task/ViewTask.php index 4fe53b7ec85..62160dee756 100644 --- a/lib/Cake/Console/Command/Task/ViewTask.php +++ b/lib/Cake/Console/Command/Task/ViewTask.php @@ -448,7 +448,7 @@ public function getOptionParser() { * @param Model $model * @return array $associations */ - protected function _associations($model) { + protected function _associations(Model $model) { $keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); $associations = array(); diff --git a/lib/Cake/Controller/Component.php b/lib/Cake/Controller/Component.php index e6dd15d67ce..8c18b797193 100644 --- a/lib/Cake/Controller/Component.php +++ b/lib/Cake/Controller/Component.php @@ -106,7 +106,7 @@ public function __get($name) { * @return void * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize */ - public function initialize($controller) { } + public function initialize(Controller $controller) { } /** * Called after the Controller::beforeFilter() and before the controller action @@ -115,7 +115,7 @@ public function initialize($controller) { } * @return void * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup */ - public function startup($controller) { } + public function startup(Controller $controller) { } /** * Called after the Controller::beforeRender(), after the view class is loaded, and before the @@ -125,7 +125,7 @@ public function startup($controller) { } * @return void * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender */ - public function beforeRender($controller) { } + public function beforeRender(Controller $controller) { } /** * Called after Controller::render() and before the output is printed to the browser. @@ -134,7 +134,7 @@ public function beforeRender($controller) { } * @return void * @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown */ - public function shutdown($controller) { } + public function shutdown(Controller $controller) { } /** * Called before Controller::redirect(). Allows you to replace the url that will @@ -155,6 +155,6 @@ public function shutdown($controller) { } * @return array|null Either an array or null. * @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect */ - public function beforeRedirect($controller, $url, $status = null, $exit = true) {} + public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {} } diff --git a/lib/Cake/Controller/Component/Acl/AclInterface.php b/lib/Cake/Controller/Component/Acl/AclInterface.php index ff8961f29c1..88b1b71fefb 100644 --- a/lib/Cake/Controller/Component/Acl/AclInterface.php +++ b/lib/Cake/Controller/Component/Acl/AclInterface.php @@ -65,5 +65,5 @@ public function inherit($aro, $aco, $action = "*"); * * @param AclComponent $component */ - public function initialize($component); + public function initialize(Component $component); } diff --git a/lib/Cake/Controller/Component/Acl/DbAcl.php b/lib/Cake/Controller/Component/Acl/DbAcl.php index a219a6e9517..5abaaf4cf76 100644 --- a/lib/Cake/Controller/Component/Acl/DbAcl.php +++ b/lib/Cake/Controller/Component/Acl/DbAcl.php @@ -52,7 +52,7 @@ public function __construct() { * @param AclComponent $component * @return void */ - public function initialize($component) { + public function initialize(Component $component) { $component->Aro = $this->Aro; $component->Aco = $this->Aco; } diff --git a/lib/Cake/Controller/Component/Acl/IniAcl.php b/lib/Cake/Controller/Component/Acl/IniAcl.php index 930d0a0a3f0..34710c81ca3 100644 --- a/lib/Cake/Controller/Component/Acl/IniAcl.php +++ b/lib/Cake/Controller/Component/Acl/IniAcl.php @@ -44,7 +44,7 @@ class IniAcl extends Object implements AclInterface { * @param AclBase $component * @return void */ - public function initialize($component) { + public function initialize(Component $component) { } diff --git a/lib/Cake/Controller/Component/Acl/PhpAcl.php b/lib/Cake/Controller/Component/Acl/PhpAcl.php index 0c77cb7aa1c..962ca4eb453 100644 --- a/lib/Cake/Controller/Component/Acl/PhpAcl.php +++ b/lib/Cake/Controller/Component/Acl/PhpAcl.php @@ -65,7 +65,7 @@ public function __construct() { * @param AclComponent $Component Component instance * @return void */ - public function initialize($Component) { + public function initialize(Component $Component) { if (!empty($Component->settings['adapter'])) { $this->options = array_merge($this->options, $Component->settings['adapter']); } diff --git a/lib/Cake/Controller/Component/Auth/BaseAuthorize.php b/lib/Cake/Controller/Component/Auth/BaseAuthorize.php index 00763ab84ed..7b10621495b 100644 --- a/lib/Cake/Controller/Component/Auth/BaseAuthorize.php +++ b/lib/Cake/Controller/Component/Auth/BaseAuthorize.php @@ -87,7 +87,7 @@ abstract public function authorize($user, CakeRequest $request); * @return mixed * @throws CakeException */ - public function controller($controller = null) { + public function controller(Controller $controller = null) { if ($controller) { if (!$controller instanceof Controller) { throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller')); diff --git a/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php b/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php index 9328caceeaf..ce90d229465 100644 --- a/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php +++ b/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php @@ -44,7 +44,7 @@ class ControllerAuthorize extends BaseAuthorize { * @return mixed * @throws CakeException */ - public function controller($controller = null) { + public function controller(Controller $controller = null) { if ($controller) { if (!method_exists($controller, 'isAuthorized')) { throw new CakeException(__d('cake_dev', '$controller does not implement an isAuthorized() method.')); diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index 0b5aea1d6a4..2bf806242aa 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -246,7 +246,7 @@ class AuthComponent extends Component { * @param Controller $controller A reference to the instantiating controller object * @return void */ - public function initialize($controller) { + public function initialize(Controller $controller) { $this->request = $controller->request; $this->response = $controller->response; $this->_methods = $controller->methods; @@ -263,7 +263,7 @@ public function initialize($controller) { * @param Controller $controller A reference to the instantiating controller object * @return boolean */ - public function startup($controller) { + public function startup(Controller $controller) { if ($controller->name == 'CakeError') { return true; } @@ -694,7 +694,7 @@ public static function password($password) { * @param Controller $controller Instantiating controller * @return void */ - public function shutdown($controller) { + public function shutdown(Controller $controller) { if ($this->loggedIn()) { $this->Session->delete('Auth.redirect'); } diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index b61ffb59ebf..06ea670e23f 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -187,7 +187,7 @@ public function __construct(ComponentCollection $collection, $settings = array() * @param Controller $controller * @return void */ - public function startup($controller) { + public function startup(Controller $controller) { $this->_expire($this->time); if (isset($_COOKIE[$this->name])) { diff --git a/lib/Cake/Controller/Component/EmailComponent.php b/lib/Cake/Controller/Component/EmailComponent.php index 15b7233c464..cc6b3f07913 100644 --- a/lib/Cake/Controller/Component/EmailComponent.php +++ b/lib/Cake/Controller/Component/EmailComponent.php @@ -270,7 +270,7 @@ public function __construct(ComponentCollection $collection, $settings = array() * @param Controller $controller Instantiating controller * @return void */ - public function initialize($controller) { + public function initialize(Controller $controller) { if (Configure::read('App.encoding') !== null) { $this->charset = Configure::read('App.encoding'); } diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index c6f8f261cda..437f41d1f15 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -115,7 +115,7 @@ public function __construct(ComponentCollection $collection, $settings = array() * @return void * @see Router::parseExtensions() */ - public function initialize($controller, $settings = array()) { + public function initialize(Controller $controller, $settings = array()) { if (isset($this->request->params['ext'])) { $this->ext = $this->request->params['ext']; } @@ -173,7 +173,7 @@ protected function _setExtension() { * @param Controller $controller A reference to the controller * @return void */ - public function startup($controller) { + public function startup(Controller $controller) { $controller->request->params['isAjax'] = $this->request->is('ajax'); $isRecognized = ( !in_array($this->ext, array('html', 'htm')) && @@ -224,7 +224,7 @@ public function convertXml($xml) { * @param boolean $exit * @return void */ - public function beforeRedirect($controller, $url, $status = null, $exit = true) { + public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) { if (!$this->request->is('ajax')) { return; } @@ -253,7 +253,7 @@ public function beforeRedirect($controller, $url, $status = null, $exit = true) * @params Controller $controller * @return boolean false if the render process should be aborted **/ - public function beforeRender($controller) { + public function beforeRender(Controller $controller) { $shouldCheck = $this->settings['checkHttpCache']; if ($shouldCheck && $this->response->checkNotModified($this->request)) { return false; @@ -566,7 +566,7 @@ public function prefers($type = null) { * @see RequestHandlerComponent::setContent() * @see RequestHandlerComponent::respondAs() */ - public function renderAs($controller, $type, $options = array()) { + public function renderAs(Controller $controller, $type, $options = array()) { $defaults = array('charset' => 'UTF-8'); if (Configure::read('App.encoding') !== null) { diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index 3bbdb921752..e128a5c839c 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -204,7 +204,7 @@ class SecurityComponent extends Component { * @param Controller $controller Instantiating controller * @return void */ - public function startup($controller) { + public function startup(Controller $controller) { $this->request = $controller->request; $this->_action = $this->request->params['action']; $this->_methodsRequired($controller); @@ -307,7 +307,7 @@ public function requireAuth() { * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks * @throws BadRequestException */ - public function blackHole($controller, $error = '') { + public function blackHole(Controller $controller, $error = '') { if ($this->blackHoleCallback == null) { throw new BadRequestException(__d('cake_dev', 'The request has been black-holed')); } else { @@ -335,7 +335,7 @@ protected function _requireMethod($method, $actions = array()) { * @param Controller $controller Instantiating controller * @return boolean true if $method is required */ - protected function _methodsRequired($controller) { + protected function _methodsRequired(Controller $controller) { foreach (array('Post', 'Get', 'Put', 'Delete') as $method) { $property = 'require' . $method; if (is_array($this->$property) && !empty($this->$property)) { @@ -358,7 +358,7 @@ protected function _methodsRequired($controller) { * @param Controller $controller Instantiating controller * @return boolean true if secure connection required */ - protected function _secureRequired($controller) { + protected function _secureRequired(Controller $controller) { if (is_array($this->requireSecure) && !empty($this->requireSecure)) { $requireSecure = $this->requireSecure; @@ -379,7 +379,7 @@ protected function _secureRequired($controller) { * @param Controller $controller Instantiating controller * @return boolean true if authentication required */ - protected function _authRequired($controller) { + protected function _authRequired(Controller $controller) { if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) { $requireAuth = $this->requireAuth; @@ -419,7 +419,7 @@ protected function _authRequired($controller) { * @param Controller $controller Instantiating controller * @return boolean true if submitted form is valid */ - protected function _validatePost($controller) { + protected function _validatePost(Controller $controller) { if (empty($controller->request->data)) { return true; } @@ -544,7 +544,7 @@ public function generateToken(CakeRequest $request) { * @param Controller $controller A controller to check * @return boolean Valid csrf token. */ - protected function _validateCsrf($controller) { + protected function _validateCsrf(Controller $controller) { $token = $this->Session->read('_Token'); $requestToken = $controller->request->data('_Token.key'); if (isset($token['csrfTokens'][$requestToken]) && $token['csrfTokens'][$requestToken] >= time()) { @@ -585,7 +585,7 @@ protected function _expireTokens($tokens) { * @param array $params Parameters to send to method * @return mixed Controller callback method's response */ - protected function _callback($controller, $method, $params = array()) { + protected function _callback(Controller $controller, $method, $params = array()) { if (is_callable(array($controller, $method))) { return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params); } else { diff --git a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php index e0b502a2d4f..56bc69d3122 100644 --- a/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php @@ -34,7 +34,7 @@ class TestSecurityComponent extends SecurityComponent { * @param Controller $controller * @return unknown */ - public function validatePost($controller) { + public function validatePost(Controller $controller) { return $this->_validatePost($controller); } } diff --git a/lib/Cake/Test/Case/Controller/ComponentTest.php b/lib/Cake/Test/Case/Controller/ComponentTest.php index 6338135fcd0..cf8d0b08cc9 100644 --- a/lib/Cake/Test/Case/Controller/ComponentTest.php +++ b/lib/Cake/Test/Case/Controller/ComponentTest.php @@ -92,7 +92,7 @@ class AppleComponent extends Component { * @param mixed $controller * @return void */ - public function startup($controller) { + public function startup(Controller $controller) { $this->testName = $controller->name; } } @@ -117,7 +117,7 @@ class OrangeComponent extends Component { * @param mixed $controller * @return void */ - public function initialize($controller) { + public function initialize(Controller $controller) { $this->Controller = $controller; $this->Banana->testField = 'OrangeField'; } @@ -128,7 +128,7 @@ public function initialize($controller) { * @param Controller $controller * @return string */ - public function startup($controller) { + public function startup(Controller $controller) { $controller->foo = 'pass'; } } @@ -153,7 +153,7 @@ class BananaComponent extends Component { * @param Controller $controller * @return string */ - public function startup($controller) { + public function startup(Controller $controller) { $controller->bar = 'fail'; } } diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index f18abc6e71c..99a0688e761 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -328,7 +328,7 @@ public function beforeRedirect() { * * @return void */ - public function initialize($controller) { + public function initialize(Controller $controller) { } /** @@ -336,7 +336,7 @@ public function initialize($controller) { * * @return void */ - public function startup($controller) { + public function startup(Controller $controller) { } /** @@ -344,7 +344,7 @@ public function startup($controller) { * * @return void */ - public function shutdown($controller) { + public function shutdown(Controller $controller) { } /** @@ -352,7 +352,7 @@ public function shutdown($controller) { * * @return void */ - public function beforeRender($controller) { + public function beforeRender(Controller $controller) { if ($this->viewclass) { $controller->viewClass = $this->viewclass; } @@ -362,7 +362,7 @@ public function beforeRender($controller) { class Test2Component extends TestComponent { - public function beforeRender($controller) { + public function beforeRender(Controller $controller) { return false; } } diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index b127d940148..d24439c08ca 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -64,7 +64,7 @@ class BlueberryComponent extends Component { * * @return void */ - public function initialize($controller) { + public function initialize(Controller $controller) { $this->testName = 'BlueberryComponent'; } } diff --git a/lib/Cake/View/JsonView.php b/lib/Cake/View/JsonView.php index 66613a2c1f5..845497d688b 100644 --- a/lib/Cake/View/JsonView.php +++ b/lib/Cake/View/JsonView.php @@ -61,7 +61,7 @@ class JsonView extends View { * * @param Controller $controller */ - public function __construct($controller) { + public function __construct(Controller $controller = null) { parent::__construct($controller); if (isset($controller->response) && $controller->response instanceof CakeResponse) { $controller->response->type('json'); diff --git a/lib/Cake/View/MediaView.php b/lib/Cake/View/MediaView.php index 7248b940b33..3f8f172762b 100644 --- a/lib/Cake/View/MediaView.php +++ b/lib/Cake/View/MediaView.php @@ -70,7 +70,7 @@ class MediaView extends View { * * @param Controller $controller The controller with viewVars */ - public function __construct($controller = null) { + public function __construct(Controller $controller = null) { parent::__construct($controller); } diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 1e978ed24bb..5566e72d942 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -305,7 +305,7 @@ class View extends Object { * * @param Controller $controller A controller object to pull View::_passedVars from. */ - public function __construct($controller) { + public function __construct(Controller $controller = null) { if (is_object($controller)) { $count = count($this->_passedVars); for ($j = 0; $j < $count; $j++) { diff --git a/lib/Cake/View/XmlView.php b/lib/Cake/View/XmlView.php index 8d88a810f2f..f2e3e9605bd 100644 --- a/lib/Cake/View/XmlView.php +++ b/lib/Cake/View/XmlView.php @@ -63,7 +63,7 @@ class XmlView extends View { * * @param Controller $controller */ - public function __construct($controller) { + public function __construct(Controller $controller = null) { parent::__construct($controller); if (isset($controller->response) && $controller->response instanceof CakeResponse) {