Skip to content
Browse files

Merge pull request #911 from dogmatic69/type-checks

Type checks
  • Loading branch information...
2 parents 6fc019e + 641ba9f commit 2841611c0fc4815882a616f1723520d0df4c3764 @markstory markstory committed Oct 24, 2012
Showing with 211 additions and 234 deletions.
  1. +2 −3 lib/Cake/Cache/Engine/ApcEngine.php
  2. +1 −1 lib/Cake/Console/Command/AclShell.php
  3. +5 −4 lib/Cake/Console/Command/ApiShell.php
  4. +7 −7 lib/Cake/Console/Command/ConsoleShell.php
  5. +3 −3 lib/Cake/Console/Command/Task/ControllerTask.php
  6. +13 −17 lib/Cake/Console/Command/Task/DbConfigTask.php
  7. +3 −3 lib/Cake/Console/Command/Task/ExtractTask.php
  8. +10 −13 lib/Cake/Console/Command/Task/ModelTask.php
  9. +4 −7 lib/Cake/Console/Command/Task/ProjectTask.php
  10. +2 −2 lib/Cake/Console/Command/Task/TemplateTask.php
  11. +4 −3 lib/Cake/Console/Command/Task/TestTask.php
  12. +2 −2 lib/Cake/Console/Command/Task/ViewTask.php
  13. +1 −1 lib/Cake/Console/ConsoleErrorHandler.php
  14. +5 −5 lib/Cake/Console/Shell.php
  15. +1 −1 lib/Cake/Controller/Component/Acl/IniAcl.php
  16. +2 −2 lib/Cake/Controller/Component/Acl/PhpAcl.php
  17. +2 −2 lib/Cake/Controller/Component/CookieComponent.php
  18. +1 −1 lib/Cake/Controller/Component/EmailComponent.php
  19. +1 −1 lib/Cake/Controller/Component/SecurityComponent.php
  20. +11 −10 lib/Cake/Controller/Controller.php
  21. +1 −1 lib/Cake/Controller/Scaffold.php
  22. +1 −1 lib/Cake/Core/App.php
  23. +2 −2 lib/Cake/Error/ExceptionRenderer.php
  24. +1 −1 lib/Cake/I18n/I18n.php
  25. +1 −1 lib/Cake/Model/Behavior/TranslateBehavior.php
  26. +7 −9 lib/Cake/Model/Behavior/TreeBehavior.php
  27. +3 −3 lib/Cake/Model/Datasource/CakeSession.php
  28. +5 −4 lib/Cake/Model/Datasource/Database/Mysql.php
  29. +10 −10 lib/Cake/Model/Datasource/Database/Postgres.php
  30. +9 −9 lib/Cake/Model/Datasource/Database/Sqlite.php
  31. +3 −3 lib/Cake/Model/Datasource/Database/Sqlserver.php
  32. +7 −8 lib/Cake/Model/Datasource/DboSource.php
  33. +9 −10 lib/Cake/Model/Model.php
  34. +5 −5 lib/Cake/Model/Permission.php
  35. +3 −3 lib/Cake/Network/CakeRequest.php
  36. +1 −1 lib/Cake/Network/CakeResponse.php
  37. +2 −2 lib/Cake/Network/CakeSocket.php
  38. +2 −2 lib/Cake/Network/Http/HttpResponse.php
  39. +1 −1 lib/Cake/Network/Http/HttpSocket.php
  40. +1 −1 lib/Cake/Routing/Route/RedirectRoute.php
  41. +2 −2 lib/Cake/Routing/Router.php
  42. +1 −1 lib/Cake/Test/Case/Model/ModelWriteTest.php
  43. +1 −1 lib/Cake/Test/Case/Network/CakeRequestTest.php
  44. +1 −1 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
  45. +1 −1 lib/Cake/TestSuite/CakeTestSuiteCommand.php
  46. +1 −1 lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
  47. +3 −3 lib/Cake/TestSuite/Reporter/CakeTextReporter.php
  48. +2 −2 lib/Cake/Utility/CakeNumber.php
  49. +4 −4 lib/Cake/Utility/CakeTime.php
  50. +1 −1 lib/Cake/Utility/Debugger.php
  51. +3 −3 lib/Cake/Utility/File.php
  52. +1 −1 lib/Cake/Utility/Folder.php
  53. +1 −1 lib/Cake/Utility/Security.php
  54. +3 −3 lib/Cake/Utility/Set.php
  55. +1 −1 lib/Cake/Utility/String.php
  56. +2 −2 lib/Cake/Utility/Validation.php
  57. +4 −5 lib/Cake/View/Helper.php
  58. +3 −3 lib/Cake/View/Helper/CacheHelper.php
  59. +4 −4 lib/Cake/View/Helper/FormHelper.php
  60. +7 −8 lib/Cake/View/Helper/HtmlHelper.php
  61. +1 −1 lib/Cake/View/Helper/JsHelper.php
  62. +3 −8 lib/Cake/View/Helper/PaginatorHelper.php
  63. +1 −1 lib/Cake/View/Helper/RssHelper.php
  64. +1 −1 lib/Cake/View/Helper/SessionHelper.php
  65. +1 −1 lib/Cake/View/View.php
  66. +4 −9 lib/Cake/basics.php
