Skip to content

Commit

Permalink
type hinting controllers and views
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark authored and markstory committed Feb 26, 2012
1 parent 38c3e30 commit 22452f6
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 50 deletions.
10 changes: 5 additions & 5 deletions lib/Cake/Console/Command/Task/ModelTask.php
Expand Up @@ -534,7 +534,7 @@ public function doAssociations($model) {
* @param array $associations Array of in progress associations * @param array $associations Array of in progress associations
* @return array $associations with belongsTo added in. * @return array $associations with belongsTo added in.
*/ */
public function findBelongsTo($model, $associations) { public function findBelongsTo(Model $model, $associations) {
$fields = $model->schema(true); $fields = $model->schema(true);
foreach ($fields as $fieldName => $field) { foreach ($fields as $fieldName => $field) {
$offset = strpos($fieldName, '_id'); $offset = strpos($fieldName, '_id');
Expand Down Expand Up @@ -563,7 +563,7 @@ public function findBelongsTo($model, $associations) {
* @param array $associations Array of in progress associations * @param array $associations Array of in progress associations
* @return array $associations with hasOne and hasMany added in. * @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); $foreignKey = $this->_modelKey($model->name);
foreach ($this->_tables as $otherTable) { foreach ($this->_tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable); $tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
Expand Down Expand Up @@ -606,7 +606,7 @@ public function findHasOneAndMany($model, $associations) {
* @param array $associations Array of in-progress associations * @param array $associations Array of in-progress associations
* @return array $associations with hasAndBelongsToMany added in. * @return array $associations with hasAndBelongsToMany added in.
*/ */
public function findHasAndBelongsToMany($model, $associations) { public function findHasAndBelongsToMany(Model $model, $associations) {
$foreignKey = $this->_modelKey($model->name); $foreignKey = $this->_modelKey($model->name);
foreach ($this->_tables as $otherTable) { foreach ($this->_tables as $otherTable) {
$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable); $tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
Expand Down Expand Up @@ -646,7 +646,7 @@ public function findHasAndBelongsToMany($model, $associations) {
* @param array $associations Array of associations to be confirmed. * @param array $associations Array of associations to be confirmed.
* @return array Array of confirmed associations * @return array Array of confirmed associations
*/ */
public function confirmAssociations($model, $associations) { public function confirmAssociations(Model $model, $associations) {
foreach ($associations as $type => $settings) { foreach ($associations as $type => $settings) {
if (!empty($associations[$type])) { if (!empty($associations[$type])) {
foreach ($associations[$type] as $i => $assoc) { foreach ($associations[$type] as $i => $assoc) {
Expand All @@ -672,7 +672,7 @@ public function confirmAssociations($model, $associations) {
* @param array $associations Array of associations. * @param array $associations Array of associations.
* @return array 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?'); $prompt = __d('cake_console', 'Would you like to define some additional model associations?');
$wannaDoMoreAssoc = $this->in($prompt, array('y', 'n'), 'n'); $wannaDoMoreAssoc = $this->in($prompt, array('y', 'n'), 'n');
$possibleKeys = $this->_generatePossibleKeys(); $possibleKeys = $this->_generatePossibleKeys();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/ViewTask.php
Expand Up @@ -448,7 +448,7 @@ public function getOptionParser() {
* @param Model $model * @param Model $model
* @return array $associations * @return array $associations
*/ */
protected function _associations($model) { protected function _associations(Model $model) {
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); $keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
$associations = array(); $associations = array();


Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Controller/Component.php
Expand Up @@ -106,7 +106,7 @@ public function __get($name) {
* @return void * @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize * @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 * Called after the Controller::beforeFilter() and before the controller action
Expand All @@ -115,7 +115,7 @@ public function initialize($controller) { }
* @return void * @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup * @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 * Called after the Controller::beforeRender(), after the view class is loaded, and before the
Expand All @@ -125,7 +125,7 @@ public function startup($controller) { }
* @return void * @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender * @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. * Called after Controller::render() and before the output is printed to the browser.
Expand All @@ -134,7 +134,7 @@ public function beforeRender($controller) { }
* @return void * @return void
* @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown * @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 * Called before Controller::redirect(). Allows you to replace the url that will
Expand All @@ -155,6 +155,6 @@ public function shutdown($controller) { }
* @return array|null Either an array or null. * @return array|null Either an array or null.
* @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect * @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) {}


} }
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Acl/AclInterface.php
Expand Up @@ -65,5 +65,5 @@ public function inherit($aro, $aco, $action = "*");
* *
* @param AclComponent $component * @param AclComponent $component
*/ */
public function initialize($component); public function initialize(Component $component);
} }
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Acl/DbAcl.php
Expand Up @@ -52,7 +52,7 @@ public function __construct() {
* @param AclComponent $component * @param AclComponent $component
* @return void * @return void
*/ */
public function initialize($component) { public function initialize(Component $component) {
$component->Aro = $this->Aro; $component->Aro = $this->Aro;
$component->Aco = $this->Aco; $component->Aco = $this->Aco;
} }
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Acl/IniAcl.php
Expand Up @@ -44,7 +44,7 @@ class IniAcl extends Object implements AclInterface {
* @param AclBase $component * @param AclBase $component
* @return void * @return void
*/ */
public function initialize($component) { public function initialize(Component $component) {


} }


Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Acl/PhpAcl.php
Expand Up @@ -65,7 +65,7 @@ public function __construct() {
* @param AclComponent $Component Component instance * @param AclComponent $Component Component instance
* @return void * @return void
*/ */
public function initialize($Component) { public function initialize(Component $Component) {
if (!empty($Component->settings['adapter'])) { if (!empty($Component->settings['adapter'])) {
$this->options = array_merge($this->options, $Component->settings['adapter']); $this->options = array_merge($this->options, $Component->settings['adapter']);
} }
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Auth/BaseAuthorize.php
Expand Up @@ -87,7 +87,7 @@ abstract public function authorize($user, CakeRequest $request);
* @return mixed * @return mixed
* @throws CakeException * @throws CakeException
*/ */
public function controller($controller = null) { public function controller(Controller $controller = null) {
if ($controller) { if ($controller) {
if (!$controller instanceof Controller) { if (!$controller instanceof Controller) {
throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller')); throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller'));
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Auth/ControllerAuthorize.php
Expand Up @@ -44,7 +44,7 @@ class ControllerAuthorize extends BaseAuthorize {
* @return mixed * @return mixed
* @throws CakeException * @throws CakeException
*/ */
public function controller($controller = null) { public function controller(Controller $controller = null) {
if ($controller) { if ($controller) {
if (!method_exists($controller, 'isAuthorized')) { if (!method_exists($controller, 'isAuthorized')) {
throw new CakeException(__d('cake_dev', '$controller does not implement an isAuthorized() method.')); throw new CakeException(__d('cake_dev', '$controller does not implement an isAuthorized() method.'));
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -246,7 +246,7 @@ class AuthComponent extends Component {
* @param Controller $controller A reference to the instantiating controller object * @param Controller $controller A reference to the instantiating controller object
* @return void * @return void
*/ */
public function initialize($controller) { public function initialize(Controller $controller) {
$this->request = $controller->request; $this->request = $controller->request;
$this->response = $controller->response; $this->response = $controller->response;
$this->_methods = $controller->methods; $this->_methods = $controller->methods;
Expand All @@ -263,7 +263,7 @@ public function initialize($controller) {
* @param Controller $controller A reference to the instantiating controller object * @param Controller $controller A reference to the instantiating controller object
* @return boolean * @return boolean
*/ */
public function startup($controller) { public function startup(Controller $controller) {
if ($controller->name == 'CakeError') { if ($controller->name == 'CakeError') {
return true; return true;
} }
Expand Down Expand Up @@ -694,7 +694,7 @@ public static function password($password) {
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return void * @return void
*/ */
public function shutdown($controller) { public function shutdown(Controller $controller) {
if ($this->loggedIn()) { if ($this->loggedIn()) {
$this->Session->delete('Auth.redirect'); $this->Session->delete('Auth.redirect');
} }
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/CookieComponent.php
Expand Up @@ -187,7 +187,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
* @param Controller $controller * @param Controller $controller
* @return void * @return void
*/ */
public function startup($controller) { public function startup(Controller $controller) {
$this->_expire($this->time); $this->_expire($this->time);


if (isset($_COOKIE[$this->name])) { if (isset($_COOKIE[$this->name])) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/EmailComponent.php
Expand Up @@ -270,7 +270,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return void * @return void
*/ */
public function initialize($controller) { public function initialize(Controller $controller) {
if (Configure::read('App.encoding') !== null) { if (Configure::read('App.encoding') !== null) {
$this->charset = Configure::read('App.encoding'); $this->charset = Configure::read('App.encoding');
} }
Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -115,7 +115,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
* @return void * @return void
* @see Router::parseExtensions() * @see Router::parseExtensions()
*/ */
public function initialize($controller, $settings = array()) { public function initialize(Controller $controller, $settings = array()) {
if (isset($this->request->params['ext'])) { if (isset($this->request->params['ext'])) {
$this->ext = $this->request->params['ext']; $this->ext = $this->request->params['ext'];
} }
Expand Down Expand Up @@ -173,7 +173,7 @@ protected function _setExtension() {
* @param Controller $controller A reference to the controller * @param Controller $controller A reference to the controller
* @return void * @return void
*/ */
public function startup($controller) { public function startup(Controller $controller) {
$controller->request->params['isAjax'] = $this->request->is('ajax'); $controller->request->params['isAjax'] = $this->request->is('ajax');
$isRecognized = ( $isRecognized = (
!in_array($this->ext, array('html', 'htm')) && !in_array($this->ext, array('html', 'htm')) &&
Expand Down Expand Up @@ -224,7 +224,7 @@ public function convertXml($xml) {
* @param boolean $exit * @param boolean $exit
* @return void * @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')) { if (!$this->request->is('ajax')) {
return; return;
} }
Expand Down Expand Up @@ -253,7 +253,7 @@ public function beforeRedirect($controller, $url, $status = null, $exit = true)
* @params Controller $controller * @params Controller $controller
* @return boolean false if the render process should be aborted * @return boolean false if the render process should be aborted
**/ **/
public function beforeRender($controller) { public function beforeRender(Controller $controller) {
$shouldCheck = $this->settings['checkHttpCache']; $shouldCheck = $this->settings['checkHttpCache'];
if ($shouldCheck && $this->response->checkNotModified($this->request)) { if ($shouldCheck && $this->response->checkNotModified($this->request)) {
return false; return false;
Expand Down Expand Up @@ -566,7 +566,7 @@ public function prefers($type = null) {
* @see RequestHandlerComponent::setContent() * @see RequestHandlerComponent::setContent()
* @see RequestHandlerComponent::respondAs() * @see RequestHandlerComponent::respondAs()
*/ */
public function renderAs($controller, $type, $options = array()) { public function renderAs(Controller $controller, $type, $options = array()) {
$defaults = array('charset' => 'UTF-8'); $defaults = array('charset' => 'UTF-8');


if (Configure::read('App.encoding') !== null) { if (Configure::read('App.encoding') !== null) {
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Controller/Component/SecurityComponent.php
Expand Up @@ -204,7 +204,7 @@ class SecurityComponent extends Component {
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return void * @return void
*/ */
public function startup($controller) { public function startup(Controller $controller) {
$this->request = $controller->request; $this->request = $controller->request;
$this->_action = $this->request->params['action']; $this->_action = $this->request->params['action'];
$this->_methodsRequired($controller); $this->_methodsRequired($controller);
Expand Down Expand Up @@ -307,7 +307,7 @@ public function requireAuth() {
* @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks
* @throws BadRequestException * @throws BadRequestException
*/ */
public function blackHole($controller, $error = '') { public function blackHole(Controller $controller, $error = '') {
if ($this->blackHoleCallback == null) { if ($this->blackHoleCallback == null) {
throw new BadRequestException(__d('cake_dev', 'The request has been black-holed')); throw new BadRequestException(__d('cake_dev', 'The request has been black-holed'));
} else { } else {
Expand Down Expand Up @@ -335,7 +335,7 @@ protected function _requireMethod($method, $actions = array()) {
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return boolean true if $method is required * @return boolean true if $method is required
*/ */
protected function _methodsRequired($controller) { protected function _methodsRequired(Controller $controller) {
foreach (array('Post', 'Get', 'Put', 'Delete') as $method) { foreach (array('Post', 'Get', 'Put', 'Delete') as $method) {
$property = 'require' . $method; $property = 'require' . $method;
if (is_array($this->$property) && !empty($this->$property)) { if (is_array($this->$property) && !empty($this->$property)) {
Expand All @@ -358,7 +358,7 @@ protected function _methodsRequired($controller) {
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return boolean true if secure connection required * @return boolean true if secure connection required
*/ */
protected function _secureRequired($controller) { protected function _secureRequired(Controller $controller) {
if (is_array($this->requireSecure) && !empty($this->requireSecure)) { if (is_array($this->requireSecure) && !empty($this->requireSecure)) {
$requireSecure = $this->requireSecure; $requireSecure = $this->requireSecure;


Expand All @@ -379,7 +379,7 @@ protected function _secureRequired($controller) {
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return boolean true if authentication required * @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)) { if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) {
$requireAuth = $this->requireAuth; $requireAuth = $this->requireAuth;


Expand Down Expand Up @@ -419,7 +419,7 @@ protected function _authRequired($controller) {
* @param Controller $controller Instantiating controller * @param Controller $controller Instantiating controller
* @return boolean true if submitted form is valid * @return boolean true if submitted form is valid
*/ */
protected function _validatePost($controller) { protected function _validatePost(Controller $controller) {
if (empty($controller->request->data)) { if (empty($controller->request->data)) {
return true; return true;
} }
Expand Down Expand Up @@ -544,7 +544,7 @@ public function generateToken(CakeRequest $request) {
* @param Controller $controller A controller to check * @param Controller $controller A controller to check
* @return boolean Valid csrf token. * @return boolean Valid csrf token.
*/ */
protected function _validateCsrf($controller) { protected function _validateCsrf(Controller $controller) {
$token = $this->Session->read('_Token'); $token = $this->Session->read('_Token');
$requestToken = $controller->request->data('_Token.key'); $requestToken = $controller->request->data('_Token.key');
if (isset($token['csrfTokens'][$requestToken]) && $token['csrfTokens'][$requestToken] >= time()) { if (isset($token['csrfTokens'][$requestToken]) && $token['csrfTokens'][$requestToken] >= time()) {
Expand Down Expand Up @@ -585,7 +585,7 @@ protected function _expireTokens($tokens) {
* @param array $params Parameters to send to method * @param array $params Parameters to send to method
* @return mixed Controller callback method's response * @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))) { if (is_callable(array($controller, $method))) {
return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params); return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params);
} else { } else {
Expand Down
Expand Up @@ -34,7 +34,7 @@ class TestSecurityComponent extends SecurityComponent {
* @param Controller $controller * @param Controller $controller
* @return unknown * @return unknown
*/ */
public function validatePost($controller) { public function validatePost(Controller $controller) {
return $this->_validatePost($controller); return $this->_validatePost($controller);
} }
} }
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Controller/ComponentTest.php
Expand Up @@ -92,7 +92,7 @@ class AppleComponent extends Component {
* @param mixed $controller * @param mixed $controller
* @return void * @return void
*/ */
public function startup($controller) { public function startup(Controller $controller) {
$this->testName = $controller->name; $this->testName = $controller->name;
} }
} }
Expand All @@ -117,7 +117,7 @@ class OrangeComponent extends Component {
* @param mixed $controller * @param mixed $controller
* @return void * @return void
*/ */
public function initialize($controller) { public function initialize(Controller $controller) {
$this->Controller = $controller; $this->Controller = $controller;
$this->Banana->testField = 'OrangeField'; $this->Banana->testField = 'OrangeField';
} }
Expand All @@ -128,7 +128,7 @@ public function initialize($controller) {
* @param Controller $controller * @param Controller $controller
* @return string * @return string
*/ */
public function startup($controller) { public function startup(Controller $controller) {
$controller->foo = 'pass'; $controller->foo = 'pass';
} }
} }
Expand All @@ -153,7 +153,7 @@ class BananaComponent extends Component {
* @param Controller $controller * @param Controller $controller
* @return string * @return string
*/ */
public function startup($controller) { public function startup(Controller $controller) {
$controller->bar = 'fail'; $controller->bar = 'fail';
} }
} }
Expand Down

0 comments on commit 22452f6

Please sign in to comment.