Merge pull request #911 from dogmatic69/type-checks

Type checks
This commit is contained in:
Mark Story 2012-10-24 17:26:30 -07:00
commit 2841611c0f
66 changed files with 213 additions and 236 deletions

View file

@ -61,9 +61,8 @@ class ApcEngine extends CacheEngine {
* @return boolean True if the data was successfully cached, false on failure * @return boolean True if the data was successfully cached, false on failure
*/ */
public function write($key, $value, $duration) { public function write($key, $value, $duration) {
if ($duration == 0) { $expires = 0;
$expires = 0; if ($duration) {
} else {
$expires = time() + $duration; $expires = time() + $duration;
} }
apc_store($key . '_expires', $expires, $duration); apc_store($key . '_expires', $expires, $duration);

View file

@ -598,7 +598,7 @@ class AclShell extends AppShell {
* @return array Variables * @return array Variables
*/ */
protected function _dataVars($type = null) { protected function _dataVars($type = null) {
if ($type == null) { if (!$type) {
$type = $this->args[0]; $type = $this->args[0];
} }
$vars = array(); $vars = array();

View file

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

View file

@ -182,7 +182,7 @@ class ConsoleShell extends AppShell {
$this->out(" - {$model}"); $this->out(" - {$model}");
} }
break; break;
case (preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp) == true): case preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp):
foreach ($tmp as $data) { foreach ($tmp as $data) {
$data = strip_tags($data); $data = strip_tags($data);
$data = str_replace($this->badCommandChars, "", $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")); $this->out(__d('cake_console', "Please verify you are using valid models and association types"));
} }
break; break;
case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true): case preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp):
foreach ($tmp as $data) { foreach ($tmp as $data) {
$data = strip_tags($data); $data = strip_tags($data);
$data = str_replace($this->badCommandChars, "", $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)); $this->out(__d('cake_console', 'Saved record for %s', $modelToSave));
} }
break; 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])); $modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
if ($this->_isValidModel($modelToCheck)) { 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")); $this->out(__d('cake_console', "Please verify that you selected a valid model"));
} }
break; break;
case (preg_match("/^routes\s+reload/i", $command, $tmp) == true): case preg_match("/^routes\s+reload/i", $command, $tmp):
if (!$this->_loadRoutes()) { 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.")); $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; break;
} }
$this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes))); $this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes)));
break; 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)); $this->out(print_r(Hash::combine(Router::$routes, '{n}.template', '{n}.defaults'), true));
break; 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] . ';')) { if ($url = eval('return array' . $tmp[1] . ';')) {
$this->out(Router::url($url)); $this->out(Router::url($url));
} }
break; 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)); $this->out(var_export(Router::parse($tmp[1]), true));
break; break;
default: default:

View file

@ -395,7 +395,7 @@ class ControllerTask extends BakeTask {
} }
$this->__tables = $this->Model->getAllTables($useDbConfig); $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->out(__d('cake_console', 'Possible Controllers based on your current database:'));
$this->hr(); $this->hr();
$this->_controllerNames = array(); $this->_controllerNames = array();
@ -419,14 +419,14 @@ class ControllerTask extends BakeTask {
$controllers = $this->listAll($useDbConfig); $controllers = $this->listAll($useDbConfig);
$enteredController = ''; $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'); $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') { if ($enteredController === 'q') {
$this->out(__d('cake_console', 'Exit')); $this->out(__d('cake_console', 'Exit'));
return $this->_stop(); 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.")); $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 = ''; $enteredController = '';
} }

View file

