Browse Source

strict type checks and removing some duplicate count() calls by setting a variable

dogmatic69 13 years ago
parent
commit
cfadc4dbb0

+ 5 - 4
lib/Cake/Console/Command/ApiShell.php

@@ -73,12 +73,13 @@ class ApiShell extends AppShell {
 			$path = $this->paths['core'];
 		}
 
-		if (count($this->args) == 1) {
-			$file = $type;
-			$class = Inflector::camelize($type);
-		} elseif (count($this->args) > 1) {
+		$count = count($this->args);
+		if ($count > 1) {
 			$file = Inflector::underscore($this->args[1]);
 			$class = Inflector::camelize($this->args[1]);
+		} elseif($count) {
+			$file = $type;
+			$class = Inflector::camelize($type);
 		}
 		$objects = App::objects('class', $path);
 		if (in_array($class, $objects)) {

+ 1 - 1
lib/Cake/Console/Command/Task/ExtractTask.php

@@ -480,7 +480,7 @@ class ExtractTask extends AppShell {
 		}
 
 		$dims = Hash::dimensions($rules);
-		if ($dims == 1 || ($dims == 2 && isset($rules['message']))) {
+		if ($dims === 1 || ($dims === 2 && isset($rules['message']))) {
 			$rules = array($rules);
 		}
 

+ 1 - 1
lib/Cake/Console/Command/Task/ProjectTask.php

@@ -384,7 +384,7 @@ class ProjectTask extends AppShell {
 		$admin = '';
 		$prefixes = Configure::read('Routing.prefixes');
 		if (!empty($prefixes)) {
-			if (count($prefixes) == 1) {
+			if (count($prefixes) === 1) {
 				return $prefixes[0] . '_';
 			}
 			if ($this->interactive) {

+ 1 - 1
lib/Cake/Console/Command/Task/TemplateTask.php

@@ -166,7 +166,7 @@ class TemplateTask extends AppShell {
  * @return string returns the path to the selected theme.
  */
 	public function getThemePath() {
-		if (count($this->templatePaths) == 1) {
+		if (count($this->templatePaths) === 1) {
 			$paths = array_values($this->templatePaths);
 			return $paths[0];
 		}

+ 4 - 3
lib/Cake/Console/Command/Task/TestTask.php

@@ -83,15 +83,16 @@ class TestTask extends BakeTask {
  */
 	public function execute() {
 		parent::execute();
-		if (empty($this->args)) {
+		$count = count($this->args);
+		if (!$count) {
 			$this->_interactive();
 		}
 
-		if (count($this->args) == 1) {
+		if ($count === 1) {
 			$this->_interactive($this->args[0]);
 		}
 
-		if (count($this->args) > 1) {
+		if ($count > 1) {
 			$type = Inflector::classify($this->args[0]);
 			if ($this->bake($type, $this->args[1])) {
 				$this->out('<success>Done</success>');

+ 1 - 1
lib/Cake/Console/Shell.php

@@ -325,7 +325,7 @@ class Shell extends Object {
  */
 	public function dispatchShell() {
 		$args = func_get_args();
-		if (is_string($args[0]) && count($args) == 1) {
+		if (is_string($args[0]) && count($args) === 1) {
 			$args = explode(' ', $args[0]);
 		}
 

+ 1 - 1
lib/Cake/Controller/Controller.php

@@ -454,7 +454,7 @@ class Controller extends Object implements CakeEventListener {
 			$this->passedArgs = array_merge($request->params['pass'], $request->params['named']);
 		}
 
-		if (array_key_exists('return', $request->params) && $request->params['return'] == 1) {
+		if (!empty($request->params['return']) && $request->params['return']) {
 			$this->autoRender = false;
 		}
 		if (!empty($request->params['bare'])) {

+ 1 - 1
lib/Cake/Model/Datasource/Database/Mysql.php

@@ -643,7 +643,7 @@ class Mysql extends DboSource {
 		if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
 			return $col;
 		}
-		if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') {
+		if (($col === 'tinyint' && $limit === 1) || $col === 'boolean') {
 			return 'boolean';
 		}
 		if (strpos($col, 'bigint') !== false || $col === 'bigint') {

+ 1 - 1
lib/Cake/Routing/Route/RedirectRoute.php

@@ -74,7 +74,7 @@ class RedirectRoute extends CakeRoute {
 			$this->response = new CakeResponse();
 		}
 		$redirect = $this->redirect;
-		if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) {
+		if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) {
 			$redirect = $this->redirect[0];
 		}
 		if (isset($this->options['persist']) && is_array($redirect)) {

+ 1 - 1
lib/Cake/Utility/CakeTime.php

@@ -745,7 +745,7 @@ class CakeTime {
 				$years = floor($months / 12);
 				$months = $months - ($years * 12);
 			}
-			if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] == 1) {
+			if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] === 1) {
 				$years--;
 			}
 

+ 2 - 2
lib/Cake/Utility/Set.php

@@ -349,7 +349,7 @@ class Set {
 					$context = array('trace' => array(null), 'item' => $context, 'key' => $key);
 				}
 				if ($token === '..') {
-					if (count($context['trace']) == 1) {
+					if (count($context['trace']) === 1) {
 						$context['trace'][] = $context['key'];
 					}
 					$parent = implode('/', $context['trace']) . '/.';
@@ -373,7 +373,7 @@ class Set {
 					);
 				} elseif (is_array($context['item'])
 					&& array_key_exists($token, $context['item'])
-					&& !(strval($key) === strval($token) && count($tokens) == 1 && $tokens[0] === '.')) {
+					&& !(strval($key) === strval($token) && count($tokens) === 1 && $tokens[0] === '.')) {
 					$items = $context['item'][$token];
 					if (!is_array($items)) {
 						$items = array($items);

+ 2 - 3
lib/Cake/View/Helper.php

@@ -526,12 +526,11 @@ class Helper extends Object {
 
 		$isHabtm = (
 			isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
-			$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' &&
-			$count == 1
+			$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
 		);
 
 		// habtm models are special
-		if ($count == 1 && $isHabtm) {
+		if ($count === 1 && $isHabtm) {
 			$this->_association = $parts[0];
 			$entity = $parts[0] . '.' . $parts[0];
 		} else {

+ 4 - 9
lib/Cake/basics.php

@@ -44,20 +44,15 @@ if (!function_exists('config')) {
  */
 	function config() {
 		$args = func_get_args();
+		$count = count($args);
+		$included = 0;
 		foreach ($args as $arg) {
 			if (file_exists(APP . 'Config' . DS . $arg . '.php')) {
 				include_once APP . 'Config' . DS . $arg . '.php';
-
-				if (count($args) == 1) {
-					return true;
-				}
-			} else {
-				if (count($args) == 1) {
-					return false;
-				}
+				$included++;
 			}
 		}
-		return true;
+		return $included === $count;
 	}
 
 }