Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…ng a variable
  • Loading branch information...
commit cfadc4dbb00c124538138cdf728bb99249c6cd50 1 parent 5cc03ca
@dogmatic69 dogmatic69 authored
View
9 lib/Cake/Console/Command/ApiShell.php
@@ -73,12 +73,13 @@ public function main() {
$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)) {
View
2  lib/Cake/Console/Command/Task/ExtractTask.php
@@ -480,7 +480,7 @@ protected function _processValidationRules($field, $rules, $file, $domain) {
}
$dims = Hash::dimensions($rules);
- if ($dims == 1 || ($dims == 2 && isset($rules['message']))) {
+ if ($dims === 1 || ($dims === 2 && isset($rules['message']))) {
$rules = array($rules);
}
View
2  lib/Cake/Console/Command/Task/ProjectTask.php
@@ -384,7 +384,7 @@ public function getPrefix() {
$admin = '';
$prefixes = Configure::read('Routing.prefixes');
if (!empty($prefixes)) {
- if (count($prefixes) == 1) {
+ if (count($prefixes) === 1) {
return $prefixes[0] . '_';
}
if ($this->interactive) {
View
2  lib/Cake/Console/Command/Task/TemplateTask.php
@@ -166,7 +166,7 @@ public function generate($directory, $filename, $vars = null) {
* @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];
}
View
7 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>');
View
2  lib/Cake/Console/Shell.php
@@ -325,7 +325,7 @@ public function hasMethod($name) {
*/
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]);
}
View
2  lib/Cake/Controller/Controller.php
@@ -454,7 +454,7 @@ public function setRequest(CakeRequest $request) {
$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'])) {
View
2  lib/Cake/Model/Datasource/Database/Mysql.php
@@ -643,7 +643,7 @@ public function column($real) {
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') {
View
2  lib/Cake/Routing/Route/RedirectRoute.php
@@ -74,7 +74,7 @@ public function parse($url) {
$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)) {
View
2  lib/Cake/Utility/CakeTime.php
@@ -745,7 +745,7 @@ public static function timeAgoInWords($dateTime, $options = array()) {
$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--;
}
View
4 lib/Cake/Utility/Set.php
@@ -349,7 +349,7 @@ public static function extract($path, $data = null, $options = array()) {
$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 @@ public static function extract($path, $data = null, $options = array()) {
);
} 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);
View
5 lib/Cake/View/Helper.php
@@ -526,12 +526,11 @@ public function setEntity($entity, $setScope = false) {
$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 {
View
13 lib/Cake/basics.php
@@ -44,20 +44,15 @@
*/
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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.