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

This commit is contained in:
dogmatic69 2012-09-14 19:26:00 +01:00
parent 5cc03ca805
commit cfadc4dbb0
13 changed files with 25 additions and 29 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -74,7 +74,7 @@ class RedirectRoute extends CakeRoute {
$this->response = new CakeResponse(); $this->response = new CakeResponse();
} }
$redirect = $this->redirect; $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]; $redirect = $this->redirect[0];
} }
if (isset($this->options['persist']) && is_array($redirect)) { if (isset($this->options['persist']) && is_array($redirect)) {

View file

@ -745,7 +745,7 @@ class CakeTime {
$years = floor($months / 12); $years = floor($months / 12);
$months = $months - ($years * 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--; $years--;
} }

View file

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

View file

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

View file

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