View
5 lib/Cake/Cache/Engine/ApcEngine.php
@@ -61,9 +61,8 @@ public function init($settings = array()) {
* @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);
View
2 lib/Cake/Console/Command/AclShell.php
@@ -598,7 +598,7 @@ protected function _getParams() {
* @return array Variables
*/
protected function _dataVars($type = null) {
- if ($type == null) {
+ if (!$type) {
$type = $this->args[0];
}
$vars = array();
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
14 lib/Cake/Console/Command/ConsoleShell.php
@@ -182,7 +182,7 @@ public function main($command = null) {
$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 @@ public function main($command = null) {
$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 @@ public function main($command = null) {
$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 @@ public function main($command = null) {
$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:
View
6 lib/Cake/Console/Command/Task/ControllerTask.php
@@ -395,7 +395,7 @@ public function listAll($useDbConfig = null) {
}
$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();
@@ -419,14 +419,14 @@ public function getName($useDbConfig = null) {
$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 = '';
}
View
30 lib/Cake/Console/Command/Task/DbConfigTask.php
@@ -92,10 +92,10 @@ protected function _interactive() {
$done = false;
$dbConfigs = array();
- while ($done == false) {
+ 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 @@ protected function _interactive() {
}
$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 @@ protected function _interactive() {
}
$login = '';
- while ($login == '') {
+ while (!$login) {
$login = $this->in(__d('cake_console', 'User:'), null, 'root');
}
$password = '';
$blankPassword = false;
- while ($password == '' && $blankPassword == false) {
+ 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,20 +148,20 @@ protected function _interactive() {
}
$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') {
$prefix = null;
}
$encoding = '';
- while ($encoding == '') {
+ while (!$encoding) {
$encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n');
}
if (strtolower($encoding) == 'n') {
@@ -170,7 +170,7 @@ protected function _interactive() {
$schema = '';
if ($datasource == 'postgres') {
- while ($schema == '') {
+ while (!$schema) {
$schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n');
}
}
@@ -180,7 +180,7 @@ protected function _interactive() {
$config = compact('name', 'datasource', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
- while ($this->_verify($config) == false) {
+ while (!$this->_verify($config)) {
$this->_interactive();
}
@@ -277,11 +277,7 @@ public function bake($configs) {
$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,
View
6 lib/Cake/Console/Command/Task/ExtractTask.php
@@ -391,7 +391,7 @@ protected function _parse($functionName, $map) {
$position = $count;
$depth = 0;
- while ($depth == 0) {
+ while (!$depth) {
if ($this->_tokens[$position] == '(') {
$depth++;
} elseif ($this->_tokens[$position] == ')') {
@@ -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);
}
@@ -591,7 +591,7 @@ protected function _writeFiles() {
);
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;
View
23 lib/Cake/Console/Command/Task/ModelTask.php
@@ -472,16 +472,14 @@ public function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
}
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 @@ public function findHasOneAndMany(Model $model, $associations) {
$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) {
@@ -780,7 +778,7 @@ protected function _generatePossibleKeys() {
*/
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);
@@ -935,7 +933,7 @@ public function getName($useDbConfig = null) {
$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 +942,17 @@ public function getName($useDbConfig = null) {
$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;
}
/**
View
11 lib/Cake/Console/Command/Task/ProjectTask.php
@@ -66,7 +66,7 @@ public function execute() {
}
$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', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
$response = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($response) === 'n') {
@@ -349,10 +349,7 @@ protected function _replaceCorePath($filename, $hardCode) {
if (!file_put_contents($filename, $result)) {
return false;
}
- if ($count == 0) {
- return false;
- }
- return true;
+ return (bool)$count;
}
/**
@@ -387,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) {
@@ -409,7 +406,7 @@ public function getPrefix() {
$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) {
View
4 lib/Cake/Console/Command/Task/TemplateTask.php
@@ -123,7 +123,7 @@ public function set($one, $two = null) {
$data = array($one => $two);
}
- if ($data == null) {
+ if (!$data) {
return false;
}
$this->templateVars = $data + $this->templateVars;
@@ -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
4 lib/Cake/Console/Command/Task/ViewTask.php
@@ -316,9 +316,9 @@ public function bakeActions($actions, $vars) {
*/
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.'));
}
}
View
2 lib/Cake/Console/ConsoleErrorHandler.php
@@ -81,7 +81,7 @@ public function handleError($code, $description, $file = null, $line = null, $co
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
$stderr->write(__d('cake_console', "<error>%s Error:</error> %s\n", $name, $message));
- if (Configure::read('debug') == 0) {
+ if (!Configure::read('debug')) {
CakeLog::write($log, $message);
}
View
10 lib/Cake/Console/Shell.php
@@ -154,21 +154,21 @@ 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);
$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();
@@ -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/Component/Acl/IniAcl.php
@@ -91,7 +91,7 @@ public function inherit($aro, $aco, $action = "*") {
* @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;
View
4 lib/Cake/Controller/Component/Acl/PhpAcl.php
@@ -170,11 +170,11 @@ public function check($aro, $aco, $action = "*") {
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));
}
}
}
View
4 lib/Cake/Controller/Component/CookieComponent.php
@@ -391,7 +391,7 @@ protected function _expire($expires = null) {
}
$this->_reset = $this->_expires;
- if ($expires == 0) {
+ if (!$expires) {
return $this->_expires = 0;
}
@@ -517,7 +517,7 @@ protected function _explode($string) {
$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) {
View
2 lib/Cake/Controller/Component/EmailComponent.php
@@ -316,7 +316,7 @@ public function send($content = null, $template = null, $layout = null) {
foreach ($this->headers as $key => $value) {
$headers['X-' . $key] = $value;
}
- if ($this->date != false) {
+ if ($this->date) {
$headers['Date'] = $this->date;
}
$lib->setHeaders($headers);
View
2 lib/Cake/Controller/Component/SecurityComponent.php
@@ -314,7 +314,7 @@ public function requireAuth() {
* @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));
View
21 lib/Cake/Controller/Controller.php
@@ -319,7 +319,7 @@ public function __construct($request = null, $response = null) {
$this->name = substr(get_class($this), 0, -10);
}
- if ($this->viewPath == null) {
+ if (!$this->viewPath) {
$this->viewPath = $this->name;
}
@@ -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'] == 1) {
$this->autoRender = false;
}
if (!empty($request->params['bare'])) {
@@ -966,14 +966,15 @@ public function render($view = null, $layout = null) {
* @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 '/';
+ }
+
+ $referer = $this->request->referer($local);
+ if ($referer == '/' && $default) {
+ return Router::url($default, true);
}
- return '/';
+ return $referer;
}
/**
@@ -1061,7 +1062,7 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
$cond[$key] = $value;
}
}
- if ($bool != null && strtoupper($bool) != 'AND') {
+ if ($bool && strtoupper($bool) != 'AND') {
$cond = array($bool => $cond);
}
return $cond;
View
2 lib/Cake/Controller/Scaffold.php
@@ -146,7 +146,7 @@ public function __construct(Controller $controller, CakeRequest $request) {
$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);
}
View
2 lib/Cake/Core/App.php
@@ -607,7 +607,7 @@ public static function import($type = null, $name = null, $parent = true, $searc
extract($parent, EXTR_OVERWRITE);
}
- if ($name == null && $file == null) {
+ if (!$name && !$file) {
return false;
}
View
4 lib/Cake/Error/ExceptionRenderer.php
@@ -201,7 +201,7 @@ protected function _cakeError(CakeException $error) {
*/
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();
@@ -223,7 +223,7 @@ public function error400($error) {
*/
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();
View
2 lib/Cake/I18n/I18n.php
@@ -405,7 +405,7 @@ public static function loadMo($filename) {
$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"]);
View
2 lib/Cake/Model/Behavior/TranslateBehavior.php
@@ -338,7 +338,7 @@ public function beforeValidate(Model $Model) {
* @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'])) {
View
16 lib/Cake/Model/Behavior/TreeBehavior.php
@@ -355,17 +355,16 @@ public function generateTreeList(Model $Model, $conditions = null, $keyPath = nu
$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 @@ public function recover(Model $Model, $mode = 'parent', $missingParentAction = n
$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]));
@@ -800,7 +798,7 @@ public function verify(Model $Model) {
$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');
View
6 lib/Cake/Model/Datasource/CakeSession.php
@@ -131,7 +131,7 @@ public static function init($base = null) {
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);
@@ -247,7 +247,7 @@ public static function id($id = null) {
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;
@@ -660,7 +660,7 @@ protected static function _checkValid() {
*/
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);
View
9 lib/Cake/Model/Datasource/Database/Mysql.php
@@ -186,7 +186,7 @@ public function enabled() {
*/
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']));
@@ -300,7 +300,7 @@ public function getCharsetName($name) {
public function describe($model) {
$key = $this->fullTableName($model, false);
$cache = parent::describe($key);
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
$table = $this->fullTableName($model);
@@ -352,7 +352,7 @@ public function update(Model $model, $fields = array(), $values = null, $conditi
return parent::update($model, $fields, $values, $conditions);
}
- if ($values == null) {
+ if (!$values) {
$combined = $fields;
} else {
$combined = array_combine($fields, $values);
@@ -453,6 +453,7 @@ public function index($model) {
if (!isset($index[$idx->Key_name]['column'])) {
$col = array();
$index[$idx->Key_name]['column'] = $idx->Column_name;
+
if ($idx->Index_type === 'FULLTEXT') {
$index[$idx->Key_name]['type'] = strtolower($idx->Index_type);
} else {
@@ -654,7 +655,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
20 lib/Cake/Model/Datasource/Database/Postgres.php
@@ -149,7 +149,7 @@ public function enabled() {
public function listSources($data = null) {
$cache = parent::listSources();
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
@@ -159,17 +159,17 @@ public function listSources($data = null) {
if (!$result) {
return array();
- } else {
- $tables = array();
+ }
- foreach ($result as $item) {
- $tables[] = $item->name;
- }
+ $tables = array();
- $result->closeCursor();
- parent::listSources($tables);
- return $tables;
+ foreach ($result as $item) {
+ $tables[] = $item->name;
}
+
+ $result->closeCursor();
+ parent::listSources($tables);
+ return $tables;
}
/**
@@ -695,7 +695,7 @@ public function length($real) {
if ($col == 'uuid') {
return 36;
}
- if ($limit != null) {
+ if ($limit) {
return intval($limit);
}
return null;
View
18 lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -139,22 +139,22 @@ public function enabled() {
*/
public function listSources($data = null) {
$cache = parent::listSources();
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
$result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false);
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;
}
/**
@@ -166,7 +166,7 @@ public function listSources($data = null) {
public function describe($model) {
$table = $this->fullTableName($model, false, false);
$cache = parent::describe($table);
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
$fields = array();
View
6 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -187,7 +187,7 @@ public function listSources($data = null) {
public function describe($model) {
$table = $this->fullTableName($model, false);
$cache = parent::describe($table);
- if ($cache != null) {
+ if ($cache) {
return $cache;
}
$fields = array();
@@ -622,7 +622,7 @@ public function fetchResult() {
*/
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))
);
@@ -735,7 +735,7 @@ public function lastAffected($source = null) {
*/
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);
}
View
15 lib/Cake/Model/Datasource/DboSource.php
@@ -671,7 +671,7 @@ public function fetchAll($sql, $params = array(), $options = array()) {
if ($this->hasResult()) {
$first = $this->fetchRow();
- if ($first != null) {
+ if ($first) {
$out[] = $first;
}
while ($item = $this->fetchResult()) {
@@ -984,7 +984,7 @@ public function fullTableName($model, $quote = true, $schema = true) {
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);
@@ -1054,7 +1054,7 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
if ($model->recursive == -1) {
$_associations = array();
- } elseif ($model->recursive == 0) {
+ } elseif ($model->recursive === 0) {
unset($_associations[2], $_associations[3]);
}
@@ -1408,10 +1408,9 @@ protected function _mergeAssociation(&$data, &$merge, $association, $type, $self
}
}
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])) {
@@ -1821,7 +1820,7 @@ protected function _mergeConditions($query, $assoc) {
* @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);
@@ -2514,7 +2513,7 @@ public function conditionKeysToString($conditions, $quoteValues = true, $model =
$data = $this->_parseKey($model, trim($key), $value);
}
- if ($data != null) {
+ if ($data) {
$out[] = $data;
$data = null;
}
View
19 lib/Cake/Model/Model.php
@@ -727,7 +727,7 @@ public function __construct($id = false, $table = null, $ds = null) {
$this->useTable = Inflector::tableize($this->name);
}
- if ($this->displayField == null) {
+ if (!$this->displayField) {
unset($this->displayField);
}
$this->table = $this->useTable;
@@ -1400,7 +1400,7 @@ public function hasField($name, $checkVirtual = false) {
$this->schema();
}
- if ($this->_schema != null) {
+ if ($this->_schema) {
return isset($this->_schema[$name]);
}
return false;
@@ -1454,7 +1454,7 @@ public function isVirtualField($field) {
* 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)) {
@@ -1510,7 +1510,7 @@ public function create($data = array(), $filterKey = false) {
public function read($fields = null, $id = null) {
$this->validationErrors = array();
- if ($id != null) {
+ if ($id) {
$this->id = $id;
}
@@ -1526,9 +1526,8 @@ public function read($fields = null, $id = null) {
'fields' => $fields
));
return $this->data;
- } else {
- return false;
}
+ return false;
}
/**
@@ -2573,7 +2572,7 @@ public function exists($id = null) {
* @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));
}
/**
@@ -2991,7 +2990,7 @@ public function isUnique($fields, $or = true) {
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));
}
/**
@@ -3162,7 +3161,7 @@ public function getAffectedRows() {
public function setDataSource($dataSource = null) {
$oldConfig = $this->useDbConfig;
- if ($dataSource != null) {
+ if ($dataSource) {
$this->useDbConfig = $dataSource;
}
$db = ConnectionManager::getDataSource($this->useDbConfig);
@@ -3208,7 +3207,7 @@ public function associations() {
* @return array Associations
*/
public function getAssociated($type = null) {
- if ($type == null) {
+ if (!$type) {
$associated = array();
foreach ($this->_associations as $assoc) {
if (!empty($this->{$assoc})) {
View
10 lib/Cake/Model/Permission.php
@@ -81,20 +81,20 @@ public function __construct() {
* @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;
}
$permKeys = $this->getAcoKeys($this->schema());
$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 @@ public function allow($aro, $aco, $actions = "*", $value = 1) {
$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;
}
@@ -198,7 +198,7 @@ public function allow($aro, $aco, $actions = "*", $value = 1) {
}
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']);
View
6 lib/Cake/Network/CakeRequest.php
@@ -366,17 +366,17 @@ protected function _processFileData($path, $data, $field) {
* @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)) {
View
2 lib/Cake/Network/CakeResponse.php
@@ -790,7 +790,7 @@ public function sharable($public = null, $time = null) {
unset($this->_cacheDirectives['public']);
$this->maxAge($time);
}
- if ($time == null) {
+ if (!$time) {
$this->_setCacheControl();
}
return (bool)$public;
View
4 lib/Cake/Network/CakeSocket.php
@@ -121,7 +121,7 @@ public function __construct($config = array()) {
* @throws SocketException
*/
public function connect() {
- if ($this->connection != null) {
+ if ($this->connection) {
$this->disconnect();
}
@@ -130,7 +130,7 @@ public function connect() {
$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']);
View
4 lib/Cake/Network/Http/HttpResponse.php
@@ -108,7 +108,7 @@ public function getHeader($name, $headers = null) {
return $headers[$name];
}
foreach ($headers as $key => $value) {
- if (strcasecmp($key, $name) == 0) {
+ if (strcasecmp($key, $name) === 0) {
return $value;
}
}
@@ -361,7 +361,7 @@ protected function _tokenEscapeChars($hex = true, $chars = null) {
$escape[] = chr(127);
}
- if ($hex == false) {
+ if (!$hex) {
return $escape;
}
foreach ($escape as $key => $char) {
View
2 lib/Cake/Network/Http/HttpSocket.php
@@ -944,7 +944,7 @@ protected function _tokenEscapeChars($hex = true, $chars = null) {
$escape[] = chr(127);
}
- if ($hex == false) {
+ if (!$hex) {
return $escape;
}
foreach ($escape as $key => $char) {
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
4 lib/Cake/Routing/Router.php
@@ -434,7 +434,7 @@ public static function connectNamed($named, $options = array()) {
$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();
}
@@ -1090,7 +1090,7 @@ public static function &currentRoute() {
* @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, '/');
View
2 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -58,7 +58,7 @@ public function testInsertAnotherHabtmRecordWithSameForeignKey() {
$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(
View
2 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -980,7 +980,7 @@ public function testAddDetector() {
* @return void
*/
public function detectCallback($request) {
- return $request->return == true;
+ return (bool)$request->return;
}
/**
View
2 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -1168,7 +1168,7 @@ public function testSendRenderWithImage() {
$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');
}
View
2 lib/Cake/TestSuite/CakeTestSuiteCommand.php
@@ -73,7 +73,7 @@ public function run(array $argv, $exit = true) {
);
}
- if (count($suite) == 0) {
+ if (!count($suite)) {
$skeleton = new PHPUnit_Util_Skeleton_Test(
$suite->getName(),
$this->arguments['testFile']
View
2 lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
@@ -200,7 +200,7 @@ public function load(CakeTestCase $test) {
return;
}
$fixtures = $test->fixtures;
- if (empty($fixtures) || $test->autoFixtures == false) {
+ if (empty($fixtures) || !$test->autoFixtures) {
return;
}
View
6 lib/Cake/TestSuite/Reporter/CakeTextReporter.php
@@ -71,10 +71,10 @@ public function paintFail($message) {
* @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() .
View
4 lib/Cake/Utility/CakeNumber.php
@@ -296,8 +296,8 @@ public static function currency($value, $currency = 'USD', $options = array()) {
$result = $options['before'] = $options['after'] = null;
$symbolKey = 'whole';
- if ($value == 0) {
- if ($options['zero'] !== 0) {
+ if (!$value) {
+ if ($options['zero'] !== 0 ) {
return $options['zero'];
}
} elseif ($value < 1 && $value > -1) {
View
8 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--;
}
@@ -766,7 +766,7 @@ public static function timeAgoInWords($dateTime, $options = array()) {
}
}
- if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) {
+ if (!$months && $years >= 1 && $diff < ($years * 31536000)) {
$months = 11;
$years--;
}
@@ -795,7 +795,7 @@ public static function timeAgoInWords($dateTime, $options = array()) {
}
$diff = $futureTime - $pastTime;
- if ($diff == 0) {
+ if (!$diff) {
return __d('cake', 'just now', 'just now');
}
@@ -903,7 +903,7 @@ public static function isWithinNext($timeInterval, $dateString, $timezone = null
*/
public static function gmt($dateString = null) {
$time = time();
- if ($dateString != null) {
+ if ($dateString) {
$time = self::fromString($dateString);
}
return gmmktime(
View
2 lib/Cake/Utility/Debugger.php
@@ -474,7 +474,7 @@ protected static function _export($var, $depth, $indent) {
case 'float':
return '(float) ' . $var;
case 'string':
- if (trim($var) == '') {
+ if (!trim($var)) {
return "''";
}
return "'" . $var . "'";
View
6 lib/Cake/Utility/File.php
@@ -302,7 +302,7 @@ public function delete() {
* @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 @@ public function info() {
* @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 @@ public function ext() {
* @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'])) {
View
2 lib/Cake/Utility/Folder.php
@@ -425,7 +425,7 @@ public function chmod($path, $mode = false, $recursive = true, $exceptions = arr
* @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();
View
2 lib/Cake/Utility/Security.php
@@ -108,7 +108,7 @@ public static function hash($string, $type = null, $salt = false) {
}
}
- if ($type == 'sha1' || $type == null) {
+ if (!$type || $type == 'sha1') {
if (function_exists('sha1')) {
$return = sha1($string);
return $return;
View
6 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);
@@ -827,7 +827,7 @@ public static function combine($data, $path1 = null, $path2 = null, $groupPath =
}
}
- if ($groupPath != null) {