From cf8fccae96fe9318f7f9a7e5daf0046c4f6cdc92 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 18:26:30 +0100 Subject: [PATCH 01/10] converting $foo == null / $foo == false to !$foo --- lib/Cake/Console/Command/AclShell.php | 2 +- lib/Cake/Console/Command/Task/DbConfigTask.php | 6 +++--- lib/Cake/Console/Command/Task/ModelTask.php | 2 +- lib/Cake/Console/Command/Task/ProjectTask.php | 2 +- lib/Cake/Console/Command/Task/TemplateTask.php | 2 +- lib/Cake/Console/Shell.php | 8 ++++---- lib/Cake/Controller/Component/Acl/IniAcl.php | 2 +- .../Controller/Component/SecurityComponent.php | 2 +- lib/Cake/Controller/Controller.php | 2 +- lib/Cake/Core/App.php | 2 +- lib/Cake/Model/Behavior/TranslateBehavior.php | 2 +- lib/Cake/Model/Behavior/TreeBehavior.php | 14 ++++++-------- lib/Cake/Model/Datasource/CakeSession.php | 2 +- lib/Cake/Model/Datasource/Database/Mysql.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 4 ++-- lib/Cake/Model/Model.php | 6 +++--- lib/Cake/Model/Permission.php | 8 ++++---- lib/Cake/Network/CakeResponse.php | 2 +- lib/Cake/Network/Http/HttpResponse.php | 2 +- lib/Cake/Network/Http/HttpSocket.php | 2 +- lib/Cake/TestSuite/Fixture/CakeFixtureManager.php | 2 +- lib/Cake/Utility/File.php | 6 +++--- lib/Cake/Utility/Folder.php | 4 ++-- lib/Cake/Utility/Security.php | 2 +- lib/Cake/View/Helper.php | 2 +- lib/Cake/View/Helper/FormHelper.php | 2 +- lib/Cake/View/Helper/HtmlHelper.php | 4 ++-- lib/Cake/View/Helper/JsHelper.php | 2 +- lib/Cake/View/Helper/SessionHelper.php | 2 +- lib/Cake/View/View.php | 2 +- 30 files changed, 50 insertions(+), 52 deletions(-) diff --git a/lib/Cake/Console/Command/AclShell.php b/lib/Cake/Console/Command/AclShell.php index 4a935287f..a65737ebf 100644 --- a/lib/Cake/Console/Command/AclShell.php +++ b/lib/Cake/Console/Command/AclShell.php @@ -598,7 +598,7 @@ class AclShell extends AppShell { * @return array Variables */ protected function _dataVars($type = null) { - if ($type == null) { + if (!$type) { $type = $this->args[0]; } $vars = array(); diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index b9778a558..d8be6303d 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -92,7 +92,7 @@ class DbConfigTask extends AppShell { $done = false; $dbConfigs = array(); - while ($done == false) { + while (!$done) { $name = ''; while ($name == '') { @@ -136,7 +136,7 @@ class DbConfigTask extends AppShell { $password = ''; $blankPassword = false; - while ($password == '' && $blankPassword == false) { + while ($password == '' && !$blankPassword) { $password = $this->in(__d('cake_console', 'Password:')); if ($password == '') { @@ -180,7 +180,7 @@ class DbConfigTask extends AppShell { $config = compact('name', 'datasource', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema'); - while ($this->_verify($config) == false) { + while (!$this->_verify($config)) { $this->_interactive(); } diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index df2725d1f..cc7a5b3f5 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -780,7 +780,7 @@ class ModelTask extends BakeTask { */ public function bake($name, $data = array()) { if (is_object($name)) { - if ($data == false) { + if (!$data) { $data = array(); $data['associations'] = $this->doAssociations($name); $data['validate'] = $this->doValidation($name); diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index 77afa983b..3935a826d 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/lib/Cake/Console/Command/Task/ProjectTask.php @@ -66,7 +66,7 @@ class ProjectTask extends AppShell { } $response = false; - while ($response == false && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) { + while (!$response && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) { $prompt = __d('cake_console', 'A project already exists in this location: %s Overwrite?', $project); $response = $this->in($prompt, array('y', 'n'), 'n'); if (strtolower($response) === 'n') { diff --git a/lib/Cake/Console/Command/Task/TemplateTask.php b/lib/Cake/Console/Command/Task/TemplateTask.php index 69b4cdd39..b9a7fba63 100644 --- a/lib/Cake/Console/Command/Task/TemplateTask.php +++ b/lib/Cake/Console/Command/Task/TemplateTask.php @@ -123,7 +123,7 @@ class TemplateTask extends AppShell { $data = array($one => $two); } - if ($data == null) { + if (!$data) { return false; } $this->templateVars = $data + $this->templateVars; diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index 74e5e033b..567aa731f 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -154,7 +154,7 @@ class Shell extends Object { * @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell */ public function __construct($stdout = null, $stderr = null, $stdin = null) { - if ($this->name == null) { + if (!$this->name) { $this->name = Inflector::camelize(str_replace(array('Shell', 'Task'), '', get_class($this))); } $this->Tasks = new TaskCollection($this); @@ -162,13 +162,13 @@ class Shell extends Object { $this->stdout = $stdout; $this->stderr = $stderr; $this->stdin = $stdin; - if ($this->stdout == null) { + if (!$this->stdout) { $this->stdout = new ConsoleOutput('php://stdout'); } - if ($this->stderr == null) { + if (!$this->stderr) { $this->stderr = new ConsoleOutput('php://stderr'); } - if ($this->stdin == null) { + if (!$this->stdin) { $this->stdin = new ConsoleInput('php://stdin'); } $this->_useLogger(); diff --git a/lib/Cake/Controller/Component/Acl/IniAcl.php b/lib/Cake/Controller/Component/Acl/IniAcl.php index d915443fb..4bcb5d214 100644 --- a/lib/Cake/Controller/Component/Acl/IniAcl.php +++ b/lib/Cake/Controller/Component/Acl/IniAcl.php @@ -91,7 +91,7 @@ class IniAcl extends Object implements AclInterface { * @return boolean Success */ public function check($aro, $aco, $action = null) { - if ($this->config == null) { + if (!$this->config) { $this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php'); } $aclConfig = $this->config; diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index f6e407935..61dd3a0de 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -308,7 +308,7 @@ class SecurityComponent extends Component { * @throws BadRequestException */ public function blackHole(Controller $controller, $error = '') { - if ($this->blackHoleCallback == null) { + if (!$this->blackHoleCallback) { throw new BadRequestException(__d('cake_dev', 'The request has been black-holed')); } return $this->_callback($controller, $this->blackHoleCallback, array($error)); diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index fa8b7dae9..cd8c801c2 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -319,7 +319,7 @@ class Controller extends Object implements CakeEventListener { $this->name = substr(get_class($this), 0, -10); } - if ($this->viewPath == null) { + if (!$this->viewPath) { $this->viewPath = $this->name; } diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 7619bef6a..fd6d1d1b2 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -607,7 +607,7 @@ class App { extract($parent, EXTR_OVERWRITE); } - if ($name == null && $file == null) { + if (!$name && !$file) { return false; } diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 3eccf6269..8d4a11bf0 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -328,7 +328,7 @@ class TranslateBehavior extends ModelBehavior { * @return boolean true. */ public function beforeSave(Model $Model, $options = array()) { - if (isset($options['validate']) && $options['validate'] == false) { + if (isset($options['validate']) && !$options['validate']) { unset($this->runtime[$Model->alias]['beforeSave']); } if (isset($this->runtime[$Model->alias]['beforeSave'])) { diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index eb5242fb2..af6957444 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -355,17 +355,16 @@ class TreeBehavior extends ModelBehavior { $recursive = $overrideRecursive; } - if ($keyPath == null && $valuePath == null && $Model->hasField($Model->displayField)) { + $fields = null; + if (!$keyPath && !$valuePath && $Model->hasField($Model->displayField)) { $fields = array($Model->primaryKey, $Model->displayField, $left, $right); - } else { - $fields = null; } - if ($keyPath == null) { + if (!$keyPath) { $keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey; } - if ($valuePath == null) { + if (!$valuePath) { $valuePath = array('%s%s', '{n}.tree_prefix', '{n}.' . $Model->alias . '.' . $Model->displayField); } elseif (is_string($valuePath)) { @@ -645,9 +644,8 @@ class TreeBehavior extends ModelBehavior { $db = ConnectionManager::getDataSource($Model->useDbConfig); foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { $path = $this->getPath($Model, $array[$Model->alias][$Model->primaryKey]); - if ($path == null || count($path) < 2) { - $parentId = null; - } else { + $parentId = null; + if (count($path) > 1) { $parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey]; } $Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey])); diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 6baab1d5b..6f8050f0f 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -248,7 +248,7 @@ class CakeSession { public static function delete($name) { if (self::check($name)) { self::_overwrite($_SESSION, Hash::remove($_SESSION, $name)); - return (self::check($name) == false); + return !self::check($name); } self::_setError(2, __d('cake_dev', "%s doesn't exist", $name)); return false; diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index f75c5330b..88fa97661 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -332,7 +332,7 @@ class Mysql extends DboSource { return parent::update($model, $fields, $values, $conditions); } - if ($values == null) { + if (!$values) { $combined = $fields; } else { $combined = array_combine($fields, $values); diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index cac97e6c0..ec0b91167 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -983,7 +983,7 @@ class DboSource extends DataSource { public function create(Model $model, $fields = null, $values = null) { $id = null; - if ($fields == null) { + if (!$fields) { unset($fields, $values); $fields = array_keys($model->data); $values = array_values($model->data); @@ -1820,7 +1820,7 @@ class DboSource extends DataSource { * @return boolean Success */ public function update(Model $model, $fields = array(), $values = null, $conditions = null) { - if ($values == null) { + if (!$values) { $combined = $fields; } else { $combined = array_combine($fields, $values); diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 515f2e5b3..abb218a4f 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -716,7 +716,7 @@ class Model extends Object implements CakeEventListener { $this->useTable = Inflector::tableize($this->name); } - if ($this->displayField == null) { + if (!$this->displayField) { unset($this->displayField); } $this->table = $this->useTable; @@ -1443,7 +1443,7 @@ class Model extends Object implements CakeEventListener { * or false if none $field exist. */ public function getVirtualField($field = null) { - if ($field == null) { + if (!$field) { return empty($this->virtualFields) ? false : $this->virtualFields; } if ($this->isVirtualField($field)) { @@ -3197,7 +3197,7 @@ class Model extends Object implements CakeEventListener { * @return array Associations */ public function getAssociated($type = null) { - if ($type == null) { + if (!$type) { $associated = array(); foreach ($this->_associations as $assoc) { if (!empty($this->{$assoc})) { diff --git a/lib/Cake/Model/Permission.php b/lib/Cake/Model/Permission.php index b7c92d1a7..e293aa19b 100644 --- a/lib/Cake/Model/Permission.php +++ b/lib/Cake/Model/Permission.php @@ -81,7 +81,7 @@ class Permission extends AppModel { * @return boolean Success (true if ARO has access to action in ACO, false otherwise) */ public function check($aro, $aco, $action = "*") { - if ($aro == null || $aco == null) { + if (!$aro || !$aco) { return false; } @@ -89,12 +89,12 @@ class Permission extends AppModel { $aroPath = $this->Aro->node($aro); $acoPath = $this->Aco->node($aco); - if (empty($aroPath) || empty($acoPath)) { + if (!$aroPath || !$acoPath) { trigger_error(__d('cake_dev', "DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: ") . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING); return false; } - if ($acoPath == null || $acoPath == array()) { + if (!$acoPath) { trigger_error(__d('cake_dev', "DbAcl::check() - Failed ACO node lookup in permissions check. Node references:\nAro: ") . print_r($aro, true) . "\nAco: " . print_r($aco, true), E_USER_WARNING); return false; } @@ -171,7 +171,7 @@ class Permission extends AppModel { $permKeys = $this->getAcoKeys($this->schema()); $save = array(); - if ($perms == false) { + if (!$perms) { trigger_error(__d('cake_dev', 'DbAcl::allow() - Invalid node'), E_USER_WARNING); return false; } diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 7d49fdff6..386fde7ac 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -789,7 +789,7 @@ class CakeResponse { unset($this->_cacheDirectives['public']); $this->maxAge($time); } - if ($time == null) { + if (!$time) { $this->_setCacheControl(); } return (bool)$public; diff --git a/lib/Cake/Network/Http/HttpResponse.php b/lib/Cake/Network/Http/HttpResponse.php index dec507041..08b5598f9 100644 --- a/lib/Cake/Network/Http/HttpResponse.php +++ b/lib/Cake/Network/Http/HttpResponse.php @@ -361,7 +361,7 @@ class HttpResponse implements ArrayAccess { $escape[] = chr(127); } - if ($hex == false) { + if (!$hex) { return $escape; } foreach ($escape as $key => $char) { diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 502505676..21882b498 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -944,7 +944,7 @@ class HttpSocket extends CakeSocket { $escape[] = chr(127); } - if ($hex == false) { + if (!$hex) { return $escape; } foreach ($escape as $key => $char) { diff --git a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php index d5998ecda..066e7c0f7 100644 --- a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php +++ b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php @@ -200,7 +200,7 @@ class CakeFixtureManager { return; } $fixtures = $test->fixtures; - if (empty($fixtures) || $test->autoFixtures == false) { + if (empty($fixtures) || !$test->autoFixtures) { return; } diff --git a/lib/Cake/Utility/File.php b/lib/Cake/Utility/File.php index edf2dfbf3..a3cd6b03d 100644 --- a/lib/Cake/Utility/File.php +++ b/lib/Cake/Utility/File.php @@ -302,7 +302,7 @@ class File { * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::info */ public function info() { - if ($this->info == null) { + if (!$this->info) { $this->info = pathinfo($this->path); } if (!isset($this->info['filename'])) { @@ -324,7 +324,7 @@ class File { * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::ext */ public function ext() { - if ($this->info == null) { + if (!$this->info) { $this->info(); } if (isset($this->info['extension'])) { @@ -340,7 +340,7 @@ class File { * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::name */ public function name() { - if ($this->info == null) { + if (!$this->info) { $this->info(); } if (isset($this->info['extension'])) { diff --git a/lib/Cake/Utility/Folder.php b/lib/Cake/Utility/Folder.php index a5b2a9493..37d0e53ce 100644 --- a/lib/Cake/Utility/Folder.php +++ b/lib/Cake/Utility/Folder.php @@ -23,7 +23,7 @@ class Folder { /** * Default scheme for Folder::copy - * Recursively merges subfolders with the same name + * Recursively merges subfolders with the same name * * @constant MERGE */ @@ -425,7 +425,7 @@ class Folder { * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::tree */ public function tree($path = null, $exceptions = false, $type = null) { - if ($path == null) { + if (!$path) { $path = $this->path; } $files = array(); diff --git a/lib/Cake/Utility/Security.php b/lib/Cake/Utility/Security.php index 84369e04d..dde26242a 100644 --- a/lib/Cake/Utility/Security.php +++ b/lib/Cake/Utility/Security.php @@ -108,7 +108,7 @@ class Security { } } - if ($type == 'sha1' || $type == null) { + if (!$type || $type == 'sha1') { if (function_exists('sha1')) { $return = sha1($string); return $return; diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 1f5933353..7ff039331 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -500,7 +500,7 @@ class Helper extends Object { // Either 'body' or 'date.month' type inputs. if ( - ($count === 1 && $this->_modelScope && $setScope == false) || + ($count === 1 && $this->_modelScope && !$setScope) || ( $count === 2 && in_array($lastPart, $this->_fieldSuffixes) && diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index a1066a15d..592d3eab1 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -409,7 +409,7 @@ class FormHelper extends AppHelper { $action = $this->url($options['action']); unset($options['type'], $options['action']); - if ($options['default'] == false) { + if (!$options['default']) { if (!isset($options['onsubmit'])) { $options['onsubmit'] = ''; } diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 8cf545748..57bc376b9 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -359,7 +359,7 @@ class HtmlHelper extends AppHelper { $confirmMessage = str_replace("'", "\'", $confirmMessage); $confirmMessage = str_replace('"', '\"', $confirmMessage); $options['onclick'] = "return confirm('{$confirmMessage}');"; - } elseif (isset($options['default']) && $options['default'] == false) { + } elseif (isset($options['default']) && !$options['default']) { if (isset($options['onclick'])) { $options['onclick'] .= ' event.returnValue = false; return false;'; } else { @@ -441,7 +441,7 @@ class HtmlHelper extends AppHelper { if ($rel == 'import') { $out = sprintf($this->_tags['style'], $this->_parseAttributes($options, array('inline', 'block'), '', ' '), '@import url(' . $url . ');'); } else { - if ($rel == null) { + if (!$rel) { $rel = 'stylesheet'; } $out = sprintf($this->_tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline', 'block'), '', ' ')); diff --git a/lib/Cake/View/Helper/JsHelper.php b/lib/Cake/View/Helper/JsHelper.php index 00cf1756d..8bce3f87a 100644 --- a/lib/Cake/View/Helper/JsHelper.php +++ b/lib/Cake/View/Helper/JsHelper.php @@ -338,7 +338,7 @@ class JsHelper extends AppHelper { } else { $data = array($one => $two); } - if ($data == null) { + if (!$data) { return false; } $this->_jsVars = array_merge($this->_jsVars, $data); diff --git a/lib/Cake/View/Helper/SessionHelper.php b/lib/Cake/View/Helper/SessionHelper.php index 2bb983c47..de036c97f 100644 --- a/lib/Cake/View/Helper/SessionHelper.php +++ b/lib/Cake/View/Helper/SessionHelper.php @@ -134,7 +134,7 @@ class SessionHelper extends AppHelper { $class = $flash['params']['class']; } $out = '
' . $message . '
'; - } elseif ($flash['element'] == '' || $flash['element'] == null) { + } elseif (!$flash['element']) { $out = $message; } else { $options = array(); diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 9e0bafb91..46eec3151 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -757,7 +757,7 @@ class View extends Object { } else { $data = array($one => $two); } - if ($data == null) { + if (!$data) { return false; } $this->viewVars = $data + $this->viewVars; From 22a2e1b51e6b5cbbfadd0b44365826053b8d6f4f Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 18:42:25 +0100 Subject: [PATCH 02/10] converting $foo == / $foo == 0 to !$foo (and a few $foo === 0) --- lib/Cake/Cache/Engine/ApcEngine.php | 5 ++--- .../Console/Command/Task/ControllerTask.php | 4 ++-- .../Console/Command/Task/DbConfigTask.php | 20 +++++++++---------- lib/Cake/Console/Command/Task/ExtractTask.php | 4 ++-- lib/Cake/Console/Command/Task/ModelTask.php | 13 ++++++------ lib/Cake/Console/Command/Task/ProjectTask.php | 7 ++----- lib/Cake/Console/Command/Task/ViewTask.php | 4 ++-- lib/Cake/Console/ConsoleErrorHandler.php | 2 +- lib/Cake/Controller/Component/Acl/PhpAcl.php | 4 ++-- .../Controller/Component/CookieComponent.php | 2 +- lib/Cake/Error/ExceptionRenderer.php | 6 +++--- lib/Cake/I18n/I18n.php | 2 +- lib/Cake/Model/Behavior/TreeBehavior.php | 2 +- lib/Cake/Model/Datasource/Database/Mysql.php | 2 +- .../Model/Datasource/Database/Sqlserver.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 2 +- lib/Cake/Model/Model.php | 2 +- lib/Cake/Network/Http/HttpResponse.php | 2 +- lib/Cake/Routing/Dispatcher.php | 2 +- lib/Cake/TestSuite/CakeTestSuiteCommand.php | 2 +- .../TestSuite/Reporter/CakeTextReporter.php | 6 +++--- lib/Cake/Utility/CakeNumber.php | 2 +- lib/Cake/Utility/CakeTime.php | 4 ++-- lib/Cake/Utility/Debugger.php | 2 +- lib/Cake/Utility/String.php | 2 +- lib/Cake/Utility/Validation.php | 4 ++-- lib/Cake/View/Helper/FormHelper.php | 2 +- lib/Cake/View/Helper/HtmlHelper.php | 6 +++--- lib/Cake/View/Helper/PaginatorHelper.php | 2 +- 29 files changed, 57 insertions(+), 62 deletions(-) diff --git a/lib/Cake/Cache/Engine/ApcEngine.php b/lib/Cake/Cache/Engine/ApcEngine.php index 7b93cbb0c..58b035af2 100644 --- a/lib/Cake/Cache/Engine/ApcEngine.php +++ b/lib/Cake/Cache/Engine/ApcEngine.php @@ -61,9 +61,8 @@ class ApcEngine extends CacheEngine { * @return boolean True if the data was successfully cached, false on failure */ public function write($key, $value, $duration) { - if ($duration == 0) { - $expires = 0; - } else { + $expires = 0; + if ($duration) { $expires = time() + $duration; } apc_store($key . '_expires', $expires, $duration); diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 8feecc1a5..567e288c8 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -419,14 +419,14 @@ class ControllerTask extends BakeTask { $controllers = $this->listAll($useDbConfig); $enteredController = ''; - while ($enteredController == '') { + while (!$enteredController) { $enteredController = $this->in(__d('cake_console', "Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q'); if ($enteredController === 'q') { $this->out(__d('cake_console', 'Exit')); return $this->_stop(); } - if ($enteredController == '' || intval($enteredController) > count($controllers)) { + if (!$enteredController || intval($enteredController) > count($controllers)) { $this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again.")); $enteredController = ''; } diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index d8be6303d..f952fbbd4 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -95,7 +95,7 @@ class DbConfigTask extends AppShell { while (!$done) { $name = ''; - while ($name == '') { + while (!$name) { $name = $this->in(__d('cake_console', "Name:"), null, 'default'); if (preg_match('/[^a-z0-9_]/i', $name)) { $name = ''; @@ -116,12 +116,12 @@ class DbConfigTask extends AppShell { } $host = ''; - while ($host == '') { + while (!$host) { $host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost'); } $port = ''; - while ($port == '') { + while (!$port) { $port = $this->in(__d('cake_console', 'Port?'), null, 'n'); } @@ -130,16 +130,16 @@ class DbConfigTask extends AppShell { } $login = ''; - while ($login == '') { + while (!$login) { $login = $this->in(__d('cake_console', 'User:'), null, 'root'); } $password = ''; $blankPassword = false; - while ($password == '' && !$blankPassword) { + while (!$password && !$blankPassword) { $password = $this->in(__d('cake_console', 'Password:')); - if ($password == '') { + if (!$password) { $blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n'); if ($blank == 'y') { $blankPassword = true; @@ -148,12 +148,12 @@ class DbConfigTask extends AppShell { } $database = ''; - while ($database == '') { + while (!$database) { $database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake'); } $prefix = ''; - while ($prefix == '') { + while (!$prefix) { $prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n'); } if (strtolower($prefix) == 'n') { @@ -161,7 +161,7 @@ class DbConfigTask extends AppShell { } $encoding = ''; - while ($encoding == '') { + while (!$encoding) { $encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n'); } if (strtolower($encoding) == 'n') { @@ -170,7 +170,7 @@ class DbConfigTask extends AppShell { $schema = ''; if ($datasource == 'postgres') { - while ($schema == '') { + while (!$schema) { $schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n'); } } diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 8d0777be9..37af29d49 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -391,7 +391,7 @@ class ExtractTask extends AppShell { $position = $count; $depth = 0; - while ($depth == 0) { + while (!$depth) { if ($this->_tokens[$position] == '(') { $depth++; } elseif ($this->_tokens[$position] == ')') { @@ -591,7 +591,7 @@ class ExtractTask extends AppShell { ); if (strtoupper($response) === 'N') { $response = ''; - while ($response == '') { + while (!$response) { $response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename); $File = new File($this->_output . $response); $filename = $response; diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index cc7a5b3f5..b13330d6f 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -700,7 +700,7 @@ class ModelTask extends BakeTask { $alias = $this->in(__d('cake_console', 'What is the alias for this association?')); $className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias ); - if ($assocType == 0) { + if (!$assocType) { if (!empty($possibleKeys[$model->table])) { $showKeys = $possibleKeys[$model->table]; } else { @@ -935,7 +935,7 @@ class ModelTask extends BakeTask { $enteredModel = ''; - while ($enteredModel == '') { + while (!$enteredModel) { $enteredModel = $this->in(__d('cake_console', "Enter a number from the list above,\n" . "type in the name of another model, or 'q' to exit"), null, 'q'); @@ -944,18 +944,17 @@ class ModelTask extends BakeTask { $this->_stop(); } - if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) { + if (!$enteredModel || intval($enteredModel) > count($this->_modelNames)) { $this->err(__d('cake_console', "The model name you supplied was empty,\n" . "or the number you selected was not an option. Please try again.")); $enteredModel = ''; } } if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) { - $currentModelName = $this->_modelNames[intval($enteredModel) - 1]; - } else { - $currentModelName = $enteredModel; + return $this->_modelNames[intval($enteredModel) - 1]; } - return $currentModelName; + + return $enteredModel; } /** diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index 3935a826d..769ec5e1d 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/lib/Cake/Console/Command/Task/ProjectTask.php @@ -349,10 +349,7 @@ class ProjectTask extends AppShell { if (!file_put_contents($filename, $result)) { return false; } - if ($count == 0) { - return false; - } - return true; + return (bool)$count; } /** @@ -409,7 +406,7 @@ class ProjectTask extends AppShell { $this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/core.php to use prefix routing.')); $this->out(__d('cake_console', 'What would you like the prefix route to be?')); $this->out(__d('cake_console', 'Example: www.example.com/admin/controller')); - while ($admin == '') { + while (!$admin) { $admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin'); } if ($this->cakeAdmin($admin) !== true) { diff --git a/lib/Cake/Console/Command/Task/ViewTask.php b/lib/Cake/Console/Command/Task/ViewTask.php index 8baf4263e..2854c4aa8 100644 --- a/lib/Cake/Console/Command/Task/ViewTask.php +++ b/lib/Cake/Console/Command/Task/ViewTask.php @@ -316,9 +316,9 @@ class ViewTask extends BakeTask { */ public function customAction() { $action = ''; - while ($action == '') { + while (!$action) { $action = $this->in(__d('cake_console', 'Action Name? (use lowercase_underscored function name)')); - if ($action == '') { + if (!$action) { $this->out(__d('cake_console', 'The action name you supplied was empty. Please try again.')); } } diff --git a/lib/Cake/Console/ConsoleErrorHandler.php b/lib/Cake/Console/ConsoleErrorHandler.php index 043c62125..3000911ef 100644 --- a/lib/Cake/Console/ConsoleErrorHandler.php +++ b/lib/Cake/Console/ConsoleErrorHandler.php @@ -81,7 +81,7 @@ class ConsoleErrorHandler { $message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line); $stderr->write(__d('cake_console', "%s Error: %s\n", $name, $message)); - if (Configure::read('debug') == 0) { + if (!Configure::read('debug')) { CakeLog::write($log, $message); } } diff --git a/lib/Cake/Controller/Component/Acl/PhpAcl.php b/lib/Cake/Controller/Component/Acl/PhpAcl.php index 6540b935b..eef48e976 100644 --- a/lib/Cake/Controller/Component/Acl/PhpAcl.php +++ b/lib/Cake/Controller/Component/Acl/PhpAcl.php @@ -170,11 +170,11 @@ class PhpAcl extends Object implements AclInterface { foreach ($path as $depth => $node) { foreach ($prioritizedAros as $aros) { if (!empty($node['allow'])) { - $allow = $allow || count(array_intersect($node['allow'], $aros)) > 0; + $allow = $allow || count(array_intersect($node['allow'], $aros)); } if (!empty($node['deny'])) { - $allow = $allow && count(array_intersect($node['deny'], $aros)) == 0; + $allow = $allow && !count(array_intersect($node['deny'], $aros)); } } } diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index 45551a8af..48ab51440 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -381,7 +381,7 @@ class CookieComponent extends Component { } $this->_reset = $this->_expires; - if ($expires == 0) { + if (!$expires) { return $this->_expires = 0; } diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index fb55b3ad6..c45a1e2b7 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -119,7 +119,7 @@ class ExceptionRenderer { } } - if (Configure::read('debug') == 0) { + if (!Configure::read('debug')) { if ($method == '_cakeError') { $method = 'error400'; } @@ -205,7 +205,7 @@ class ExceptionRenderer { */ public function error400($error) { $message = $error->getMessage(); - if (Configure::read('debug') == 0 && $error instanceof CakeException) { + if (!Configure::read('debug') && $error instanceof CakeException) { $message = __d('cake', 'Not Found'); } $url = $this->controller->request->here(); @@ -227,7 +227,7 @@ class ExceptionRenderer { */ public function error500($error) { $message = $error->getMessage(); - if (Configure::read('debug') == 0) { + if (!Configure::read('debug')) { $message = __d('cake', 'An Internal Error Has Occurred.'); } $url = $this->controller->request->here(); diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 7678ba6ae..e79b7a9f8 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -412,7 +412,7 @@ class I18n { $header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header); extract($header); - if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) { + if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && !$version) { for ($n = 0; $n < $count; $n++) { $r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8)); $msgid = substr($data, $r["offs"], $r["len"]); diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index af6957444..83c7045ea 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -798,7 +798,7 @@ class TreeBehavior extends ModelBehavior { $scope, 'OR' => array($Model->escapeField($left) => $i, $Model->escapeField($right) => $i) ))); if ($count != 1) { - if ($count == 0) { + if (!$count) { $errors[] = array('index', $i, 'missing'); } else { $errors[] = array('index', $i, 'duplicate'); diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 88fa97661..f32c05bf4 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -433,7 +433,7 @@ class Mysql extends DboSource { if (!isset($index[$idx->Key_name]['column'])) { $col = array(); $index[$idx->Key_name]['column'] = $idx->Column_name; - $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); + $index[$idx->Key_name]['unique'] = intval(!$idx->Non_unique); } else { if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) { $col[] = $index[$idx->Key_name]['column']; diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 48b50a253..cb502832b 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -732,7 +732,7 @@ class Sqlserver extends DboSource { */ protected function _execute($sql, $params = array(), $prepareOptions = array()) { $this->_lastAffected = false; - if (strncasecmp($sql, 'SELECT', 6) == 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) { + if (strncasecmp($sql, 'SELECT', 6) === 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) { $prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL); return parent::_execute($sql, $params, $prepareOptions); } diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index ec0b91167..3c358f401 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1053,7 +1053,7 @@ class DboSource extends DataSource { if ($model->recursive == -1) { $_associations = array(); - } elseif ($model->recursive == 0) { + } elseif (!$model->recursive) { unset($_associations[2], $_associations[3]); } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index abb218a4f..ef987e6ee 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2980,7 +2980,7 @@ class Model extends Object implements CakeEventListener { if (!empty($this->id)) { $fields[$this->alias . '.' . $this->primaryKey . ' !='] = $this->id; } - return ($this->find('count', array('conditions' => $fields, 'recursive' => -1)) == 0); + return !$this->find('count', array('conditions' => $fields, 'recursive' => -1)); } /** diff --git a/lib/Cake/Network/Http/HttpResponse.php b/lib/Cake/Network/Http/HttpResponse.php index 08b5598f9..3be27aad3 100644 --- a/lib/Cake/Network/Http/HttpResponse.php +++ b/lib/Cake/Network/Http/HttpResponse.php @@ -108,7 +108,7 @@ class HttpResponse implements ArrayAccess { return $headers[$name]; } foreach ($headers as $key => $value) { - if (strcasecmp($key, $name) == 0) { + if (strcasecmp($key, $name) === 0) { return $value; } } diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index b10fe4ebb..3a56d87e5 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -209,7 +209,7 @@ class Dispatcher implements CakeEventListener { public function parseParams($event) { $request = $event->data['request']; Router::setRequestInfo($request); - if (count(Router::$routes) == 0) { + if (!count(Router::$routes)) { $namedExpressions = Router::getNamedExpressions(); extract($namedExpressions); $this->_loadRoutes(); diff --git a/lib/Cake/TestSuite/CakeTestSuiteCommand.php b/lib/Cake/TestSuite/CakeTestSuiteCommand.php index 6d410ec79..d7ba59337 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteCommand.php +++ b/lib/Cake/TestSuite/CakeTestSuiteCommand.php @@ -73,7 +73,7 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command { ); } - if (count($suite) == 0) { + if (!count($suite)) { $skeleton = new PHPUnit_Util_Skeleton_Test( $suite->getName(), $this->arguments['testFile'] diff --git a/lib/Cake/TestSuite/Reporter/CakeTextReporter.php b/lib/Cake/TestSuite/Reporter/CakeTextReporter.php index 1c8c20142..e127f1d02 100644 --- a/lib/Cake/TestSuite/Reporter/CakeTextReporter.php +++ b/lib/Cake/TestSuite/Reporter/CakeTextReporter.php @@ -71,10 +71,10 @@ class CakeTextReporter extends CakeBaseReporter { * @return void */ public function paintFooter($result) { - if ($result->failureCount() + $result->errorCount() == 0) { - echo "\nOK\n"; - } else { + if ($result->failureCount() + $result->errorCount()) { echo "FAILURES!!!\n"; + } else { + echo "\nOK\n"; } echo "Test cases run: " . $result->count() . diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 3b21cbc36..3bc49cb64 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -241,7 +241,7 @@ class CakeNumber { $result = $options['before'] = $options['after'] = null; $symbolKey = 'whole'; - if ($number == 0 ) { + if (!$number) { if ($options['zero'] !== 0 ) { return $options['zero']; } diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 53db5688d..f8f92fd79 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -766,7 +766,7 @@ class CakeTime { } } - if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) { + if (!$months && $years >= 1 && $diff < ($years * 31536000)) { $months = 11; $years--; } @@ -795,7 +795,7 @@ class CakeTime { } $diff = $futureTime - $pastTime; - if ($diff == 0) { + if (!$diff) { return __d('cake', 'just now', 'just now'); } diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 71638f334..933244a77 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -475,7 +475,7 @@ class Debugger { case 'float': return '(float) ' . $var; case 'string': - if (trim($var) == '') { + if (!trim($var)) { return "''"; } return "'" . $var . "'"; diff --git a/lib/Cake/Utility/String.php b/lib/Cake/Utility/String.php index 026286f58..2a8fb7293 100644 --- a/lib/Cake/Utility/String.php +++ b/lib/Cake/Utility/String.php @@ -134,7 +134,7 @@ class String { } if ($tmpOffset !== -1) { $buffer .= substr($data, $offset, ($tmpOffset - $offset)); - if ($data{$tmpOffset} == $separator && $depth == 0) { + if (!$depth && $data{$tmpOffset} == $separator) { $results[] = $buffer; $buffer = ''; } else { diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 43347e37d..f5b77f798 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -859,7 +859,7 @@ class Validation { if ($deep !== true) { return true; } - if ($check == 0) { + if (!$check) { return false; } $sum = 0; @@ -874,7 +874,7 @@ class Validation { $sum += ($number < 10) ? $number : $number - 9; } - return ($sum % 10 == 0); + return ($sum % 10 === 0); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 592d3eab1..d9b5b6a8d 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2228,7 +2228,7 @@ class FormHelper extends AppHelper { } elseif ($time[0] >= 12) { $meridian = 'pm'; } - if ($time[0] == 0 && $timeFormat == '12') { + if (!$time[0] && $timeFormat == '12') { $time[0] = 12; } $hour = $min = null; diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 57bc376b9..c4da2a8a9 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -701,7 +701,7 @@ class HtmlHelper extends AppHelper { } else { $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]); } - if ($which == 0) { + if (!$which) { $options['class'] = 'first'; } elseif ($which == $crumbCount - 1) { $options['class'] = 'last'; @@ -1116,9 +1116,9 @@ class HtmlHelper extends AppHelper { if (is_array($item)) { $item = $key . $this->nestedList($item, $options, $itemOptions, $tag); } - if (isset($itemOptions['even']) && $index % 2 == 0) { + if (isset($itemOptions['even']) && $index % 2 === 0) { $itemOptions['class'] = $itemOptions['even']; - } elseif (isset($itemOptions['odd']) && $index % 2 != 0) { + } elseif (isset($itemOptions['odd']) && $index % 2 !== 0) { $itemOptions['class'] = $itemOptions['odd']; } $out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item); diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 05a9935b1..207bad137 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -583,7 +583,7 @@ class PaginatorHelper extends AppHelper { $options); $paging = $this->params($options['model']); - if ($paging['pageCount'] == 0) { + if (!$paging['pageCount']) { $paging['pageCount'] = 1; } $start = 0; From 5cc03ca80524c1d8805baf2e3f7923397ca29d3a Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 18:54:29 +0100 Subject: [PATCH 03/10] converting if($foo == true) to if($foo) --- lib/Cake/Console/Command/ConsoleShell.php | 14 +++++++------- lib/Cake/Console/Command/Task/ControllerTask.php | 2 +- lib/Cake/Console/Command/Task/DbConfigTask.php | 6 +----- lib/Cake/Console/Command/Task/ModelTask.php | 10 ++++------ lib/Cake/Network/CakeSocket.php | 2 +- lib/Cake/Routing/Router.php | 2 +- lib/Cake/Test/Case/Network/CakeRequestTest.php | 2 +- lib/Cake/View/Helper/CacheHelper.php | 2 +- lib/Cake/View/Helper/FormHelper.php | 4 ++-- lib/Cake/View/Helper/PaginatorHelper.php | 7 +------ 10 files changed, 20 insertions(+), 31 deletions(-) diff --git a/lib/Cake/Console/Command/ConsoleShell.php b/lib/Cake/Console/Command/ConsoleShell.php index d8c79c933..66d286c03 100644 --- a/lib/Cake/Console/Command/ConsoleShell.php +++ b/lib/Cake/Console/Command/ConsoleShell.php @@ -182,7 +182,7 @@ class ConsoleShell extends AppShell { $this->out(" - {$model}"); } break; - case (preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp) == true): + case preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp): foreach ($tmp as $data) { $data = strip_tags($data); $data = str_replace($this->badCommandChars, "", $data); @@ -200,7 +200,7 @@ class ConsoleShell extends AppShell { $this->out(__d('cake_console', "Please verify you are using valid models and association types")); } break; - case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true): + case preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp): foreach ($tmp as $data) { $data = strip_tags($data); $data = str_replace($this->badCommandChars, "", $data); @@ -298,7 +298,7 @@ class ConsoleShell extends AppShell { $this->out(__d('cake_console', 'Saved record for %s', $modelToSave)); } break; - case (preg_match("/^(\w+) columns/", $command, $tmp) == true): + case preg_match("/^(\w+) columns/", $command, $tmp): $modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1])); if ($this->_isValidModel($modelToCheck)) { @@ -315,22 +315,22 @@ class ConsoleShell extends AppShell { $this->out(__d('cake_console', "Please verify that you selected a valid model")); } break; - case (preg_match("/^routes\s+reload/i", $command, $tmp) == true): + case preg_match("/^routes\s+reload/i", $command, $tmp): if (!$this->_loadRoutes()) { $this->err(__d('cake_console', "There was an error loading the routes config. Please check that the file exists and is free of parse errors.")); break; } $this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes))); break; - case (preg_match("/^routes\s+show/i", $command, $tmp) == true): + case preg_match("/^routes\s+show/i", $command, $tmp): $this->out(print_r(Hash::combine(Router::$routes, '{n}.template', '{n}.defaults'), true)); break; - case (preg_match("/^route\s+(\(.*\))$/i", $command, $tmp) == true): + case preg_match("/^route\s+(\(.*\))$/i", $command, $tmp): if ($url = eval('return array' . $tmp[1] . ';')) { $this->out(Router::url($url)); } break; - case (preg_match("/^route\s+(.*)/i", $command, $tmp) == true): + case preg_match("/^route\s+(.*)/i", $command, $tmp): $this->out(var_export(Router::parse($tmp[1]), true)); break; default: diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 567e288c8..657274aa0 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -395,7 +395,7 @@ class ControllerTask extends BakeTask { } $this->__tables = $this->Model->getAllTables($useDbConfig); - if ($this->interactive == true) { + if ($this->interactive) { $this->out(__d('cake_console', 'Possible Controllers based on your current database:')); $this->hr(); $this->_controllerNames = array(); diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index f952fbbd4..bd732fe96 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -277,11 +277,7 @@ class DbConfigTask extends AppShell { $info['port'] = null; } - if ($info['persistent'] === false) { - $info['persistent'] = 'false'; - } else { - $info['persistent'] = ($info['persistent'] == true) ? 'true' : 'false'; - } + $info['persistent'] = var_export((bool)$info['persistent'], true); $oldConfigs[] = array( 'name' => $configName, diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index b13330d6f..5aa14d39e 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -472,16 +472,14 @@ class ModelTask extends BakeTask { } if ($choice != $defaultChoice) { + $validate[$validatorName] = $choice; if (is_numeric($choice) && isset($this->_validations[$choice])) { $validate[$validatorName] = $this->_validations[$choice]; - } else { - $validate[$validatorName] = $choice; } } - if ($this->interactive == true && $choice != $defaultChoice) { + $anotherValidator = 'n'; + if ($this->interactive && $choice != $defaultChoice) { $anotherValidator = $this->in(__d('cake_console', 'Would you like to add another validation rule?'), array('y', 'n'), 'n'); - } else { - $anotherValidator = 'n'; } } return $validate; @@ -583,7 +581,7 @@ class ModelTask extends BakeTask { $pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/'; $possibleJoinTable = preg_match($pattern, $otherTable); - if ($possibleJoinTable == true) { + if ($possibleJoinTable) { continue; } foreach ($modelFieldsTemp as $fieldName => $field) { diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index 04f0302c4..aa5ab6dc8 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -130,7 +130,7 @@ class CakeSocket { $scheme = 'ssl://'; } - if ($this->config['persistent'] == true) { + if ($this->config['persistent']) { $this->connection = @pfsockopen($scheme . $this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); } else { $this->connection = @fsockopen($scheme . $this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 662ed0af0..4c6f35528 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -425,7 +425,7 @@ class Router { $options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options); } - if ($options['reset'] == true || self::$_namedConfig['rules'] === false) { + if ($options['reset'] || self::$_namedConfig['rules'] === false) { self::$_namedConfig['rules'] = array(); } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index ae64aad6e..1e3977bef 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -962,7 +962,7 @@ class CakeRequestTest extends CakeTestCase { * @return void */ public function detectCallback($request) { - return $request->return == true; + return (bool)$request->return; } /** diff --git a/lib/Cake/View/Helper/CacheHelper.php b/lib/Cake/View/Helper/CacheHelper.php index 2f85cd50b..3ebcea3f8 100644 --- a/lib/Cake/View/Helper/CacheHelper.php +++ b/lib/Cake/View/Helper/CacheHelper.php @@ -312,7 +312,7 @@ class CacheHelper extends AppHelper { Router::setRequestInfo($controller->request); $this->request = $request;'; - if ($useCallbacks == true) { + if ($useCallbacks) { $file .= ' $controller->constructClasses(); $controller->startupProcess();'; diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index d9b5b6a8d..f561b6ede 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1286,7 +1286,7 @@ class FormHelper extends AppHelper { 'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'), 'secure' => false ); - if (isset($options['disabled']) && $options['disabled'] == true) { + if (isset($options['disabled']) && $options['disabled']) { $hiddenOptions['disabled'] = 'disabled'; } $output = $this->hidden($fieldName, $hiddenOptions); @@ -1865,7 +1865,7 @@ class FormHelper extends AppHelper { if (!empty($tag) || isset($template)) { $hasOptions = (count($options) > 0 || $showEmpty); if ( - (!isset($secure) || $secure == true) && + (!isset($secure) || $secure) && empty($attributes['disabled']) && $hasOptions ) { diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 207bad137..836877345 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -526,12 +526,7 @@ class PaginatorHelper extends AppHelper { */ protected function _hasPage($model, $page) { $params = $this->params($model); - if (!empty($params)) { - if ($params["{$page}Page"] == true) { - return true; - } - } - return false; + return !empty($params) && $params[$page . 'Page']; } /** From cfadc4dbb00c124538138cdf728bb99249c6cd50 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 19:26:00 +0100 Subject: [PATCH 04/10] strict type checks and removing some duplicate count() calls by setting a variable --- lib/Cake/Console/Command/ApiShell.php | 9 +++++---- lib/Cake/Console/Command/Task/ExtractTask.php | 2 +- lib/Cake/Console/Command/Task/ProjectTask.php | 2 +- lib/Cake/Console/Command/Task/TemplateTask.php | 2 +- lib/Cake/Console/Command/Task/TestTask.php | 7 ++++--- lib/Cake/Console/Shell.php | 2 +- lib/Cake/Controller/Controller.php | 2 +- lib/Cake/Model/Datasource/Database/Mysql.php | 2 +- lib/Cake/Routing/Route/RedirectRoute.php | 2 +- lib/Cake/Utility/CakeTime.php | 2 +- lib/Cake/Utility/Set.php | 4 ++-- lib/Cake/View/Helper.php | 5 ++--- lib/Cake/basics.php | 13 ++++--------- 13 files changed, 25 insertions(+), 29 deletions(-) diff --git a/lib/Cake/Console/Command/ApiShell.php b/lib/Cake/Console/Command/ApiShell.php index 8ba50e7fb..44e36368f 100644 --- a/lib/Cake/Console/Command/ApiShell.php +++ b/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)) { diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 37af29d49..f6f9c560a 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/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); } diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index 769ec5e1d..d1dff2b9f 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/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) { diff --git a/lib/Cake/Console/Command/Task/TemplateTask.php b/lib/Cake/Console/Command/Task/TemplateTask.php index b9a7fba63..0a0366c5c 100644 --- a/lib/Cake/Console/Command/Task/TemplateTask.php +++ b/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]; } diff --git a/lib/Cake/Console/Command/Task/TestTask.php b/lib/Cake/Console/Command/Task/TestTask.php index 8c28aac35..e1da43c79 100644 --- a/lib/Cake/Console/Command/Task/TestTask.php +++ b/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('Done'); diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index 567aa731f..f23004e4a 100644 --- a/lib/Cake/Console/Shell.php +++ b/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]); } diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index cd8c801c2..4eb68f1b5 100644 --- a/lib/Cake/Controller/Controller.php +++ b/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'])) { diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index f32c05bf4..541bd87aa 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/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') { diff --git a/lib/Cake/Routing/Route/RedirectRoute.php b/lib/Cake/Routing/Route/RedirectRoute.php index bfb0f06c3..d890d2475 100644 --- a/lib/Cake/Routing/Route/RedirectRoute.php +++ b/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)) { diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index f8f92fd79..dd1570b6e 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/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--; } diff --git a/lib/Cake/Utility/Set.php b/lib/Cake/Utility/Set.php index 3bfa00882..6e1ffc6a0 100644 --- a/lib/Cake/Utility/Set.php +++ b/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); diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 7ff039331..d9296f09a 100644 --- a/lib/Cake/View/Helper.php +++ b/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 { diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index 434629562..30e5d0bca 100644 --- a/lib/Cake/basics.php +++ b/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; } } From f5a8eb6bbf0af71f431a944dd4dccf648bb75c02 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 14 Sep 2012 19:57:51 +0100 Subject: [PATCH 05/10] ADmads comments --- lib/Cake/Console/Command/ApiShell.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/ApiShell.php b/lib/Cake/Console/Command/ApiShell.php index 44e36368f..7a7b664e8 100644 --- a/lib/Cake/Console/Command/ApiShell.php +++ b/lib/Cake/Console/Command/ApiShell.php @@ -77,7 +77,7 @@ class ApiShell extends AppShell { if ($count > 1) { $file = Inflector::underscore($this->args[1]); $class = Inflector::camelize($this->args[1]); - } elseif($count) { + } elseif ($count) { $file = $type; $class = Inflector::camelize($type); } diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 3c358f401..14dbbfc7b 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1053,7 +1053,7 @@ class DboSource extends DataSource { if ($model->recursive == -1) { $_associations = array(); - } elseif (!$model->recursive) { + } elseif (!$model->recursive === 0) { unset($_associations[2], $_associations[3]); } From b1f26b59a39ea753b1557b2acd01248a412b2a95 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 21 Sep 2012 23:30:43 +0100 Subject: [PATCH 06/10] converting if ($foo != null) to if ($foo) --- .../Controller/Component/CookieComponent.php | 2 +- .../Component/RequestHandlerComponent.php | 4 ++-- lib/Cake/Controller/Controller.php | 17 ++++++------- lib/Cake/Model/Datasource/CakeSession.php | 2 +- lib/Cake/Model/Datasource/Database/Mysql.php | 4 ++-- .../Model/Datasource/Database/Postgres.php | 24 +++++++++---------- lib/Cake/Model/Datasource/Database/Sqlite.php | 18 +++++++------- .../Model/Datasource/Database/Sqlserver.php | 4 ++-- lib/Cake/Model/Datasource/DboSource.php | 9 ++++--- lib/Cake/Model/Model.php | 9 ++++--- lib/Cake/Model/Permission.php | 2 +- lib/Cake/Network/CakeRequest.php | 6 ++--- lib/Cake/Network/CakeSocket.php | 2 +- lib/Cake/Routing/Router.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 2 +- .../Test/Case/Network/Email/CakeEmailTest.php | 2 +- lib/Cake/Utility/CakeTime.php | 2 +- lib/Cake/Utility/Set.php | 2 +- lib/Cake/View/Helper/HtmlHelper.php | 5 ++-- lib/Cake/View/Helper/PaginatorHelper.php | 2 +- lib/Cake/View/Helper/RssHelper.php | 2 +- 21 files changed, 60 insertions(+), 62 deletions(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index 48ab51440..aef21bfe6 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -507,7 +507,7 @@ class CookieComponent extends Component { $first = substr($string, 0, 1); if ($first === '{' || $first === '[') { $ret = json_decode($string, true); - return ($ret != null) ? $ret : $string; + return ($ret) ? $ret : $string; } $array = array(); foreach (explode(',', $string) as $pair) { diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index d3147af00..f95411816 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -398,7 +398,7 @@ class RequestHandlerComponent extends Component { * @return string Prototype version of component making Ajax call */ public function getAjaxVersion() { - if (env('HTTP_X_PROTOTYPE_VERSION') != null) { + if (env('HTTP_X_PROTOTYPE_VERSION')) { return env('HTTP_X_PROTOTYPE_VERSION'); } return false; @@ -672,7 +672,7 @@ class RequestHandlerComponent extends Component { $cType = $type; } - if ($cType != null) { + if ($cType) { if (empty($this->request->params['requested'])) { $this->response->type($cType); } diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 4eb68f1b5..15bbc2e69 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -967,14 +967,15 @@ class Controller extends Object implements CakeEventListener { * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer */ public function referer($default = null, $local = false) { - if ($this->request) { - $referer = $this->request->referer($local); - if ($referer == '/' && $default != null) { - return Router::url($default, true); - } - return $referer; + if(!$this->request) { + return '/'; } - return '/'; + + $referer = $this->request->referer($local); + if ($referer == '/' && $default) { + return Router::url($default, true); + } + return $referer; } /** @@ -1062,7 +1063,7 @@ class Controller extends Object implements CakeEventListener { $cond[$key] = $value; } } - if ($bool != null && strtoupper($bool) != 'AND') { + if ($bool && strtoupper($bool) != 'AND') { $cond = array($bool => $cond); } return $cond; diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 6f8050f0f..4c0ff34a3 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -131,7 +131,7 @@ class CakeSession { self::$time = time(); $checkAgent = Configure::read('Session.checkAgent'); - if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT') != null) { + if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT')) { self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt')); } self::_setPath($base); diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 541bd87aa..02e315e6b 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -175,7 +175,7 @@ class Mysql extends DboSource { */ public function listSources($data = null) { $cache = parent::listSources(); - if ($cache != null) { + if ($cache) { return $cache; } $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database'])); @@ -280,7 +280,7 @@ class Mysql extends DboSource { public function describe($model) { $key = $this->fullTableName($model, false); $cache = parent::describe($key); - if ($cache != null) { + if ($cache) { return $cache; } $table = $this->fullTableName($model); diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 9b1fbcf3d..b284f79a6 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -146,7 +146,7 @@ class Postgres extends DboSource { public function listSources($data = null) { $cache = parent::listSources(); - if ($cache != null) { + if ($cache) { return $cache; } @@ -156,17 +156,17 @@ class Postgres extends DboSource { if (!$result) { return array(); - } else { - $tables = array(); - - foreach ($result as $item) { - $tables[] = $item->name; - } - - $result->closeCursor(); - parent::listSources($tables); - return $tables; } + + $tables = array(); + + foreach ($result as $item) { + $tables[] = $item->name; + } + + $result->closeCursor(); + parent::listSources($tables); + return $tables; } /** @@ -671,7 +671,7 @@ class Postgres extends DboSource { if ($col == 'uuid') { return 36; } - if ($limit != null) { + if ($limit) { return intval($limit); } return null; diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 0ca4bc2c3..34e52d256 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -136,7 +136,7 @@ class Sqlite extends DboSource { */ public function listSources($data = null) { $cache = parent::listSources(); - if ($cache != null) { + if ($cache) { return $cache; } @@ -144,14 +144,14 @@ class Sqlite extends DboSource { if (!$result || empty($result)) { return array(); - } else { - $tables = array(); - foreach ($result as $table) { - $tables[] = $table[0]['name']; - } - parent::listSources($tables); - return $tables; } + + $tables = array(); + foreach ($result as $table) { + $tables[] = $table[0]['name']; + } + parent::listSources($tables); + return $tables; } /** @@ -163,7 +163,7 @@ class Sqlite extends DboSource { public function describe($model) { $table = $this->fullTableName($model, false, false); $cache = parent::describe($table); - if ($cache != null) { + if ($cache) { return $cache; } $fields = array(); diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index cb502832b..e2dc00485 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -184,7 +184,7 @@ class Sqlserver extends DboSource { public function describe($model) { $table = $this->fullTableName($model, false); $cache = parent::describe($table); - if ($cache != null) { + if ($cache) { return $cache; } $fields = array(); @@ -619,7 +619,7 @@ class Sqlserver extends DboSource { */ public function insertMulti($table, $fields, $values) { $primaryKey = $this->_getPrimaryKey($table); - $hasPrimaryKey = $primaryKey != null && ( + $hasPrimaryKey = $primaryKey && ( (is_array($fields) && in_array($primaryKey, $fields) || (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false)) ); diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 14dbbfc7b..521080823 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -670,7 +670,7 @@ class DboSource extends DataSource { if ($this->hasResult()) { $first = $this->fetchRow(); - if ($first != null) { + if ($first) { $out[] = $first; } while ($item = $this->fetchResult()) { @@ -1407,10 +1407,9 @@ class DboSource extends DataSource { } } if (!isset($data[$association])) { - if ($merge[0][$association] != null) { + $data[$association] = array(); + if ($merge[0][$association]) { $data[$association] = $merge[0][$association]; - } else { - $data[$association] = array(); } } else { if (is_array($merge[0][$association])) { @@ -2513,7 +2512,7 @@ class DboSource extends DataSource { $data = $this->_parseKey($model, trim($key), $value); } - if ($data != null) { + if ($data) { $out[] = $data; $data = null; } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index ef987e6ee..462170371 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1389,7 +1389,7 @@ class Model extends Object implements CakeEventListener { $this->schema(); } - if ($this->_schema != null) { + if ($this->_schema) { return isset($this->_schema[$name]); } return false; @@ -1499,7 +1499,7 @@ class Model extends Object implements CakeEventListener { public function read($fields = null, $id = null) { $this->validationErrors = array(); - if ($id != null) { + if ($id) { $this->id = $id; } @@ -1515,9 +1515,8 @@ class Model extends Object implements CakeEventListener { 'fields' => $fields )); return $this->data; - } else { - return false; } + return false; } /** @@ -3151,7 +3150,7 @@ class Model extends Object implements CakeEventListener { public function setDataSource($dataSource = null) { $oldConfig = $this->useDbConfig; - if ($dataSource != null) { + if ($dataSource) { $this->useDbConfig = $dataSource; } $db = ConnectionManager::getDataSource($this->useDbConfig); diff --git a/lib/Cake/Model/Permission.php b/lib/Cake/Model/Permission.php index e293aa19b..7802703d1 100644 --- a/lib/Cake/Model/Permission.php +++ b/lib/Cake/Model/Permission.php @@ -198,7 +198,7 @@ class Permission extends AppModel { } list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']); - if ($perms['link'] != null && !empty($perms['link'])) { + if ($perms['link'] && !empty($perms['link'])) { $save['id'] = $perms['link'][0][$this->alias]['id']; } else { unset($save['id']); diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 919e380a3..ab53b4617 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -364,17 +364,17 @@ class CakeRequest implements ArrayAccess { * @return string The client IP. */ public function clientIp($safe = true) { - if (!$safe && env('HTTP_X_FORWARDED_FOR') != null) { + if (!$safe && env('HTTP_X_FORWARDED_FOR')) { $ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR')); } else { - if (env('HTTP_CLIENT_IP') != null) { + if (env('HTTP_CLIENT_IP')) { $ipaddr = env('HTTP_CLIENT_IP'); } else { $ipaddr = env('REMOTE_ADDR'); } } - if (env('HTTP_CLIENTADDRESS') != null) { + if (env('HTTP_CLIENTADDRESS')) { $tmpipaddr = env('HTTP_CLIENTADDRESS'); if (!empty($tmpipaddr)) { diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index aa5ab6dc8..941c0b261 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -121,7 +121,7 @@ class CakeSocket { * @throws SocketException */ public function connect() { - if ($this->connection != null) { + if ($this->connection) { $this->disconnect(); } diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 4c6f35528..e43ad97f6 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -1073,7 +1073,7 @@ class Router { * @return string base url with plugin name removed if present */ public static function stripPlugin($base, $plugin = null) { - if ($plugin != null) { + if ($plugin) { $base = preg_replace('/(?:' . $plugin . ')/', '', $base); $base = str_replace('//', '', $base); $pos1 = strrpos($base, '/'); diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 31327e7de..50d195794 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -58,7 +58,7 @@ class ModelWriteTest extends BaseModelTest { $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); $data['id'] = $lastInsertId; $this->assertEquals(array('JoinAsJoinB' => $data), $result); - $this->assertTrue($lastInsertId != null); + $this->assertTrue($lastInsertId); $result = $TestModel->JoinAsJoinB->findById(1); $expected = array( diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index ae19b80f0..1e21c5381 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -1164,7 +1164,7 @@ class CakeEmailTest extends CakeTestCase { $this->CakeEmail->emailFormat('html'); $server = env('SERVER_NAME') ? env('SERVER_NAME') : 'localhost'; - if (env('SERVER_PORT') != null && env('SERVER_PORT') != 80) { + if (env('SERVER_PORT') && env('SERVER_PORT') != 80) { $server .= ':' . env('SERVER_PORT'); } diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index dd1570b6e..e378627fa 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -903,7 +903,7 @@ class CakeTime { */ public static function gmt($dateString = null) { $time = time(); - if ($dateString != null) { + if ($dateString) { $time = self::fromString($dateString); } return gmmktime( diff --git a/lib/Cake/Utility/Set.php b/lib/Cake/Utility/Set.php index 6e1ffc6a0..5f1a9f445 100644 --- a/lib/Cake/Utility/Set.php +++ b/lib/Cake/Utility/Set.php @@ -827,7 +827,7 @@ class Set { } } - if ($groupPath != null) { + if ($groupPath) { $group = Set::extract($data, $groupPath); if (!empty($group)) { $c = count($keys); diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index c4da2a8a9..008965d4d 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -951,13 +951,12 @@ class HtmlHelper extends AppHelper { if (isset($options['escape'])) { $text = h($text); } - if ($class != null && !empty($class)) { + if ($class && !empty($class)) { $options['class'] = $class; } + $tag = 'para'; if ($text === null) { $tag = 'parastart'; - } else { - $tag = 'para'; } return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text); } diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 836877345..373c59679 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -536,7 +536,7 @@ class PaginatorHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel */ public function defaultModel() { - if ($this->_defaultModel != null) { + if ($this->_defaultModel) { return $this->_defaultModel; } if (empty($this->request->params['paging'])) { diff --git a/lib/Cake/View/Helper/RssHelper.php b/lib/Cake/View/Helper/RssHelper.php index 26160f055..0cbd456be 100644 --- a/lib/Cake/View/Helper/RssHelper.php +++ b/lib/Cake/View/Helper/RssHelper.php @@ -167,7 +167,7 @@ class RssHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::items */ public function items($items, $callback = null) { - if ($callback != null) { + if ($callback) { $items = array_map($callback, $items); } From 8dc4de5de8454a55b961def4efc5c47ffa6af0f6 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 21 Sep 2012 23:32:52 +0100 Subject: [PATCH 07/10] converting if ($foo != false) to if ($foo) --- lib/Cake/Controller/Component/EmailComponent.php | 2 +- lib/Cake/Controller/Scaffold.php | 2 +- lib/Cake/Model/Model.php | 2 +- lib/Cake/View/Helper/CacheHelper.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Controller/Component/EmailComponent.php b/lib/Cake/Controller/Component/EmailComponent.php index 702ec911d..18c25baa8 100644 --- a/lib/Cake/Controller/Component/EmailComponent.php +++ b/lib/Cake/Controller/Component/EmailComponent.php @@ -316,7 +316,7 @@ class EmailComponent extends Component { foreach ($this->headers as $key => $value) { $headers['X-' . $key] = $value; } - if ($this->date != false) { + if ($this->date) { $headers['Date'] = $this->date; } $lib->setHeaders($headers); diff --git a/lib/Cake/Controller/Scaffold.php b/lib/Cake/Controller/Scaffold.php index 854312686..434146eb4 100644 --- a/lib/Cake/Controller/Scaffold.php +++ b/lib/Cake/Controller/Scaffold.php @@ -146,7 +146,7 @@ class Scaffold { $this->controller->viewClass = 'Scaffold'; } $this->_validSession = ( - isset($this->controller->Session) && $this->controller->Session->valid() != false + isset($this->controller->Session) && $this->controller->Session->valid() ); $this->_scaffold($request); } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 462170371..7e9220f65 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2561,7 +2561,7 @@ class Model extends Object implements CakeEventListener { * @return boolean True if such a record exists */ public function hasAny($conditions = null) { - return ($this->find('count', array('conditions' => $conditions, 'recursive' => -1)) != false); + return (bool)$this->find('count', array('conditions' => $conditions, 'recursive' => -1)); } /** diff --git a/lib/Cake/View/Helper/CacheHelper.php b/lib/Cake/View/Helper/CacheHelper.php index 3ebcea3f8..c6328b72b 100644 --- a/lib/Cake/View/Helper/CacheHelper.php +++ b/lib/Cake/View/Helper/CacheHelper.php @@ -59,7 +59,7 @@ class CacheHelper extends AppHelper { * @return boolean */ protected function _enabled() { - return (($this->_View->cacheAction != false)) && (Configure::read('Cache.check') === true); + return $this->_View->cacheAction && (Configure::read('Cache.check') === true); } /** From 36314e6d37cf954e207d183f15705aecd85e55fe Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 21 Sep 2012 23:34:37 +0100 Subject: [PATCH 08/10] converting if ($foo != "") to if ($foo) --- lib/Cake/Model/Datasource/CakeSession.php | 2 +- lib/Cake/View/Helper.php | 2 +- lib/Cake/View/Helper/CacheHelper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 4c0ff34a3..3161066cf 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -663,7 +663,7 @@ class CakeSession { */ public static function renew() { if (session_id()) { - if (session_id() != '' || isset($_COOKIE[session_name()])) { + if (session_id() || isset($_COOKIE[session_name()])) { setcookie(Configure::read('Session.cookie'), '', time() - 42000, self::$path); } session_regenerate_id(true); diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index d9296f09a..ce597d52b 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -749,7 +749,7 @@ class Helper extends Object { * @return array Array of options with $key set. */ public function addClass($options = array(), $class = null, $key = 'class') { - if (isset($options[$key]) && trim($options[$key]) != '') { + if (isset($options[$key]) && trim($options[$key])) { $options[$key] .= ' ' . $class; } else { $options[$key] = $class; diff --git a/lib/Cake/View/Helper/CacheHelper.php b/lib/Cake/View/Helper/CacheHelper.php index c6328b72b..d4d40c376 100644 --- a/lib/Cake/View/Helper/CacheHelper.php +++ b/lib/Cake/View/Helper/CacheHelper.php @@ -148,7 +148,7 @@ class CacheHelper extends AppHelper { $cacheTime = $cacheAction; } - if ($cacheTime != '' && $cacheTime > 0) { + if ($cacheTime && $cacheTime > 0) { $cached = $this->_parseOutput($out); try { $this->_writeFile($cached, $cacheTime, $useCallbacks); From cd99b7d6ff335a5ef8d3e6609cbc09d4ef31be4d Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 21 Sep 2012 23:40:21 +0100 Subject: [PATCH 09/10] fixing error pointed out by dereuromark with recursive https://github.com/cakephp/cakephp/pull/846#commitcomment-1884073 --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 521080823..f168b5b8c 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1053,7 +1053,7 @@ class DboSource extends DataSource { if ($model->recursive == -1) { $_associations = array(); - } elseif (!$model->recursive === 0) { + } elseif ($model->recursive === 0) { unset($_associations[2], $_associations[3]); } From 1b3685335521251b3601787f5afea7d542b679bb Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 21 Sep 2012 23:49:24 +0100 Subject: [PATCH 10/10] undo the change to avoid change in behavior --- lib/Cake/Controller/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 15bbc2e69..88d50a914 100644 --- a/lib/Cake/Controller/Controller.php +++ b/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 (!empty($request->params['return']) && $request->params['return']) { + if (!empty($request->params['return']) && $request->params['return'] == 1) { $this->autoRender = false; } if (!empty($request->params['bare'])) {