Permalink
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 25, 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
@@ -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);
@@ -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();
@@ -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)) {
@@ -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:
@@ -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 = '';
}
@@ -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,
@@ -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;
@@ -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;
}
/**
@@ -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) {
@@ -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];
}
@@ -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>');
Oops, something went wrong.

0 comments on commit 2841611

Please sign in to comment.