Skip to content
This repository
Browse code

strict type checks and removing some duplicate count() calls by setti…

…ng a variable
  • Loading branch information...
commit cfadc4dbb00c124538138cdf728bb99249c6cd50 1 parent 5cc03ca
Carl Sutton authored September 14, 2012
9  lib/Cake/Console/Command/ApiShell.php
@@ -73,12 +73,13 @@ public function main() {
73 73
 			$path = $this->paths['core'];
74 74
 		}
75 75
 
76  
-		if (count($this->args) == 1) {
77  
-			$file = $type;
78  
-			$class = Inflector::camelize($type);
79  
-		} elseif (count($this->args) > 1) {
  76
+		$count = count($this->args);
  77
+		if ($count > 1) {
80 78
 			$file = Inflector::underscore($this->args[1]);
81 79
 			$class = Inflector::camelize($this->args[1]);
  80
+		} elseif($count) {
  81
+			$file = $type;
  82
+			$class = Inflector::camelize($type);
82 83
 		}
83 84
 		$objects = App::objects('class', $path);
84 85
 		if (in_array($class, $objects)) {
2  lib/Cake/Console/Command/Task/ExtractTask.php
@@ -480,7 +480,7 @@ protected function _processValidationRules($field, $rules, $file, $domain) {
480 480
 		}
481 481
 
482 482
 		$dims = Hash::dimensions($rules);
483  
-		if ($dims == 1 || ($dims == 2 && isset($rules['message']))) {
  483
+		if ($dims === 1 || ($dims === 2 && isset($rules['message']))) {
484 484
 			$rules = array($rules);
485 485
 		}
486 486
 
2  lib/Cake/Console/Command/Task/ProjectTask.php
@@ -384,7 +384,7 @@ public function getPrefix() {
384 384
 		$admin = '';
385 385
 		$prefixes = Configure::read('Routing.prefixes');
386 386
 		if (!empty($prefixes)) {
387  
-			if (count($prefixes) == 1) {
  387
+			if (count($prefixes) === 1) {
388 388
 				return $prefixes[0] . '_';
389 389
 			}
390 390
 			if ($this->interactive) {
2  lib/Cake/Console/Command/Task/TemplateTask.php
@@ -166,7 +166,7 @@ public function generate($directory, $filename, $vars = null) {
166 166
  * @return string returns the path to the selected theme.
167 167
  */
168 168
 	public function getThemePath() {
169  
-		if (count($this->templatePaths) == 1) {
  169
+		if (count($this->templatePaths) === 1) {
170 170
 			$paths = array_values($this->templatePaths);
171 171
 			return $paths[0];
172 172
 		}
7  lib/Cake/Console/Command/Task/TestTask.php
@@ -83,15 +83,16 @@ class TestTask extends BakeTask {
83 83
  */
84 84
 	public function execute() {
85 85
 		parent::execute();
86  
-		if (empty($this->args)) {
  86
+		$count = count($this->args);
  87
+		if (!$count) {
87 88
 			$this->_interactive();
88 89
 		}
89 90
 
90  
-		if (count($this->args) == 1) {
  91
+		if ($count === 1) {
91 92
 			$this->_interactive($this->args[0]);
92 93
 		}
93 94
 
94  
-		if (count($this->args) > 1) {
  95
+		if ($count > 1) {
95 96
 			$type = Inflector::classify($this->args[0]);
96 97
 			if ($this->bake($type, $this->args[1])) {
97 98
 				$this->out('<success>Done</success>');
2  lib/Cake/Console/Shell.php
@@ -325,7 +325,7 @@ public function hasMethod($name) {
325 325
  */
326 326
 	public function dispatchShell() {
327 327
 		$args = func_get_args();
328  
-		if (is_string($args[0]) && count($args) == 1) {
  328
+		if (is_string($args[0]) && count($args) === 1) {
329 329
 			$args = explode(' ', $args[0]);
330 330
 		}
331 331
 
2  lib/Cake/Controller/Controller.php
@@ -454,7 +454,7 @@ public function setRequest(CakeRequest $request) {
454 454
 			$this->passedArgs = array_merge($request->params['pass'], $request->params['named']);
455 455
 		}
456 456
 
457  
-		if (array_key_exists('return', $request->params) && $request->params['return'] == 1) {
  457
+		if (!empty($request->params['return']) && $request->params['return']) {
458 458
 			$this->autoRender = false;
459 459
 		}
460 460
 		if (!empty($request->params['bare'])) {
2  lib/Cake/Model/Datasource/Database/Mysql.php
@@ -643,7 +643,7 @@ public function column($real) {
643 643
 		if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
644 644
 			return $col;
645 645
 		}
646  
-		if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') {
  646
+		if (($col === 'tinyint' && $limit === 1) || $col === 'boolean') {
647 647
 			return 'boolean';
648 648
 		}
649 649
 		if (strpos($col, 'bigint') !== false || $col === 'bigint') {
2  lib/Cake/Routing/Route/RedirectRoute.php
@@ -74,7 +74,7 @@ public function parse($url) {
74 74
 			$this->response = new CakeResponse();
75 75
 		}
76 76
 		$redirect = $this->redirect;
77  
-		if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) {
  77
+		if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) {
78 78
 			$redirect = $this->redirect[0];
79 79
 		}
80 80
 		if (isset($this->options['persist']) && is_array($redirect)) {
2  lib/Cake/Utility/CakeTime.php
@@ -745,7 +745,7 @@ public static function timeAgoInWords($dateTime, $options = array()) {
745 745
 				$years = floor($months / 12);
746 746
 				$months = $months - ($years * 12);
747 747
 			}
748  
-			if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] == 1) {
  748
+			if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] === 1) {
749 749
 				$years--;
750 750
 			}
751 751
 
4  lib/Cake/Utility/Set.php
@@ -349,7 +349,7 @@ public static function extract($path, $data = null, $options = array()) {
349 349
 					$context = array('trace' => array(null), 'item' => $context, 'key' => $key);
350 350
 				}
351 351
 				if ($token === '..') {
352  
-					if (count($context['trace']) == 1) {
  352
+					if (count($context['trace']) === 1) {
353 353
 						$context['trace'][] = $context['key'];
354 354
 					}
355 355
 					$parent = implode('/', $context['trace']) . '/.';
@@ -373,7 +373,7 @@ public static function extract($path, $data = null, $options = array()) {
373 373
 					);
374 374
 				} elseif (is_array($context['item'])
375 375
 					&& array_key_exists($token, $context['item'])
376  
-					&& !(strval($key) === strval($token) && count($tokens) == 1 && $tokens[0] === '.')) {
  376
+					&& !(strval($key) === strval($token) && count($tokens) === 1 && $tokens[0] === '.')) {
377 377
 					$items = $context['item'][$token];
378 378
 					if (!is_array($items)) {
379 379
 						$items = array($items);
5  lib/Cake/View/Helper.php
@@ -526,12 +526,11 @@ public function setEntity($entity, $setScope = false) {
526 526
 
527 527
 		$isHabtm = (
528 528
 			isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
529  
-			$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' &&
530  
-			$count == 1
  529
+			$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
531 530
 		);
532 531
 
533 532
 		// habtm models are special
534  
-		if ($count == 1 && $isHabtm) {
  533
+		if ($count === 1 && $isHabtm) {
535 534
 			$this->_association = $parts[0];
536 535
 			$entity = $parts[0] . '.' . $parts[0];
537 536
 		} else {
13  lib/Cake/basics.php
@@ -44,20 +44,15 @@
44 44
  */
45 45
 	function config() {
46 46
 		$args = func_get_args();
  47
+		$count = count($args);
  48
+		$included = 0;
47 49
 		foreach ($args as $arg) {
48 50
 			if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
49 51
 				include_once APP . 'Config' . DS . $arg . '.php';
50  
-
51  
-				if (count($args) == 1) {
52  
-					return true;
53  
-				}
54  
-			} else {
55  
-				if (count($args) == 1) {
56  
-					return false;
57  
-				}
  52
+				$included++;
58 53
 			}
59 54
 		}
60  
-		return true;
  55
+		return $included === $count;
61 56
 	}
62 57
 
63 58
 }

0 notes on commit cfadc4d

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