Skip to content
This repository
Browse code

type hinting controllers and views

  • Loading branch information...
commit 22452f61f8841dd10400fb48b2aeb8c6d9e0c52d 1 parent 38c3e30
Mark authored February 23, 2012 markstory committed February 25, 2012
10  lib/Cake/Console/Command/Task/ModelTask.php
@@ -534,7 +534,7 @@ public function doAssociations($model) {
534 534
  * @param array $associations Array of in progress associations
535 535
  * @return array $associations with belongsTo added in.
536 536
  */
537  
-	public function findBelongsTo($model, $associations) {
  537
+	public function findBelongsTo(Model $model, $associations) {
538 538
 		$fields = $model->schema(true);
539 539
 		foreach ($fields as $fieldName => $field) {
540 540
 			$offset = strpos($fieldName, '_id');
@@ -563,7 +563,7 @@ public function findBelongsTo($model, $associations) {
563 563
  * @param array $associations Array of in progress associations
564 564
  * @return array $associations with hasOne and hasMany added in.
565 565
  */
566  
-	public function findHasOneAndMany($model, $associations) {
  566
+	public function findHasOneAndMany(Model $model, $associations) {
567 567
 		$foreignKey = $this->_modelKey($model->name);
568 568
 		foreach ($this->_tables as $otherTable) {
569 569
 			$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
@@ -606,7 +606,7 @@ public function findHasOneAndMany($model, $associations) {
606 606
  * @param array $associations Array of in-progress associations
607 607
  * @return array $associations with hasAndBelongsToMany added in.
608 608
  */
609  
-	public function findHasAndBelongsToMany($model, $associations) {
  609
+	public function findHasAndBelongsToMany(Model $model, $associations) {
610 610
 		$foreignKey = $this->_modelKey($model->name);
611 611
 		foreach ($this->_tables as $otherTable) {
612 612
 			$tempOtherModel = $this->_getModelObject($this->_modelName($otherTable), $otherTable);
@@ -646,7 +646,7 @@ public function findHasAndBelongsToMany($model, $associations) {
646 646
  * @param array $associations Array of associations to be confirmed.
647 647
  * @return array Array of confirmed associations
648 648
  */
649  
-	public function confirmAssociations($model, $associations) {
  649
+	public function confirmAssociations(Model $model, $associations) {
650 650
 		foreach ($associations as $type => $settings) {
651 651
 			if (!empty($associations[$type])) {
652 652
 				foreach ($associations[$type] as $i => $assoc) {
@@ -672,7 +672,7 @@ public function confirmAssociations($model, $associations) {
672 672
  * @param array $associations Array of associations.
673 673
  * @return array Array of associations.
674 674
  */
675  
-	public function doMoreAssociations($model, $associations) {
  675
+	public function doMoreAssociations(Model $model, $associations) {
676 676
 		$prompt = __d('cake_console', 'Would you like to define some additional model associations?');
677 677
 		$wannaDoMoreAssoc = $this->in($prompt, array('y', 'n'), 'n');
678 678
 		$possibleKeys = $this->_generatePossibleKeys();
2  lib/Cake/Console/Command/Task/ViewTask.php
@@ -448,7 +448,7 @@ public function getOptionParser() {
448 448
  * @param Model $model
449 449
  * @return array $associations
450 450
  */
451  
-	protected function _associations($model) {
  451
+	protected function _associations(Model $model) {
452 452
 		$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
453 453
 		$associations = array();
454 454
 
10  lib/Cake/Controller/Component.php
@@ -106,7 +106,7 @@ public function __get($name) {
106 106
  * @return void
107 107
  * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
108 108
  */
109  
-	public function initialize($controller) { }
  109
+	public function initialize(Controller $controller) { }
110 110
 
111 111
 /**
112 112
  * Called after the Controller::beforeFilter() and before the controller action
@@ -115,7 +115,7 @@ public function initialize($controller) { }
115 115
  * @return void
116 116
  * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::startup
117 117
  */
118  
-	public function startup($controller) { }
  118
+	public function startup(Controller $controller) { }
119 119
 
120 120
 /**
121 121
  * Called after the Controller::beforeRender(), after the view class is loaded, and before the
@@ -125,7 +125,7 @@ public function startup($controller) { }
125 125
  * @return void
126 126
  * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRender
127 127
  */
128  
-	public function beforeRender($controller) { }
  128
+	public function beforeRender(Controller $controller) { }
129 129
 
130 130
 /**
131 131
  * Called after Controller::render() and before the output is printed to the browser.
@@ -134,7 +134,7 @@ public function beforeRender($controller) { }
134 134
  * @return void
135 135
  * @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::shutdown
136 136
  */
137  
-	public function shutdown($controller) { }
  137
+	public function shutdown(Controller $controller) { }
138 138
 
139 139
 /**
140 140
  * Called before Controller::redirect().  Allows you to replace the url that will
@@ -155,6 +155,6 @@ public function shutdown($controller) { }
155 155
  * @return array|null Either an array or null.
156 156
  * @link @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
157 157
  */
158  
-	public function beforeRedirect($controller, $url, $status = null, $exit = true) {}
  158
+	public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {}
159 159
 
160 160
 }
2  lib/Cake/Controller/Component/Acl/AclInterface.php
@@ -65,5 +65,5 @@ public function inherit($aro, $aco, $action = "*");
65 65
  *
66 66
  * @param AclComponent $component
67 67
  */
68  
-	public function initialize($component);
  68
+	public function initialize(Component $component);
69 69
 }
2  lib/Cake/Controller/Component/Acl/DbAcl.php
@@ -52,7 +52,7 @@ public function __construct() {
52 52
  * @param AclComponent $component
53 53
  * @return void
54 54
  */
55  
-	public function initialize($component) {
  55
+	public function initialize(Component $component) {
56 56
 		$component->Aro = $this->Aro;
57 57
 		$component->Aco = $this->Aco;
58 58
 	}
2  lib/Cake/Controller/Component/Acl/IniAcl.php
@@ -44,7 +44,7 @@ class IniAcl extends Object implements AclInterface {
44 44
  * @param AclBase $component
45 45
  * @return void
46 46
  */
47  
-	public function initialize($component) {
  47
+	public function initialize(Component $component) {
48 48
 
49 49
 	}
50 50
 
2  lib/Cake/Controller/Component/Acl/PhpAcl.php
@@ -65,7 +65,7 @@ public function __construct() {
65 65
  * @param AclComponent $Component Component instance 
66 66
  * @return void
67 67
  */
68  
-	public function initialize($Component) {
  68
+	public function initialize(Component $Component) {
69 69
 		if (!empty($Component->settings['adapter'])) {
70 70
 			$this->options = array_merge($this->options, $Component->settings['adapter']);
71 71
 		}
2  lib/Cake/Controller/Component/Auth/BaseAuthorize.php
@@ -87,7 +87,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
87 87
  * @return mixed
88 88
  * @throws CakeException
89 89
  */
90  
-	public function controller($controller = null) {
  90
+	public function controller(Controller $controller = null) {
91 91
 		if ($controller) {
92 92
 			if (!$controller instanceof Controller) {
93 93
 				throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller'));
2  lib/Cake/Controller/Component/Auth/ControllerAuthorize.php
@@ -44,7 +44,7 @@ class ControllerAuthorize extends BaseAuthorize {
44 44
  * @return mixed
45 45
  * @throws CakeException
46 46
  */
47  
-	public function controller($controller = null) {
  47
+	public function controller(Controller $controller = null) {
48 48
 		if ($controller) {
49 49
 			if (!method_exists($controller, 'isAuthorized')) {
50 50
 				throw new CakeException(__d('cake_dev', '$controller does not implement an isAuthorized() method.'));
6  lib/Cake/Controller/Component/AuthComponent.php
@@ -246,7 +246,7 @@ class AuthComponent extends Component {
246 246
  * @param Controller $controller A reference to the instantiating controller object
247 247
  * @return void
248 248
  */
249  
-	public function initialize($controller) {
  249
+	public function initialize(Controller $controller) {
250 250
 		$this->request = $controller->request;
251 251
 		$this->response = $controller->response;
252 252
 		$this->_methods = $controller->methods;
@@ -263,7 +263,7 @@ public function initialize($controller) {
263 263
  * @param Controller $controller A reference to the instantiating controller object
264 264
  * @return boolean
265 265
  */
266  
-	public function startup($controller) {
  266
+	public function startup(Controller $controller) {
267 267
 		if ($controller->name == 'CakeError') {
268 268
 			return true;
269 269
 		}
@@ -694,7 +694,7 @@ public static function password($password) {
694 694
  * @param Controller $controller Instantiating controller
695 695
  * @return void
696 696
  */
697  
-	public function shutdown($controller) {
  697
+	public function shutdown(Controller $controller) {
698 698
 		if ($this->loggedIn()) {
699 699
 			$this->Session->delete('Auth.redirect');
700 700
 		}
2  lib/Cake/Controller/Component/CookieComponent.php
@@ -187,7 +187,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
187 187
  * @param Controller $controller
188 188
  * @return void
189 189
  */
190  
-	public function startup($controller) {
  190
+	public function startup(Controller $controller) {
191 191
 		$this->_expire($this->time);
192 192
 
193 193
 		if (isset($_COOKIE[$this->name])) {
2  lib/Cake/Controller/Component/EmailComponent.php
@@ -270,7 +270,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
270 270
  * @param Controller $controller Instantiating controller
271 271
  * @return void
272 272
  */
273  
-	public function initialize($controller) {
  273
+	public function initialize(Controller $controller) {
274 274
 		if (Configure::read('App.encoding') !== null) {
275 275
 			$this->charset = Configure::read('App.encoding');
276 276
 		}
10  lib/Cake/Controller/Component/RequestHandlerComponent.php
@@ -115,7 +115,7 @@ public function __construct(ComponentCollection $collection, $settings = array()
115 115
  * @return void
116 116
  * @see Router::parseExtensions()
117 117
  */
118  
-	public function initialize($controller, $settings = array()) {
  118
+	public function initialize(Controller $controller, $settings = array()) {
119 119
 		if (isset($this->request->params['ext'])) {
120 120
 			$this->ext = $this->request->params['ext'];
121 121
 		}
@@ -173,7 +173,7 @@ protected function _setExtension() {
173 173
  * @param Controller $controller A reference to the controller
174 174
  * @return void
175 175
  */
176  
-	public function startup($controller) {
  176
+	public function startup(Controller $controller) {
177 177
 		$controller->request->params['isAjax'] = $this->request->is('ajax');
178 178
 		$isRecognized = (
179 179
 			!in_array($this->ext, array('html', 'htm')) &&
@@ -224,7 +224,7 @@ public function convertXml($xml) {
224 224
  * @param boolean $exit
225 225
  * @return void
226 226
  */
227  
-	public function beforeRedirect($controller, $url, $status = null, $exit = true) {
  227
+	public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
228 228
 		if (!$this->request->is('ajax')) {
229 229
 			return;
230 230
 		}
@@ -253,7 +253,7 @@ public function beforeRedirect($controller, $url, $status = null, $exit = true)
253 253
  * @params Controller $controller
254 254
  * @return boolean false if the render process should be aborted
255 255
  **/
256  
-	public function beforeRender($controller) {
  256
+	public function beforeRender(Controller $controller) {
257 257
 		$shouldCheck = $this->settings['checkHttpCache'];
258 258
 		if ($shouldCheck && $this->response->checkNotModified($this->request)) {
259 259
 			return false;
@@ -566,7 +566,7 @@ public function prefers($type = null) {
566 566
  * @see RequestHandlerComponent::setContent()
567 567
  * @see RequestHandlerComponent::respondAs()
568 568
  */
569  
-	public function renderAs($controller, $type, $options = array()) {
  569
+	public function renderAs(Controller $controller, $type, $options = array()) {
570 570
 		$defaults = array('charset' => 'UTF-8');
571 571
 
572 572
 		if (Configure::read('App.encoding') !== null) {
16  lib/Cake/Controller/Component/SecurityComponent.php
@@ -204,7 +204,7 @@ class SecurityComponent extends Component {
204 204
  * @param Controller $controller Instantiating controller
205 205
  * @return void
206 206
  */
207  
-	public function startup($controller) {
  207
+	public function startup(Controller $controller) {
208 208
 		$this->request = $controller->request;
209 209
 		$this->_action = $this->request->params['action'];
210 210
 		$this->_methodsRequired($controller);
@@ -307,7 +307,7 @@ public function requireAuth() {
307 307
  * @link http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks
308 308
  * @throws BadRequestException
309 309
  */
310  
-	public function blackHole($controller, $error = '') {
  310
+	public function blackHole(Controller $controller, $error = '') {
311 311
 		if ($this->blackHoleCallback == null) {
312 312
 			throw new BadRequestException(__d('cake_dev', 'The request has been black-holed'));
313 313
 		} else {
@@ -335,7 +335,7 @@ protected function _requireMethod($method, $actions = array()) {
335 335
  * @param Controller $controller Instantiating controller
336 336
  * @return boolean true if $method is required
337 337
  */
338  
-	protected function _methodsRequired($controller) {
  338
+	protected function _methodsRequired(Controller $controller) {
339 339
 		foreach (array('Post', 'Get', 'Put', 'Delete') as $method) {
340 340
 			$property = 'require' . $method;
341 341
 			if (is_array($this->$property) && !empty($this->$property)) {
@@ -358,7 +358,7 @@ protected function _methodsRequired($controller) {
358 358
  * @param Controller $controller Instantiating controller
359 359
  * @return boolean true if secure connection required
360 360
  */
361  
-	protected function _secureRequired($controller) {
  361
+	protected function _secureRequired(Controller $controller) {
362 362
 		if (is_array($this->requireSecure) && !empty($this->requireSecure)) {
363 363
 			$requireSecure = $this->requireSecure;
364 364
 
@@ -379,7 +379,7 @@ protected function _secureRequired($controller) {
379 379
  * @param Controller $controller Instantiating controller
380 380
  * @return boolean true if authentication required
381 381
  */
382  
-	protected function _authRequired($controller) {
  382
+	protected function _authRequired(Controller $controller) {
383 383
 		if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) {
384 384
 			$requireAuth = $this->requireAuth;
385 385
 
@@ -419,7 +419,7 @@ protected function _authRequired($controller) {
419 419
  * @param Controller $controller Instantiating controller
420 420
  * @return boolean true if submitted form is valid
421 421
  */
422  
-	protected function _validatePost($controller) {
  422
+	protected function _validatePost(Controller $controller) {
423 423
 		if (empty($controller->request->data)) {
424 424
 			return true;
425 425
 		}
@@ -544,7 +544,7 @@ public function generateToken(CakeRequest $request) {
544 544
  * @param Controller $controller A controller to check
545 545
  * @return boolean Valid csrf token.
546 546
  */
547  
-	protected function _validateCsrf($controller) {
  547
+	protected function _validateCsrf(Controller $controller) {
548 548
 		$token = $this->Session->read('_Token');
549 549
 		$requestToken = $controller->request->data('_Token.key');
550 550
 		if (isset($token['csrfTokens'][$requestToken]) && $token['csrfTokens'][$requestToken] >= time()) {
@@ -585,7 +585,7 @@ protected function _expireTokens($tokens) {
585 585
  * @param array $params Parameters to send to method
586 586
  * @return mixed Controller callback method's response
587 587
  */
588  
-	protected function _callback($controller, $method, $params = array()) {
  588
+	protected function _callback(Controller $controller, $method, $params = array()) {
589 589
 		if (is_callable(array($controller, $method))) {
590 590
 			return call_user_func_array(array(&$controller, $method), empty($params) ? null : $params);
591 591
 		} else {
2  lib/Cake/Test/Case/Controller/Component/SecurityComponentTest.php
@@ -34,7 +34,7 @@ class TestSecurityComponent extends SecurityComponent {
34 34
  * @param Controller $controller
35 35
  * @return unknown
36 36
  */
37  
-	public function validatePost($controller) {
  37
+	public function validatePost(Controller $controller) {
38 38
 		return $this->_validatePost($controller);
39 39
 	}
40 40
 }
8  lib/Cake/Test/Case/Controller/ComponentTest.php
@@ -92,7 +92,7 @@ class AppleComponent extends Component {
92 92
  * @param mixed $controller
93 93
  * @return void
94 94
  */
95  
-	public function startup($controller) {
  95
+	public function startup(Controller $controller) {
96 96
 		$this->testName = $controller->name;
97 97
 	}
98 98
 }
@@ -117,7 +117,7 @@ class OrangeComponent extends Component {
117 117
  * @param mixed $controller
118 118
  * @return void
119 119
  */
120  
-	public function initialize($controller) {
  120
+	public function initialize(Controller $controller) {
121 121
 		$this->Controller = $controller;
122 122
 		$this->Banana->testField = 'OrangeField';
123 123
 	}
@@ -128,7 +128,7 @@ public function initialize($controller) {
128 128
  * @param Controller $controller
129 129
  * @return string
130 130
  */
131  
-	public function startup($controller) {
  131
+	public function startup(Controller $controller) {
132 132
 		$controller->foo = 'pass';
133 133
 	}
134 134
 }
@@ -153,7 +153,7 @@ class BananaComponent extends Component {
153 153
  * @param Controller $controller
154 154
  * @return string
155 155
  */
156  
-	public function startup($controller) {
  156
+	public function startup(Controller $controller) {
157 157
 		$controller->bar = 'fail';
158 158
 	}
159 159
 }
10  lib/Cake/Test/Case/Controller/ControllerTest.php
@@ -328,7 +328,7 @@ public function beforeRedirect() {
328 328
  *
329 329
  * @return void
330 330
  */
331  
-	public function initialize($controller) {
  331
+	public function initialize(Controller $controller) {
332 332
 	}
333 333
 
334 334
 /**
@@ -336,7 +336,7 @@ public function initialize($controller) {
336 336
  *
337 337
  * @return void
338 338
  */
339  
-	public function startup($controller) {
  339
+	public function startup(Controller $controller) {
340 340
 	}
341 341
 
342 342
 /**
@@ -344,7 +344,7 @@ public function startup($controller) {
344 344
  *
345 345
  * @return void
346 346
  */
347  
-	public function shutdown($controller) {
  347
+	public function shutdown(Controller $controller) {
348 348
 	}
349 349
 
350 350
 /**
@@ -352,7 +352,7 @@ public function shutdown($controller) {
352 352
  *
353 353
  * @return void
354 354
  */
355  
-	public function beforeRender($controller) {
  355
+	public function beforeRender(Controller $controller) {
356 356
 		if ($this->viewclass) {
357 357
 			$controller->viewClass = $this->viewclass;
358 358
 		}
@@ -362,7 +362,7 @@ public function beforeRender($controller) {
362 362
 class Test2Component extends TestComponent {
363 363
 
364 364
 
365  
-	public function beforeRender($controller) {
  365
+	public function beforeRender(Controller $controller) {
366 366
 		return false;
367 367
 	}
368 368
 }
2  lib/Cake/Test/Case/Error/ExceptionRendererTest.php
@@ -64,7 +64,7 @@ class BlueberryComponent extends Component {
64 64
  *
65 65
  * @return void
66 66
  */
67  
-	public function initialize($controller) {
  67
+	public function initialize(Controller $controller) {
68 68
 		$this->testName = 'BlueberryComponent';
69 69
 	}
70 70
 }
2  lib/Cake/View/JsonView.php
@@ -61,7 +61,7 @@ class JsonView extends View {
61 61
  *
62 62
  * @param Controller $controller
63 63
  */
64  
-	public function __construct($controller) {
  64
+	public function __construct(Controller $controller = null) {
65 65
 		parent::__construct($controller);
66 66
 		if (isset($controller->response) && $controller->response instanceof CakeResponse) {
67 67
 			$controller->response->type('json');
2  lib/Cake/View/MediaView.php
@@ -70,7 +70,7 @@ class MediaView extends View {
70 70
  *
71 71
  * @param Controller $controller The controller with viewVars
72 72
  */
73  
-	public function __construct($controller = null) {
  73
+	public function __construct(Controller $controller = null) {
74 74
 		parent::__construct($controller);
75 75
 	}
76 76
 
2  lib/Cake/View/View.php
@@ -305,7 +305,7 @@ class View extends Object {
305 305
  *
306 306
  * @param Controller $controller A controller object to pull View::_passedVars from.
307 307
  */
308  
-	public function __construct($controller) {
  308
+	public function __construct(Controller $controller = null) {
309 309
 		if (is_object($controller)) {
310 310
 			$count = count($this->_passedVars);
311 311
 			for ($j = 0; $j < $count; $j++) {
2  lib/Cake/View/XmlView.php
@@ -63,7 +63,7 @@ class XmlView extends View {
63 63
  *
64 64
  * @param Controller $controller
65 65
  */
66  
-	public function __construct($controller) {
  66
+	public function __construct(Controller $controller = null) {
67 67
 		parent::__construct($controller);
68 68
 
69 69
 		if (isset($controller->response) && $controller->response instanceof CakeResponse) {

0 notes on commit 22452f6

Please sign in to comment.
Something went wrong with that request. Please try again.