@ -92,10 +92,10 @@ class DbConfigTask extends AppShell {
$done = false; $done = false;
$dbConfigs = array(); $dbConfigs = array();
while ($done == false) { while (!$done) {
$name = ''; $name = '';
while ($name == '') { while (!$name) {
$name = $this->in(__d('cake_console', "Name:"), null, 'default'); $name = $this->in(__d('cake_console', "Name:"), null, 'default');
if (preg_match('/[^a-z0-9_]/i', $name)) { if (preg_match('/[^a-z0-9_]/i', $name)) {
$name = ''; $name = '';
@ -116,12 +116,12 @@ class DbConfigTask extends AppShell {
} }
$host = ''; $host = '';
while ($host == '') { while (!$host) {
$host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost'); $host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost');
} }
$port = ''; $port = '';
while ($port == '') { while (!$port) {
$port = $this->in(__d('cake_console', 'Port?'), null, 'n'); $port = $this->in(__d('cake_console', 'Port?'), null, 'n');
} }
@ -130,16 +130,16 @@ class DbConfigTask extends AppShell {
} }
$login = ''; $login = '';
while ($login == '') { while (!$login) {
$login = $this->in(__d('cake_console', 'User:'), null, 'root'); $login = $this->in(__d('cake_console', 'User:'), null, 'root');
} }
$password = ''; $password = '';
$blankPassword = false; $blankPassword = false;
while ($password == '' && $blankPassword == false) { while (!$password && !$blankPassword) {
$password = $this->in(__d('cake_console', 'Password:')); $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'); $blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n');
if ($blank == 'y') { if ($blank == 'y') {
$blankPassword = true; $blankPassword = true;
@ -148,12 +148,12 @@ class DbConfigTask extends AppShell {
} }
$database = ''; $database = '';
while ($database == '') { while (!$database) {
$database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake'); $database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake');
} }
$prefix = ''; $prefix = '';
while ($prefix == '') { while (!$prefix) {
$prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n'); $prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n');
} }
if (strtolower($prefix) == 'n') { if (strtolower($prefix) == 'n') {
@ -161,7 +161,7 @@ class DbConfigTask extends AppShell {
} }
$encoding = ''; $encoding = '';
while ($encoding == '') { while (!$encoding) {
$encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n'); $encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n');
} }
if (strtolower($encoding) == 'n') { if (strtolower($encoding) == 'n') {
@ -170,7 +170,7 @@ class DbConfigTask extends AppShell {
$schema = ''; $schema = '';
if ($datasource == 'postgres') { if ($datasource == 'postgres') {
while ($schema == '') { while (!$schema) {
$schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n'); $schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n');
} }
} }
@ -180,7 +180,7 @@ class DbConfigTask extends AppShell {
$config = compact('name', 'datasource', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema'); $config = compact('name', 'datasource', 'persistent', 'host', 'login', 'password', 'database', 'prefix', 'encoding', 'port', 'schema');
while ($this->_verify($config) == false) { while (!$this->_verify($config)) {
$this->_interactive(); $this->_interactive();
} }
@ -277,11 +277,7 @@ class DbConfigTask extends AppShell {
$info['port'] = null; $info['port'] = null;
} }
if ($info['persistent'] === false) { $info['persistent'] = var_export((bool)$info['persistent'], true);
$info['persistent'] = 'false';
} else {
$info['persistent'] = ($info['persistent'] == true) ? 'true' : 'false';
}
$oldConfigs[] = array( $oldConfigs[] = array(
'name' => $configName, 'name' => $configName,

View file

@ -391,7 +391,7 @@ class ExtractTask extends AppShell {
$position = $count; $position = $count;
$depth = 0; $depth = 0;
while ($depth == 0) { while (!$depth) {
if ($this->_tokens[$position] == '(') { if ($this->_tokens[$position] == '(') {
$depth++; $depth++;
} elseif ($this->_tokens[$position] == ')') { } elseif ($this->_tokens[$position] == ')') {
@ -480,7 +480,7 @@ class ExtractTask extends AppShell {
} }
$dims = Hash::dimensions($rules); $dims = Hash::dimensions($rules);
if ($dims == 1 || ($dims == 2 && isset($rules['message']))) { if ($dims === 1 || ($dims === 2 && isset($rules['message']))) {
$rules = array($rules); $rules = array($rules);
} }
@ -591,7 +591,7 @@ class ExtractTask extends AppShell {
); );
if (strtoupper($response) === 'N') { if (strtoupper($response) === 'N') {
$response = ''; $response = '';
while ($response == '') { while (!$response) {
$response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename); $response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
$File = new File($this->_output . $response); $File = new File($this->_output . $response);
$filename = $response; $filename = $response;

View file

@ -472,16 +472,14 @@ class ModelTask extends BakeTask {
} }
if ($choice != $defaultChoice) { if ($choice != $defaultChoice) {
$validate[$validatorName] = $choice;
if (is_numeric($choice) && isset($this->_validations[$choice])) { if (is_numeric($choice) && isset($this->_validations[$choice])) {
$validate[$validatorName] = $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'); $anotherValidator = $this->in(__d('cake_console', 'Would you like to add another validation rule?'), array('y', 'n'), 'n');
} else {
$anotherValidator = 'n';
} }
} }
return $validate; return $validate;
@ -583,7 +581,7 @@ class ModelTask extends BakeTask {
$pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/'; $pattern = '/_' . preg_quote($model->table, '/') . '|' . preg_quote($model->table, '/') . '_/';
$possibleJoinTable = preg_match($pattern, $otherTable); $possibleJoinTable = preg_match($pattern, $otherTable);
if ($possibleJoinTable == true) { if ($possibleJoinTable) {
continue; continue;
} }
foreach ($modelFieldsTemp as $fieldName => $field) { foreach ($modelFieldsTemp as $fieldName => $field) {
@ -780,7 +778,7 @@ class ModelTask extends BakeTask {
*/ */
public function bake($name, $data = array()) { public function bake($name, $data = array()) {
if (is_object($name)) { if (is_object($name)) {
if ($data == false) { if (!$data) {
$data = array(); $data = array();
$data['associations'] = $this->doAssociations($name); $data['associations'] = $this->doAssociations($name);
$data['validate'] = $this->doValidation($name); $data['validate'] = $this->doValidation($name);
@ -935,7 +933,7 @@ class ModelTask extends BakeTask {
$enteredModel = ''; $enteredModel = '';
while ($enteredModel == '') { while (!$enteredModel) {
$enteredModel = $this->in(__d('cake_console', "Enter a number from the list above,\n" . $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'); "type in the name of another model, or 'q' to exit"), null, 'q');
@ -944,18 +942,17 @@ class ModelTask extends BakeTask {
$this->_stop(); $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" . $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.")); "or the number you selected was not an option. Please try again."));
$enteredModel = ''; $enteredModel = '';
} }
} }
if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) { if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
$currentModelName = $this->_modelNames[intval($enteredModel) - 1]; return $this->_modelNames[intval($enteredModel) - 1];
} else {
$currentModelName = $enteredModel;
} }
return $currentModelName;
return $enteredModel;
} }
/** /**

View file

@ -66,7 +66,7 @@ class ProjectTask extends AppShell {
} }
$response = false; $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); $prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
$response = $this->in($prompt, array('y', 'n'), 'n'); $response = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($response) === 'n') { if (strtolower($response) === 'n') {
@ -349,10 +349,7 @@ class ProjectTask extends AppShell {
if (!file_put_contents($filename, $result)) { if (!file_put_contents($filename, $result)) {
return false; return false;
} }
if ($count == 0) { return (bool)$count;
return false;
}
return true;
} }
/** /**
@ -387,7 +384,7 @@ class ProjectTask extends AppShell {
$admin = ''; $admin = '';
$prefixes = Configure::read('Routing.prefixes'); $prefixes = Configure::read('Routing.prefixes');
if (!empty($prefixes)) { if (!empty($prefixes)) {
if (count($prefixes) == 1) { if (count($prefixes) === 1) {
return $prefixes[0] . '_'; return $prefixes[0] . '_';
} }
if ($this->interactive) { if ($this->interactive) {
@ -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', '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', 'What would you like the prefix route to be?'));
$this->out(__d('cake_console', 'Example: www.example.com/admin/controller')); $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'); $admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin');
} }
if ($this->cakeAdmin($admin) !== true) { if ($this->cakeAdmin($admin) !== true) {

View file

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

View file

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

View file

@ -316,9 +316,9 @@ class ViewTask extends BakeTask {
*/ */
public function customAction() { public function customAction() {
$action = ''; $action = '';
while ($action == '') { while (!$action) {
$action = $this->in(__d('cake_console', 'Action Name? (use lowercase_underscored function name)')); $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.')); $this->out(__d('cake_console', 'The action name you supplied was empty. Please try again.'));
} }
} }

View file

@ -81,7 +81,7 @@ class ConsoleErrorHandler {
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line); $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)); $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); CakeLog::write($log, $message);
} }

View file

@ -154,7 +154,7 @@ class Shell extends Object {
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell * @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell
*/ */
public function __construct($stdout = null, $stderr = null, $stdin = null) { 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->name = Inflector::camelize(str_replace(array('Shell', 'Task'), '', get_class($this)));
} }
$this->Tasks = new TaskCollection($this); $this->Tasks = new TaskCollection($this);
@ -162,13 +162,13 @@ class Shell extends Object {
$this->stdout = $stdout; $this->stdout = $stdout;
$this->stderr = $stderr; $this->stderr = $stderr;
$this->stdin = $stdin; $this->stdin = $stdin;
if ($this->stdout == null) { if (!$this->stdout) {
$this->stdout = new ConsoleOutput('php://stdout'); $this->stdout = new ConsoleOutput('php://stdout');
} }
if ($this->stderr == null) { if (!$this->stderr) {
$this->stderr = new ConsoleOutput('php://stderr'); $this->stderr = new ConsoleOutput('php://stderr');
} }
if ($this->stdin == null) { if (!$this->stdin) {
$this->stdin = new ConsoleInput('php://stdin'); $this->stdin = new ConsoleInput('php://stdin');
} }
$this->_useLogger(); $this->_useLogger();
@ -325,7 +325,7 @@ class Shell extends Object {
*/ */
public function dispatchShell() { public function dispatchShell() {
$args = func_get_args(); $args = func_get_args();
if (is_string($args[0]) && count($args) == 1) { if (is_string($args[0]) && count($args) === 1) {
$args = explode(' ', $args[0]); $args = explode(' ', $args[0]);
} }

View file

@ -91,7 +91,7 @@ class IniAcl extends Object implements AclInterface {
* @return boolean Success * @return boolean Success
*/ */
public function check($aro, $aco, $action = null) { public function check($aro, $aco, $action = null) {
if ($this->config == null) { if (!$this->config) {
$this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php'); $this->config = $this->readConfigFile(APP . 'Config' . DS . 'acl.ini.php');
} }
$aclConfig = $this->config; $aclConfig = $this->config;

View file

@ -170,11 +170,11 @@ class PhpAcl extends Object implements AclInterface {
foreach ($path as $depth => $node) { foreach ($path as $depth => $node) {
foreach ($prioritizedAros as $aros) { foreach ($prioritizedAros as $aros) {
if (!empty($node['allow'])) { 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'])) { if (!empty($node['deny'])) {
$allow = $allow && count(array_intersect($node['deny'], $aros)) == 0; $allow = $allow && !count(array_intersect($node['deny'], $aros));
} }
} }
} }

View file

@ -391,7 +391,7 @@ class CookieComponent extends Component {
} }
$this->_reset = $this->_expires; $this->_reset = $this->_expires;
if ($expires == 0) { if (!$expires) {
return $this->_expires = 0; return $this->_expires = 0;
} }
@ -517,7 +517,7 @@ class CookieComponent extends Component {
$first = substr($string, 0, 1); $first = substr($string, 0, 1);
if ($first === '{' || $first === '[') { if ($first === '{' || $first === '[') {
$ret = json_decode($string, true); $ret = json_decode($string, true);
return ($ret != null) ? $ret : $string; return ($ret) ? $ret : $string;
} }
$array = array(); $array = array();
foreach (explode(',', $string) as $pair) { foreach (explode(',', $string) as $pair) {

View file

@ -316,7 +316,7 @@ class EmailComponent extends Component {
foreach ($this->headers as $key => $value) { foreach ($this->headers as $key => $value) {
$headers['X-' . $key] = $value; $headers['X-' . $key] = $value;
} }
if ($this->date != false) { if ($this->date) {
$headers['Date'] = $this->date; $headers['Date'] = $this->date;
} }
$lib->setHeaders($headers); $lib->setHeaders($headers);

View file

@ -314,7 +314,7 @@ class SecurityComponent extends Component {
* @throws BadRequestException * @throws BadRequestException
*/ */
public function blackHole(Controller $controller, $error = '') { 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')); throw new BadRequestException(__d('cake_dev', 'The request has been black-holed'));
} }
return $this->_callback($controller, $this->blackHoleCallback, array($error)); return $this->_callback($controller, $this->blackHoleCallback, array($error));

View file

@ -319,7 +319,7 @@ class Controller extends Object implements CakeEventListener {
$this->name = substr(get_class($this), 0, -10); $this->name = substr(get_class($this), 0, -10);
} }
if ($this->viewPath == null) { if (!$this->viewPath) {
$this->viewPath = $this->name; $this->viewPath = $this->name;
} }
@ -454,7 +454,7 @@ class Controller extends Object implements CakeEventListener {
$this->passedArgs = array_merge($request->params['pass'], $request->params['named']); $this->passedArgs = array_merge($request->params['pass'], $request->params['named']);
} }
if (array_key_exists('return', $request->params) && $request->params['return'] == 1) { if (!empty($request->params['return']) && $request->params['return'] == 1) {
$this->autoRender = false; $this->autoRender = false;
} }
if (!empty($request->params['bare'])) { if (!empty($request->params['bare'])) {
@ -966,14 +966,15 @@ class Controller extends Object implements CakeEventListener {
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer
*/ */
public function referer($default = null, $local = false) { public function referer($default = null, $local = false) {
if ($this->request) { if(!$this->request) {
$referer = $this->request->referer($local); return '/';
if ($referer == '/' && $default != null) {
return Router::url($default, true);
}
return $referer;
} }
return '/';
$referer = $this->request->referer($local);
if ($referer == '/' && $default) {
return Router::url($default, true);
}
return $referer;
} }
/** /**
@ -1061,7 +1062,7 @@ class Controller extends Object implements CakeEventListener {
$cond[$key] = $value; $cond[$key] = $value;
} }
} }
if ($bool != null && strtoupper($bool) != 'AND') { if ($bool && strtoupper($bool) != 'AND') {
$cond = array($bool => $cond); $cond = array($bool => $cond);
} }
return $cond; return $cond;

View file

@ -146,7 +146,7 @@ class Scaffold {
$this->controller->viewClass = 'Scaffold'; $this->controller->viewClass = 'Scaffold';
} }
$this->_validSession = ( $this->_validSession = (
isset($this->controller->Session) && $this->controller->Session->valid() != false isset($this->controller->Session) && $this->controller->Session->valid()
); );
$this->_scaffold($request); $this->_scaffold($request);
} }

View file

@ -607,7 +607,7 @@ class App {
extract($parent, EXTR_OVERWRITE); extract($parent, EXTR_OVERWRITE);
} }
if ($name == null && $file == null) { if (!$name && !$file) {
return false; return false;
} }

View file

@ -201,7 +201,7 @@ class ExceptionRenderer {
*/ */
public function error400($error) { public function error400($error) {
$message = $error->getMessage(); $message = $error->getMessage();
if (Configure::read('debug') == 0 && $error instanceof CakeException) { if (!Configure::read('debug') && $error instanceof CakeException) {
$message = __d('cake', 'Not Found'); $message = __d('cake', 'Not Found');
} }
$url = $this->controller->request->here(); $url = $this->controller->request->here();
@ -223,7 +223,7 @@ class ExceptionRenderer {
*/ */
public function error500($error) { public function error500($error) {
$message = $error->getMessage(); $message = $error->getMessage();
if (Configure::read('debug') == 0) { if (!Configure::read('debug')) {
$message = __d('cake', 'An Internal Error Has Occurred.'); $message = __d('cake', 'An Internal Error Has Occurred.');
} }
$url = $this->controller->request->here(); $url = $this->controller->request->here();

View file

@ -405,7 +405,7 @@ class I18n {
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header); $header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
extract($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++) { for ($n = 0; $n < $count; $n++) {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8)); $r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]); $msgid = substr($data, $r["offs"], $r["len"]);

View file

@ -338,7 +338,7 @@ class TranslateBehavior extends ModelBehavior {
* @return boolean true. * @return boolean true.
*/ */
public function beforeSave(Model $Model, $options = array()) { 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']); unset($this->runtime[$Model->alias]['beforeSave']);
} }
if (isset($this->runtime[$Model->alias]['beforeSave'])) { if (isset($this->runtime[$Model->alias]['beforeSave'])) {

View file

@ -355,17 +355,16 @@ class TreeBehavior extends ModelBehavior {
$recursive = $overrideRecursive; $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); $fields = array($Model->primaryKey, $Model->displayField, $left, $right);
} else {
$fields = null;
} }
if ($keyPath == null) { if (!$keyPath) {
$keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey; $keyPath = '{n}.' . $Model->alias . '.' . $Model->primaryKey;
} }
if ($valuePath == null) { if (!$valuePath) {
$valuePath = array('%s%s', '{n}.tree_prefix', '{n}.' . $Model->alias . '.' . $Model->displayField); $valuePath = array('%s%s', '{n}.tree_prefix', '{n}.' . $Model->alias . '.' . $Model->displayField);
} elseif (is_string($valuePath)) { } elseif (is_string($valuePath)) {
@ -645,9 +644,8 @@ class TreeBehavior extends ModelBehavior {
$db = ConnectionManager::getDataSource($Model->useDbConfig); $db = ConnectionManager::getDataSource($Model->useDbConfig);
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) { 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]); $path = $this->getPath($Model, $array[$Model->alias][$Model->primaryKey]);
if ($path == null || count($path) < 2) { $parentId = null;
$parentId = null; if (count($path) > 1) {
} else {
$parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey]; $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])); $Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey]));
@ -800,7 +798,7 @@ class TreeBehavior extends ModelBehavior {
$scope, 'OR' => array($Model->escapeField($left) => $i, $Model->escapeField($right) => $i) $scope, 'OR' => array($Model->escapeField($left) => $i, $Model->escapeField($right) => $i)
))); )));
if ($count != 1) { if ($count != 1) {
if ($count == 0) { if (!$count) {
$errors[] = array('index', $i, 'missing'); $errors[] = array('index', $i, 'missing');
} else { } else {
$errors[] = array('index', $i, 'duplicate'); $errors[] = array('index', $i, 'duplicate');

View file

@ -131,7 +131,7 @@ class CakeSession {
self::$time = time(); self::$time = time();
$checkAgent = Configure::read('Session.checkAgent'); $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::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
} }
self::_setPath($base); self::_setPath($base);
@ -247,7 +247,7 @@ class CakeSession {
public static function delete($name) { public static function delete($name) {
if (self::check($name)) { if (self::check($name)) {
self::_overwrite($_SESSION, Hash::remove($_SESSION, $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)); self::_setError(2, __d('cake_dev', "%s doesn't exist", $name));
return false; return false;
@ -660,7 +660,7 @@ class CakeSession {
*/ */
public static function renew() { public static function renew() {
if (session_id()) { 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); setcookie(Configure::read('Session.cookie'), '', time() - 42000, self::$path);
} }
session_regenerate_id(true); session_regenerate_id(true);

View file

@ -186,7 +186,7 @@ class Mysql extends DboSource {
*/ */
public function listSources($data = null) { public function listSources($data = null) {
$cache = parent::listSources(); $cache = parent::listSources();
if ($cache != null) { if ($cache) {
return $cache; return $cache;
} }
$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database'])); $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
@ -300,7 +300,7 @@ class Mysql extends DboSource {
public function describe($model) { public function describe($model) {
$key = $this->fullTableName($model, false); $key = $this->fullTableName($model, false);
$cache = parent::describe($key); $cache = parent::describe($key);
if ($cache != null) { if ($cache) {
return $cache; return $cache;
} }
$table = $this->fullTableName($model); $table = $this->fullTableName($model);
@ -352,7 +352,7 @@ class Mysql extends DboSource {
return parent::update($model, $fields, $values, $conditions); return parent::update($model, $fields, $values, $conditions);
} }
if ($values == null) { if (!$values) {
$combined = $fields; $combined = $fields;
} else { } else {
$combined = array_combine($fields, $values); $combined = array_combine($fields, $values);
@ -453,6 +453,7 @@ class Mysql extends DboSource {
if (!isset($index[$idx->Key_name]['column'])) { if (!isset($index[$idx->Key_name]['column'])) {
$col = array(); $col = array();
$index[$idx->Key_name]['column'] = $idx->Column_name; $index[$idx->Key_name]['column'] = $idx->Column_name;
if ($idx->Index_type === 'FULLTEXT') { if ($idx->Index_type === 'FULLTEXT') {
$index[$idx->Key_name]['type'] = strtolower($idx->Index_type); $index[$idx->Key_name]['type'] = strtolower($idx->Index_type);
} else { } else {
@ -654,7 +655,7 @@ class Mysql extends DboSource {
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) { if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col; return $col;
} }
if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') { if (($col === 'tinyint' && $limit === 1) || $col === 'boolean') {
return 'boolean'; return 'boolean';
} }
if (strpos($col, 'bigint') !== false || $col === 'bigint') { if (strpos($col, 'bigint') !== false || $col === 'bigint') {

View file

@ -149,7 +149,7 @@ class Postgres extends DboSource {
public function listSources($data = null) { public function listSources($data = null) {
$cache = parent::listSources(); $cache = parent::listSources();
if ($cache != null) { if ($cache) {
return $cache; return $cache;
} }
@ -159,17 +159,17 @@ class Postgres extends DboSource {
if (!$result) { if (!$result) {
return array(); 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;
} }
/** /**
@ -695,7 +695,7 @@ class Postgres extends DboSource {
if ($col == 'uuid') { if ($col == 'uuid') {
return 36; return 36;
} }
if ($limit != null) { if ($limit) {
return intval($limit); return intval($limit);
} }
return null; return null;

View file

@ -139,7 +139,7 @@ class Sqlite extends DboSource {
*/ */
public function listSources($data = null) { public function listSources($data = null) {
$cache = parent::listSources(); $cache = parent::listSources();
if ($cache != null) { if ($cache) {
return $cache; return $cache;
} }
@ -147,14 +147,14 @@ class Sqlite extends DboSource {
if (!$result || empty($result)) { if (!$result || empty($result)) {
return array(); 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 @@ class Sqlite extends DboSource {
public function describe($model) { public function describe($model) {
$table = $this->fullTableName($model, false, false); $table = $this->fullTableName($model, false, false);
$cache = parent::describe($table); $cache = parent::describe($table);
if ($cache != null) { if ($cache) {
return $cache; return $cache;
} }
$fields = array(); $fields = array();

View file

@ -187,7 +187,7 @@ class Sqlserver extends DboSource {
public function describe($model) { public function describe($model) {
$table = $this->fullTableName($model, false); $table = $this->fullTableName($model, false);
$cache = parent::describe($table); $cache = parent::describe($table);
if ($cache != null) { if ($cache) {
return $cache; return $cache;
} }
$fields = array(); $fields = array();
@ -622,7 +622,7 @@ class Sqlserver extends DboSource {
*/ */
public function insertMulti($table, $fields, $values) { public function insertMulti($table, $fields, $values) {
$primaryKey = $this->_getPrimaryKey($table); $primaryKey = $this->_getPrimaryKey($table);
$hasPrimaryKey = $primaryKey != null && ( $hasPrimaryKey = $primaryKey && (
(is_array($fields) && in_array($primaryKey, $fields) (is_array($fields) && in_array($primaryKey, $fields)
|| (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false)) || (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false))
); );
@ -735,7 +735,7 @@ class Sqlserver extends DboSource {
*/ */
protected function _execute($sql, $params = array(), $prepareOptions = array()) { protected function _execute($sql, $params = array(), $prepareOptions = array()) {
$this->_lastAffected = false; $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); $prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions); return parent::_execute($sql, $params, $prepareOptions);
} }

View file

@ -671,7 +671,7 @@ class DboSource extends DataSource {
if ($this->hasResult()) { if ($this->hasResult()) {
$first = $this->fetchRow(); $first = $this->fetchRow();
if ($first != null) { if ($first) {
$out[] = $first; $out[] = $first;
} }
while ($item = $this->fetchResult()) { while ($item = $this->fetchResult()) {
@ -984,7 +984,7 @@ class DboSource extends DataSource {
public function create(Model $model, $fields = null, $values = null) { public function create(Model $model, $fields = null, $values = null) {
$id = null; $id = null;
if ($fields == null) { if (!$fields) {
unset($fields, $values); unset($fields, $values);
$fields = array_keys($model->data); $fields = array_keys($model->data);
$values = array_values($model->data); $values = array_values($model->data);
@ -1054,7 +1054,7 @@ class DboSource extends DataSource {
if ($model->recursive == -1) { if ($model->recursive == -1) {
$_associations = array(); $_associations = array();
} elseif ($model->recursive == 0) { } elseif ($model->recursive === 0) {
unset($_associations[2], $_associations[3]); unset($_associations[2], $_associations[3]);
} }
@ -1408,10 +1408,9 @@ class DboSource extends DataSource {
} }
} }
if (!isset($data[$association])) { if (!isset($data[$association])) {
if ($merge[0][$association] != null) { $data[$association] = array();
if ($merge[0][$association]) {
$data[$association] = $merge[0][$association]; $data[$association] = $merge[0][$association];
} else {
$data[$association] = array();
} }
} else { } else {
if (is_array($merge[0][$association])) { if (is_array($merge[0][$association])) {
@ -1821,7 +1820,7 @@ class DboSource extends DataSource {
* @return boolean Success * @return boolean Success
*/ */
public function update(Model $model, $fields = array(), $values = null, $conditions = null) { public function update(Model $model, $fields = array(), $values = null, $conditions = null) {
if ($values == null) { if (!$values) {
$combined = $fields; $combined = $fields;
} else { } else {
$combined = array_combine($fields, $values); $combined = array_combine($fields, $values);
@ -2514,7 +2513,7 @@ class DboSource extends DataSource {
$data = $this->_parseKey($model, trim($key), $value); $data = $this->_parseKey($model, trim($key), $value);
} }
if ($data != null) { if ($data) {
$out[] = $data; $out[] = $data;
$data = null; $data = null;
} }

View file

@ -727,7 +727,7 @@ class Model extends Object implements CakeEventListener {
$this->useTable = Inflector::tableize($this->name); $this->useTable = Inflector::tableize($this->name);
} }
if ($this->displayField == null) { if (!$this->displayField) {
unset($this->displayField); unset($this->displayField);
} }
$this->table = $this->useTable; $this->table = $this->useTable;
@ -1400,7 +1400,7 @@ class Model extends Object implements CakeEventListener {
$this->schema(); $this->schema();
} }
if ($this->_schema != null) { if ($this->_schema) {
return isset($this->_schema[$name]); return isset($this->_schema[$name]);
} }
return false; return false;
@ -1454,7 +1454,7 @@ class Model extends Object implements CakeEventListener {
* or false if none $field exist. * or false if none $field exist.
*/ */
public function getVirtualField($field = null) { public function getVirtualField($field = null) {
if ($field == null) { if (!$field) {
return empty($this->virtualFields) ? false : $this->virtualFields; return empty($this->virtualFields) ? false : $this->virtualFields;
} }
if ($this->isVirtualField($field)) { if ($this->isVirtualField($field)) {
@ -1510,7 +1510,7 @@ class Model extends Object implements CakeEventListener {
public function read($fields = null, $id = null) { public function read($fields = null, $id = null) {
$this->validationErrors = array(); $this->validationErrors = array();
if ($id != null) { if ($id) {
$this->id = $id; $this->id = $id;
} }
@ -1526,9 +1526,8 @@ class Model extends Object implements CakeEventListener {
'fields' => $fields 'fields' => $fields
)); ));
return $this->data; return $this->data;
} else {
return false;
} }
return false;
} }
/** /**
@ -2573,7 +2572,7 @@ class Model extends Object implements CakeEventListener {
* @return boolean True if such a record exists * @return boolean True if such a record exists
*/ */
public function hasAny($conditions = null) { 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 @@ class Model extends Object implements CakeEventListener {
if (!empty($this->id)) { if (!empty($this->id)) {
$fields[$this->alias . '.' . $this->primaryKey . ' !='] = $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 @@ class Model extends Object implements CakeEventListener {
public function setDataSource($dataSource = null) { public function setDataSource($dataSource = null) {
$oldConfig = $this->useDbConfig; $oldConfig = $this->useDbConfig;
if ($dataSource != null) { if ($dataSource) {
$this->useDbConfig = $dataSource; $this->useDbConfig = $dataSource;
} }
$db = ConnectionManager::getDataSource($this->useDbConfig); $db = ConnectionManager::getDataSource($this->useDbConfig);
@ -3208,7 +3207,7 @@ class Model extends Object implements CakeEventListener {
* @return array Associations * @return array Associations
*/ */
public function getAssociated($type = null) { public function getAssociated($type = null) {
if ($type == null) { if (!$type) {
$associated = array(); $associated = array();
foreach ($this->_associations as $assoc) { foreach ($this->_associations as $assoc) {
if (!empty($this->{$assoc})) { if (!empty($this->{$assoc})) {

View file

@ -81,7 +81,7 @@ class Permission extends AppModel {
* @return boolean Success (true if ARO has access to action in ACO, false otherwise) * @return boolean Success (true if ARO has access to action in ACO, false otherwise)
*/ */
public function check($aro, $aco, $action = "*") { public function check($aro, $aco, $action = "*") {
if ($aro == null || $aco == null) { if (!$aro || !$aco) {
return false; return false;
} }
@ -89,12 +89,12 @@ class Permission extends AppModel {
$aroPath = $this->Aro->node($aro); $aroPath = $this->Aro->node($aro);
$acoPath = $this->Aco->node($aco); $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); 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; 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); 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; return false;
} }
@ -171,7 +171,7 @@ class Permission extends AppModel {
$permKeys = $this->getAcoKeys($this->schema()); $permKeys = $this->getAcoKeys($this->schema());
$save = array(); $save = array();
if ($perms == false) { if (!$perms) {
trigger_error(__d('cake_dev', 'DbAcl::allow() - Invalid node'), E_USER_WARNING); trigger_error(__d('cake_dev', 'DbAcl::allow() - Invalid node'), E_USER_WARNING);
return false; return false;
} }
@ -198,7 +198,7 @@ class Permission extends AppModel {
} }
list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']); 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']; $save['id'] = $perms['link'][0][$this->alias]['id'];
} else { } else {
unset($save['id']); unset($save['id']);

View file

@ -366,17 +366,17 @@ class CakeRequest implements ArrayAccess {
* @return string The client IP. * @return string The client IP.
*/ */
public function clientIp($safe = true) { 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')); $ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
} else { } else {
if (env('HTTP_CLIENT_IP') != null) { if (env('HTTP_CLIENT_IP')) {
$ipaddr = env('HTTP_CLIENT_IP'); $ipaddr = env('HTTP_CLIENT_IP');
} else { } else {
$ipaddr = env('REMOTE_ADDR'); $ipaddr = env('REMOTE_ADDR');
} }
} }
if (env('HTTP_CLIENTADDRESS') != null) { if (env('HTTP_CLIENTADDRESS')) {
$tmpipaddr = env('HTTP_CLIENTADDRESS'); $tmpipaddr = env('HTTP_CLIENTADDRESS');
if (!empty($tmpipaddr)) { if (!empty($tmpipaddr)) {

View file

@ -790,7 +790,7 @@ class CakeResponse {
unset($this->_cacheDirectives['public']); unset($this->_cacheDirectives['public']);
$this->maxAge($time); $this->maxAge($time);
} }
if ($time == null) { if (!$time) {
$this->_setCacheControl(); $this->_setCacheControl();
} }
return (bool)$public; return (bool)$public;

View file

@ -121,7 +121,7 @@ class CakeSocket {
* @throws SocketException * @throws SocketException
*/ */
public function connect() { public function connect() {
if ($this->connection != null) { if ($this->connection) {
$this->disconnect(); $this->disconnect();
} }
@ -130,7 +130,7 @@ class CakeSocket {
$scheme = 'ssl://'; $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']); $this->connection = @pfsockopen($scheme . $this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']);
} else { } else {
$this->connection = @fsockopen($scheme . $this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']); $this->connection = @fsockopen($scheme . $this->config['host'], $this->config['port'], $errNum, $errStr, $this->config['timeout']);

View file

@ -108,7 +108,7 @@ class HttpResponse implements ArrayAccess {
return $headers[$name]; return $headers[$name];
} }
foreach ($headers as $key => $value) { foreach ($headers as $key => $value) {
if (strcasecmp($key, $name) == 0) { if (strcasecmp($key, $name) === 0) {
return $value; return $value;
} }
} }
@ -361,7 +361,7 @@ class HttpResponse implements ArrayAccess {
$escape[] = chr(127); $escape[] = chr(127);
} }
if ($hex == false) { if (!$hex) {
return $escape; return $escape;
} }
foreach ($escape as $key => $char) { foreach ($escape as $key => $char) {

View file

@ -944,7 +944,7 @@ class HttpSocket extends CakeSocket {
$escape[] = chr(127); $escape[] = chr(127);
} }
if ($hex == false) { if (!$hex) {
return $escape; return $escape;
} }
foreach ($escape as $key => $char) { foreach ($escape as $key => $char) {

View file

@ -74,7 +74,7 @@ class RedirectRoute extends CakeRoute {
$this->response = new CakeResponse(); $this->response = new CakeResponse();
} }
$redirect = $this->redirect; $redirect = $this->redirect;
if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) { if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) {
$redirect = $this->redirect[0]; $redirect = $this->redirect[0];
} }
if (isset($this->options['persist']) && is_array($redirect)) { if (isset($this->options['persist']) && is_array($redirect)) {

View file

@ -434,7 +434,7 @@ class Router {
$options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options); $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(); self::$_namedConfig['rules'] = array();
} }
@ -1090,7 +1090,7 @@ class Router {
* @return string base url with plugin name removed if present * @return string base url with plugin name removed if present
*/ */
public static function stripPlugin($base, $plugin = null) { public static function stripPlugin($base, $plugin = null) {
if ($plugin != null) { if ($plugin) {
$base = preg_replace('/(?:' . $plugin . ')/', '', $base); $base = preg_replace('/(?:' . $plugin . ')/', '', $base);
$base = str_replace('//', '', $base); $base = str_replace('//', '', $base);
$pos1 = strrpos($base, '/'); $pos1 = strrpos($base, '/');

View file

@ -58,7 +58,7 @@ class ModelWriteTest extends BaseModelTest {
$lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID();
$data['id'] = $lastInsertId; $data['id'] = $lastInsertId;
$this->assertEquals(array('JoinAsJoinB' => $data), $result); $this->assertEquals(array('JoinAsJoinB' => $data), $result);
$this->assertTrue($lastInsertId != null); $this->assertTrue($lastInsertId);
$result = $TestModel->JoinAsJoinB->findById(1); $result = $TestModel->JoinAsJoinB->findById(1);
$expected = array( $expected = array(

View file

@ -980,7 +980,7 @@ class CakeRequestTest extends CakeTestCase {
* @return void * @return void
*/ */
public function detectCallback($request) { public function detectCallback($request) {
return $request->return == true; return (bool)$request->return;
} }
/** /**

View file

@ -1168,7 +1168,7 @@ class CakeEmailTest extends CakeTestCase {
$this->CakeEmail->emailFormat('html'); $this->CakeEmail->emailFormat('html');
$server = env('SERVER_NAME') ? env('SERVER_NAME') : 'localhost'; $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'); $server .= ':' . env('SERVER_PORT');
} }

View file

@ -73,7 +73,7 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
); );
} }
if (count($suite) == 0) { if (!count($suite)) {
$skeleton = new PHPUnit_Util_Skeleton_Test( $skeleton = new PHPUnit_Util_Skeleton_Test(
$suite->getName(), $suite->getName(),
$this->arguments['testFile'] $this->arguments['testFile']

View file

@ -200,7 +200,7 @@ class CakeFixtureManager {
return; return;
} }
$fixtures = $test->fixtures; $fixtures = $test->fixtures;
if (empty($fixtures) || $test->autoFixtures == false) { if (empty($fixtures) || !$test->autoFixtures) {
return; return;
} }

View file

@ -71,10 +71,10 @@ class CakeTextReporter extends CakeBaseReporter {
* @return void * @return void
*/ */
public function paintFooter($result) { public function paintFooter($result) {
if ($result->failureCount() + $result->errorCount() == 0) { if ($result->failureCount() + $result->errorCount()) {
echo "\nOK\n";
} else {
echo "FAILURES!!!\n"; echo "FAILURES!!!\n";
} else {
echo "\nOK\n";
} }
echo "Test cases run: " . $result->count() . echo "Test cases run: " . $result->count() .

View file

@ -296,8 +296,8 @@ class CakeNumber {
$result = $options['before'] = $options['after'] = null; $result = $options['before'] = $options['after'] = null;
$symbolKey = 'whole'; $symbolKey = 'whole';
if ($value == 0) { if (!$value) {
if ($options['zero'] !== 0) { if ($options['zero'] !== 0 ) {
return $options['zero']; return $options['zero'];
} }
} elseif ($value < 1 && $value > -1) { } elseif ($value < 1 && $value > -1) {

View file

@ -745,7 +745,7 @@ class CakeTime {
$years = floor($months / 12); $years = floor($months / 12);
$months = $months - ($years * 12); $months = $months - ($years * 12);
} }
if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] == 1) { if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] === 1) {
$years--; $years--;
} }
@ -766,7 +766,7 @@ class CakeTime {
} }
} }
if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) { if (!$months && $years >= 1 && $diff < ($years * 31536000)) {
$months = 11; $months = 11;
$years--; $years--;
} }
@ -795,7 +795,7 @@ class CakeTime {
} }
$diff = $futureTime - $pastTime; $diff = $futureTime - $pastTime;
if ($diff == 0) { if (!$diff) {
return __d('cake', 'just now', 'just now'); return __d('cake', 'just now', 'just now');
} }
@ -903,7 +903,7 @@ class CakeTime {
*/ */
public static function gmt($dateString = null) { public static function gmt($dateString = null) {
$time = time(); $time = time();
if ($dateString != null) { if ($dateString) {
$time = self::fromString($dateString); $time = self::fromString($dateString);
} }
return gmmktime( return gmmktime(

View file

@ -474,7 +474,7 @@ class Debugger {
case 'float': case 'float':
return '(float) ' . $var; return '(float) ' . $var;
case 'string': case 'string':
if (trim($var) == '') { if (!trim($var)) {
return "''"; return "''";
} }
return "'" . $var . "'"; return "'" . $var . "'";

View file

@ -302,7 +302,7 @@ class File {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::info * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::info
*/ */
public function info() { public function info() {
if ($this->info == null) { if (!$this->info) {
$this->info = pathinfo($this->path); $this->info = pathinfo($this->path);
} }
if (!isset($this->info['filename'])) { 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 * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::ext
*/ */
public function ext() { public function ext() {
if ($this->info == null) { if (!$this->info) {
$this->info(); $this->info();
} }
if (isset($this->info['extension'])) { 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 * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::name
*/ */
public function name() { public function name() {
if ($this->info == null) { if (!$this->info) {
$this->info(); $this->info();
} }
if (isset($this->info['extension'])) { if (isset($this->info['extension'])) {

View file

@ -425,7 +425,7 @@ class Folder {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::tree * @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) { public function tree($path = null, $exceptions = false, $type = null) {
if ($path == null) { if (!$path) {
$path = $this->path; $path = $this->path;
} }
$files = array(); $files = array();

View file

@ -108,7 +108,7 @@ class Security {
} }
} }
if ($type == 'sha1' || $type == null) { if (!$type || $type == 'sha1') {
if (function_exists('sha1')) { if (function_exists('sha1')) {
$return = sha1($string); $return = sha1($string);
return $return; return $return;

View file

@ -349,7 +349,7 @@ class Set {
$context = array('trace' => array(null), 'item' => $context, 'key' => $key); $context = array('trace' => array(null), 'item' => $context, 'key' => $key);
} }
if ($token === '..') { if ($token === '..') {
if (count($context['trace']) == 1) { if (count($context['trace']) === 1) {
$context['trace'][] = $context['key']; $context['trace'][] = $context['key'];
} }
$parent = implode('/', $context['trace']) . '/.'; $parent = implode('/', $context['trace']) . '/.';
@ -373,7 +373,7 @@ class Set {
); );
} elseif (is_array($context['item']) } elseif (is_array($context['item'])
&& array_key_exists($token, $context['item']) && array_key_exists($token, $context['item'])
&& !(strval($key) === strval($token) && count($tokens) == 1 && $tokens[0] === '.')) { && !(strval($key) === strval($token) && count($tokens) === 1 && $tokens[0] === '.')) {
$items = $context['item'][$token]; $items = $context['item'][$token];
if (!is_array($items)) { if (!is_array($items)) {
$items = array($items); $items = array($items);
@ -827,7 +827,7 @@ class Set {
} }
} }
if ($groupPath != null) { if ($groupPath) {
$group = Set::extract($data, $groupPath); $group = Set::extract($data, $groupPath);
if (!empty($group)) { if (!empty($group)) {
$c = count($keys); $c = count($keys);

View file

@ -134,7 +134,7 @@ class String {
} }
if ($tmpOffset !== -1) { if ($tmpOffset !== -1) {
$buffer .= substr($data, $offset, ($tmpOffset - $offset)); $buffer .= substr($data, $offset, ($tmpOffset - $offset));
if ($data{$tmpOffset} == $separator && $depth == 0) { if (!$depth && $data{$tmpOffset} == $separator) {
$results[] = $buffer; $results[] = $buffer;
$buffer = ''; $buffer = '';
} else { } else {

View file

@ -860,7 +860,7 @@ class Validation {
if ($deep !== true) { if ($deep !== true) {
return true; return true;
} }
if ($check == 0) { if (!$check) {
return false; return false;
} }
$sum = 0; $sum = 0;
@ -875,7 +875,7 @@ class Validation {
$sum += ($number < 10) ? $number : $number - 9; $sum += ($number < 10) ? $number : $number - 9;
} }
return ($sum % 10 == 0); return ($sum % 10 === 0);
} }
/** /**

View file

@ -500,7 +500,7 @@ class Helper extends Object {
// Either 'body' or 'date.month' type inputs. // Either 'body' or 'date.month' type inputs.
if ( if (
($count === 1 && $this->_modelScope && $setScope == false) || ($count === 1 && $this->_modelScope && !$setScope) ||
( (
$count === 2 && $count === 2 &&
in_array($lastPart, $this->_fieldSuffixes) && in_array($lastPart, $this->_fieldSuffixes) &&
@ -526,12 +526,11 @@ class Helper extends Object {
$isHabtm = ( $isHabtm = (
isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) && isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' && $this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
$count == 1
); );
// habtm models are special // habtm models are special
if ($count == 1 && $isHabtm) { if ($count === 1 && $isHabtm) {
$this->_association = $parts[0]; $this->_association = $parts[0];
$entity = $parts[0] . '.' . $parts[0]; $entity = $parts[0] . '.' . $parts[0];
} else { } else {
@ -750,7 +749,7 @@ class Helper extends Object {
* @return array Array of options with $key set. * @return array Array of options with $key set.
*/ */
public function addClass($options = array(), $class = null, $key = 'class') { 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; $options[$key] .= ' ' . $class;
} else { } else {
$options[$key] = $class; $options[$key] = $class;

View file

@ -59,7 +59,7 @@ class CacheHelper extends AppHelper {
* @return boolean * @return boolean
*/ */
protected function _enabled() { protected function _enabled() {
return (($this->_View->cacheAction != false)) && (Configure::read('Cache.check') === true); return $this->_View->cacheAction && (Configure::read('Cache.check') === true);
} }
/** /**
@ -148,7 +148,7 @@ class CacheHelper extends AppHelper {
$cacheTime = $cacheAction; $cacheTime = $cacheAction;
} }
if ($cacheTime != '' && $cacheTime > 0) { if ($cacheTime && $cacheTime > 0) {
$cached = $this->_parseOutput($out); $cached = $this->_parseOutput($out);
try { try {
$this->_writeFile($cached, $cacheTime, $useCallbacks); $this->_writeFile($cached, $cacheTime, $useCallbacks);
@ -312,7 +312,7 @@ class CacheHelper extends AppHelper {
Router::setRequestInfo($controller->request); Router::setRequestInfo($controller->request);
$this->request = $request;'; $this->request = $request;';
if ($useCallbacks == true) { if ($useCallbacks) {
$file .= ' $file .= '
$controller->constructClasses(); $controller->constructClasses();
$controller->startupProcess();'; $controller->startupProcess();';

View file

@ -412,7 +412,7 @@ class FormHelper extends AppHelper {
$action = $this->url($options['action']); $action = $this->url($options['action']);
unset($options['type'], $options['action']); unset($options['type'], $options['action']);
if ($options['default'] == false) { if (!$options['default']) {
if (!isset($options['onsubmit'])) { if (!isset($options['onsubmit'])) {
$options['onsubmit'] = ''; $options['onsubmit'] = '';
} }
@ -1289,7 +1289,7 @@ class FormHelper extends AppHelper {
'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'), 'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'),
'secure' => false 'secure' => false
); );
if (isset($options['disabled']) && $options['disabled'] == true) { if (isset($options['disabled']) && $options['disabled']) {
$hiddenOptions['disabled'] = 'disabled'; $hiddenOptions['disabled'] = 'disabled';
} }
$output = $this->hidden($fieldName, $hiddenOptions); $output = $this->hidden($fieldName, $hiddenOptions);
@ -1870,7 +1870,7 @@ class FormHelper extends AppHelper {
// Secure the field if there are options, or its a multi select. // Secure the field if there are options, or its a multi select.
// Single selects with no options don't submit, but multiselects do. // Single selects with no options don't submit, but multiselects do.
if ( if (
(!isset($secure) || $secure == true) && (!isset($secure) || $secure) &&
empty($attributes['disabled']) && empty($attributes['disabled']) &&
(!empty($attributes['multiple']) || $hasOptions) (!empty($attributes['multiple']) || $hasOptions)
) { ) {
@ -2235,7 +2235,7 @@ class FormHelper extends AppHelper {
} elseif ($time[0] >= 12) { } elseif ($time[0] >= 12) {
$meridian = 'pm'; $meridian = 'pm';
} }
if ($time[0] == 0 && $timeFormat == '12') { if (!$time[0] && $timeFormat == '12') {
$time[0] = 12; $time[0] = 12;
} }
$hour = $min = null; $hour = $min = null;

View file

@ -359,7 +359,7 @@ class HtmlHelper extends AppHelper {
$confirmMessage = str_replace("'", "\'", $confirmMessage); $confirmMessage = str_replace("'", "\'", $confirmMessage);
$confirmMessage = str_replace('"', '\"', $confirmMessage); $confirmMessage = str_replace('"', '\"', $confirmMessage);
$options['onclick'] = "return confirm('{$confirmMessage}');"; $options['onclick'] = "return confirm('{$confirmMessage}');";
} elseif (isset($options['default']) && $options['default'] == false) { } elseif (isset($options['default']) && !$options['default']) {
if (isset($options['onclick'])) { if (isset($options['onclick'])) {
$options['onclick'] .= ' event.returnValue = false; return false;'; $options['onclick'] .= ' event.returnValue = false; return false;';
} else { } else {
@ -441,7 +441,7 @@ class HtmlHelper extends AppHelper {
if ($rel == 'import') { if ($rel == 'import') {
$out = sprintf($this->_tags['style'], $this->_parseAttributes($options, array('inline', 'block'), '', ' '), '@import url(' . $url . ');'); $out = sprintf($this->_tags['style'], $this->_parseAttributes($options, array('inline', 'block'), '', ' '), '@import url(' . $url . ');');
} else { } else {
if ($rel == null) { if (!$rel) {
$rel = 'stylesheet'; $rel = 'stylesheet';
} }
$out = sprintf($this->_tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline', 'block'), '', ' ')); $out = sprintf($this->_tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline', 'block'), '', ' '));
@ -701,7 +701,7 @@ class HtmlHelper extends AppHelper {
} else { } else {
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]); $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
} }
if ($which == 0) { if (!$which) {
$options['class'] = 'first'; $options['class'] = 'first';
} elseif ($which == $crumbCount - 1) { } elseif ($which == $crumbCount - 1) {
$options['class'] = 'last'; $options['class'] = 'last';
@ -951,13 +951,12 @@ class HtmlHelper extends AppHelper {
if (isset($options['escape'])) { if (isset($options['escape'])) {
$text = h($text); $text = h($text);
} }
if ($class != null && !empty($class)) { if ($class && !empty($class)) {
$options['class'] = $class; $options['class'] = $class;
} }
$tag = 'para';
if ($text === null) { if ($text === null) {
$tag = 'parastart'; $tag = 'parastart';
} else {
$tag = 'para';
} }
return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text); return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
} }
@ -1116,9 +1115,9 @@ class HtmlHelper extends AppHelper {
if (is_array($item)) { if (is_array($item)) {
$item = $key . $this->nestedList($item, $options, $itemOptions, $tag); $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']; $itemOptions['class'] = $itemOptions['even'];
} elseif (isset($itemOptions['odd']) && $index % 2 != 0) { } elseif (isset($itemOptions['odd']) && $index % 2 !== 0) {
$itemOptions['class'] = $itemOptions['odd']; $itemOptions['class'] = $itemOptions['odd'];
} }
$out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item); $out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item);

View file

@ -338,7 +338,7 @@ class JsHelper extends AppHelper {
} else { } else {
$data = array($one => $two); $data = array($one => $two);
} }
if ($data == null) { if (!$data) {
return false; return false;
} }
$this->_jsVars = array_merge($this->_jsVars, $data); $this->_jsVars = array_merge($this->_jsVars, $data);

View file

@ -526,12 +526,7 @@ class PaginatorHelper extends AppHelper {
*/ */
protected function _hasPage($model, $page) { protected function _hasPage($model, $page) {
$params = $this->params($model); $params = $this->params($model);
if (!empty($params)) { return !empty($params) && $params[$page . 'Page'];
if ($params["{$page}Page"] == true) {
return true;
}
}
return false;
} }
/** /**
@ -541,7 +536,7 @@ class PaginatorHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel
*/ */
public function defaultModel() { public function defaultModel() {
if ($this->_defaultModel != null) { if ($this->_defaultModel) {
return $this->_defaultModel; return $this->_defaultModel;
} }
if (empty($this->request->params['paging'])) { if (empty($this->request->params['paging'])) {
@ -583,7 +578,7 @@ class PaginatorHelper extends AppHelper {
$options); $options);
$paging = $this->params($options['model']); $paging = $this->params($options['model']);
if ($paging['pageCount'] == 0) { if (!$paging['pageCount']) {
$paging['pageCount'] = 1; $paging['pageCount'] = 1;
} }
$start = 0; $start = 0;

View file

@ -167,7 +167,7 @@ class RssHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::items * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::items
*/ */
public function items($items, $callback = null) { public function items($items, $callback = null) {
if ($callback != null) { if ($callback) {
$items = array_map($callback, $items); $items = array_map($callback, $items);
} }

View file

@ -134,7 +134,7 @@ class SessionHelper extends AppHelper {
$class = $flash['params']['class']; $class = $flash['params']['class'];
} }
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>';
} elseif ($flash['element'] == '' || $flash['element'] == null) { } elseif (!$flash['element']) {
$out = $message; $out = $message;
} else { } else {
$options = array(); $options = array();

View file

@ -766,7 +766,7 @@ class View extends Object {
} else { } else {
$data = array($one => $two); $data = array($one => $two);
} }
if ($data == null) { if (!$data) {
return false; return false;
} }
$this->viewVars = $data + $this->viewVars; $this->viewVars = $data + $this->viewVars;

View file

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