converting $foo == / $foo == 0 to !$foo (and a few $foo === 0)

This commit is contained in:
dogmatic69 2012-09-14 18:42:25 +01:00
parent cf8fccae96
commit 22a2e1b51e
29 changed files with 57 additions and 62 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;
} else { if ($duration) {
$expires = time() + $duration; $expires = time() + $duration;
} }
apc_store($key . '_expires', $expires, $duration); apc_store($key . '_expires', $expires, $duration);

View file

@ -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

@ -95,7 +95,7 @@ class DbConfigTask extends AppShell {
while (!$done) { 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) { 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');
} }
} }

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] == ')') {
@ -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

@ -700,7 +700,7 @@ class ModelTask extends BakeTask {
$alias = $this->in(__d('cake_console', 'What is the alias for this association?')); $alias = $this->in(__d('cake_console', 'What is the alias for this association?'));
$className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias ); $className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias );
if ($assocType == 0) { if (!$assocType) {
if (!empty($possibleKeys[$model->table])) { if (!empty($possibleKeys[$model->table])) {
$showKeys = $possibleKeys[$model->table]; $showKeys = $possibleKeys[$model->table];
} else { } else {
@ -935,7 +935,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 +944,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

@ -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;
} }
/** /**
@ -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

@ -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

@ -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

@ -381,7 +381,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;
} }

View file

@ -119,7 +119,7 @@ class ExceptionRenderer {
} }
} }
if (Configure::read('debug') == 0) { if (!Configure::read('debug')) {
if ($method == '_cakeError') { if ($method == '_cakeError') {
$method = 'error400'; $method = 'error400';
} }
@ -205,7 +205,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();
@ -227,7 +227,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

@ -412,7 +412,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

@ -798,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

@ -433,7 +433,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;
$index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0); $index[$idx->Key_name]['unique'] = intval(!$idx->Non_unique);
} else { } else {
if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) { if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) {
$col[] = $index[$idx->Key_name]['column']; $col[] = $index[$idx->Key_name]['column'];

View file

@ -732,7 +732,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

@ -1053,7 +1053,7 @@ class DboSource extends DataSource {
if ($model->recursive == -1) { if ($model->recursive == -1) {
$_associations = array(); $_associations = array();
} elseif ($model->recursive == 0) { } elseif (!$model->recursive) {
unset($_associations[2], $_associations[3]); unset($_associations[2], $_associations[3]);
} }

View file

@ -2980,7 +2980,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));
} }
/** /**

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;
} }
} }

View file

@ -209,7 +209,7 @@ class Dispatcher implements CakeEventListener {
public function parseParams($event) { public function parseParams($event) {
$request = $event->data['request']; $request = $event->data['request'];
Router::setRequestInfo($request); Router::setRequestInfo($request);
if (count(Router::$routes) == 0) { if (!count(Router::$routes)) {
$namedExpressions = Router::getNamedExpressions(); $namedExpressions = Router::getNamedExpressions();
extract($namedExpressions); extract($namedExpressions);
$this->_loadRoutes(); $this->_loadRoutes();

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

@ -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

@ -241,7 +241,7 @@ class CakeNumber {
$result = $options['before'] = $options['after'] = null; $result = $options['before'] = $options['after'] = null;
$symbolKey = 'whole'; $symbolKey = 'whole';
if ($number == 0 ) { if (!$number) {
if ($options['zero'] !== 0 ) { if ($options['zero'] !== 0 ) {
return $options['zero']; return $options['zero'];
} }

View file

@ -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');
} }

View file

@ -475,7 +475,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

@ -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

@ -859,7 +859,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;
@ -874,7 +874,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

@ -2228,7 +2228,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

@ -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';
@ -1116,9 +1116,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

@ -583,7 +583,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;