Skip to content

Commit

Permalink
converting $foo == / $foo == 0 to !$foo (and a few $foo === 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Sep 14, 2012
1 parent cf8fcca commit 22a2e1b
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 62 deletions.
5 changes: 2 additions & 3 deletions lib/Cake/Cache/Engine/ApcEngine.php
Expand Up @@ -61,9 +61,8 @@ public function init($settings = array()) {
* @return boolean True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
if ($duration == 0) {
$expires = 0;
} else {
$expires = 0;
if ($duration) {
$expires = time() + $duration;
}
apc_store($key . '_expires', $expires, $duration);
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/Task/ControllerTask.php
Expand Up @@ -419,14 +419,14 @@ public function getName($useDbConfig = null) {
$controllers = $this->listAll($useDbConfig);
$enteredController = '';

while ($enteredController == '') {
while (!$enteredController) {
$enteredController = $this->in(__d('cake_console', "Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit"), null, 'q');
if ($enteredController === 'q') {
$this->out(__d('cake_console', 'Exit'));
return $this->_stop();
}

if ($enteredController == '' || intval($enteredController) > count($controllers)) {
if (!$enteredController || intval($enteredController) > count($controllers)) {
$this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
$enteredController = '';
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Cake/Console/Command/Task/DbConfigTask.php
Expand Up @@ -95,7 +95,7 @@ protected function _interactive() {
while (!$done) {
$name = '';

while ($name == '') {
while (!$name) {
$name = $this->in(__d('cake_console', "Name:"), null, 'default');
if (preg_match('/[^a-z0-9_]/i', $name)) {
$name = '';
Expand All @@ -116,12 +116,12 @@ protected function _interactive() {
}

$host = '';
while ($host == '') {
while (!$host) {
$host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost');
}

$port = '';
while ($port == '') {
while (!$port) {
$port = $this->in(__d('cake_console', 'Port?'), null, 'n');
}

Expand All @@ -130,16 +130,16 @@ protected function _interactive() {
}

$login = '';
while ($login == '') {
while (!$login) {
$login = $this->in(__d('cake_console', 'User:'), null, 'root');
}
$password = '';
$blankPassword = false;

while ($password == '' && !$blankPassword) {
while (!$password && !$blankPassword) {
$password = $this->in(__d('cake_console', 'Password:'));

if ($password == '') {
if (!$password) {
$blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n');
if ($blank == 'y') {
$blankPassword = true;
Expand All @@ -148,20 +148,20 @@ protected function _interactive() {
}

$database = '';
while ($database == '') {
while (!$database) {
$database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake');
}

$prefix = '';
while ($prefix == '') {
while (!$prefix) {
$prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n');
}
if (strtolower($prefix) == 'n') {
$prefix = null;
}

$encoding = '';
while ($encoding == '') {
while (!$encoding) {
$encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n');
}
if (strtolower($encoding) == 'n') {
Expand All @@ -170,7 +170,7 @@ protected function _interactive() {

$schema = '';
if ($datasource == 'postgres') {
while ($schema == '') {
while (!$schema) {
$schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n');
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/Task/ExtractTask.php
Expand Up @@ -391,7 +391,7 @@ protected function _parse($functionName, $map) {
$position = $count;
$depth = 0;

while ($depth == 0) {
while (!$depth) {
if ($this->_tokens[$position] == '(') {
$depth++;
} elseif ($this->_tokens[$position] == ')') {
Expand Down Expand Up @@ -591,7 +591,7 @@ protected function _writeFiles() {
);
if (strtoupper($response) === 'N') {
$response = '';
while ($response == '') {
while (!$response) {
$response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename);
$File = new File($this->_output . $response);
$filename = $response;
Expand Down
13 changes: 6 additions & 7 deletions lib/Cake/Console/Command/Task/ModelTask.php
Expand Up @@ -700,7 +700,7 @@ public function doMoreAssociations(Model $model, $associations) {
$alias = $this->in(__d('cake_console', 'What is the alias for this association?'));
$className = $this->in(__d('cake_console', 'What className will %s use?', $alias), null, $alias );

if ($assocType == 0) {
if (!$assocType) {
if (!empty($possibleKeys[$model->table])) {
$showKeys = $possibleKeys[$model->table];
} else {
Expand Down Expand Up @@ -935,7 +935,7 @@ public function getName($useDbConfig = null) {

$enteredModel = '';

while ($enteredModel == '') {
while (!$enteredModel) {
$enteredModel = $this->in(__d('cake_console', "Enter a number from the list above,\n" .
"type in the name of another model, or 'q' to exit"), null, 'q');

Expand All @@ -944,18 +944,17 @@ public function getName($useDbConfig = null) {
$this->_stop();
}

if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) {
if (!$enteredModel || intval($enteredModel) > count($this->_modelNames)) {
$this->err(__d('cake_console', "The model name you supplied was empty,\n" .
"or the number you selected was not an option. Please try again."));
$enteredModel = '';
}
}
if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
$currentModelName = $this->_modelNames[intval($enteredModel) - 1];
} else {
$currentModelName = $enteredModel;
return $this->_modelNames[intval($enteredModel) - 1];
}
return $currentModelName;

return $enteredModel;
}

/**
Expand Down
7 changes: 2 additions & 5 deletions lib/Cake/Console/Command/Task/ProjectTask.php
Expand Up @@ -349,10 +349,7 @@ protected function _replaceCorePath($filename, $hardCode) {
if (!file_put_contents($filename, $result)) {
return false;
}
if ($count == 0) {
return false;
}
return true;
return (bool)$count;
}

/**
Expand Down Expand Up @@ -409,7 +406,7 @@ public function getPrefix() {
$this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/Config/core.php to use prefix routing.'));
$this->out(__d('cake_console', 'What would you like the prefix route to be?'));
$this->out(__d('cake_console', 'Example: www.example.com/admin/controller'));
while ($admin == '') {
while (!$admin) {
$admin = $this->in(__d('cake_console', 'Enter a routing prefix:'), null, 'admin');
}
if ($this->cakeAdmin($admin) !== true) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/Task/ViewTask.php
Expand Up @@ -316,9 +316,9 @@ public function bakeActions($actions, $vars) {
*/
public function customAction() {
$action = '';
while ($action == '') {
while (!$action) {
$action = $this->in(__d('cake_console', 'Action Name? (use lowercase_underscored function name)'));
if ($action == '') {
if (!$action) {
$this->out(__d('cake_console', 'The action name you supplied was empty. Please try again.'));
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/ConsoleErrorHandler.php
Expand Up @@ -81,7 +81,7 @@ public function handleError($code, $description, $file = null, $line = null, $co
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
$stderr->write(__d('cake_console', "<error>%s Error:</error> %s\n", $name, $message));

if (Configure::read('debug') == 0) {
if (!Configure::read('debug')) {
CakeLog::write($log, $message);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Component/Acl/PhpAcl.php
Expand Up @@ -170,11 +170,11 @@ public function check($aro, $aco, $action = "*") {
foreach ($path as $depth => $node) {
foreach ($prioritizedAros as $aros) {
if (!empty($node['allow'])) {
$allow = $allow || count(array_intersect($node['allow'], $aros)) > 0;
$allow = $allow || count(array_intersect($node['allow'], $aros));
}

if (!empty($node['deny'])) {
$allow = $allow && count(array_intersect($node['deny'], $aros)) == 0;
$allow = $allow && !count(array_intersect($node['deny'], $aros));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/CookieComponent.php
Expand Up @@ -381,7 +381,7 @@ protected function _expire($expires = null) {
}
$this->_reset = $this->_expires;

if ($expires == 0) {
if (!$expires) {
return $this->_expires = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Error/ExceptionRenderer.php
Expand Up @@ -119,7 +119,7 @@ public function __construct(Exception $exception) {
}
}

if (Configure::read('debug') == 0) {
if (!Configure::read('debug')) {
if ($method == '_cakeError') {
$method = 'error400';
}
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function _cakeError(CakeException $error) {
*/
public function error400($error) {
$message = $error->getMessage();
if (Configure::read('debug') == 0 && $error instanceof CakeException) {
if (!Configure::read('debug') && $error instanceof CakeException) {
$message = __d('cake', 'Not Found');
}
$url = $this->controller->request->here();
Expand All @@ -227,7 +227,7 @@ public function error400($error) {
*/
public function error500($error) {
$message = $error->getMessage();
if (Configure::read('debug') == 0) {
if (!Configure::read('debug')) {
$message = __d('cake', 'An Internal Error Has Occurred.');
}
$url = $this->controller->request->here();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/I18n.php
Expand Up @@ -412,7 +412,7 @@ public static function loadMo($filename) {
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
extract($header);

if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) {
if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && !$version) {
for ($n = 0; $n < $count; $n++) {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -798,7 +798,7 @@ public function verify(Model $Model) {
$scope, 'OR' => array($Model->escapeField($left) => $i, $Model->escapeField($right) => $i)
)));
if ($count != 1) {
if ($count == 0) {
if (!$count) {
$errors[] = array('index', $i, 'missing');
} else {
$errors[] = array('index', $i, 'duplicate');
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -433,7 +433,7 @@ public function index($model) {
if (!isset($index[$idx->Key_name]['column'])) {
$col = array();
$index[$idx->Key_name]['column'] = $idx->Column_name;
$index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0);
$index[$idx->Key_name]['unique'] = intval(!$idx->Non_unique);
} else {
if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) {
$col[] = $index[$idx->Key_name]['column'];
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -732,7 +732,7 @@ public function lastAffected($source = null) {
*/
protected function _execute($sql, $params = array(), $prepareOptions = array()) {
$this->_lastAffected = false;
if (strncasecmp($sql, 'SELECT', 6) == 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) {
if (strncasecmp($sql, 'SELECT', 6) === 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) {
$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1053,7 +1053,7 @@ public function read(Model $model, $queryData = array(), $recursive = null) {

if ($model->recursive == -1) {
$_associations = array();
} elseif ($model->recursive == 0) {
} elseif (!$model->recursive) {
unset($_associations[2], $_associations[3]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -2980,7 +2980,7 @@ public function isUnique($fields, $or = true) {
if (!empty($this->id)) {
$fields[$this->alias . '.' . $this->primaryKey . ' !='] = $this->id;
}
return ($this->find('count', array('conditions' => $fields, 'recursive' => -1)) == 0);
return !$this->find('count', array('conditions' => $fields, 'recursive' => -1));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Http/HttpResponse.php
Expand Up @@ -108,7 +108,7 @@ public function getHeader($name, $headers = null) {
return $headers[$name];
}
foreach ($headers as $key => $value) {
if (strcasecmp($key, $name) == 0) {
if (strcasecmp($key, $name) === 0) {
return $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Dispatcher.php
Expand Up @@ -209,7 +209,7 @@ protected function _invoke(Controller $controller, CakeRequest $request, CakeRes
public function parseParams($event) {
$request = $event->data['request'];
Router::setRequestInfo($request);
if (count(Router::$routes) == 0) {
if (!count(Router::$routes)) {
$namedExpressions = Router::getNamedExpressions();
extract($namedExpressions);
$this->_loadRoutes();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/TestSuite/CakeTestSuiteCommand.php
Expand Up @@ -73,7 +73,7 @@ public function run(array $argv, $exit = true) {
);
}

if (count($suite) == 0) {
if (!count($suite)) {
$skeleton = new PHPUnit_Util_Skeleton_Test(
$suite->getName(),
$this->arguments['testFile']
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/TestSuite/Reporter/CakeTextReporter.php
Expand Up @@ -71,10 +71,10 @@ public function paintFail($message) {
* @return void
*/
public function paintFooter($result) {
if ($result->failureCount() + $result->errorCount() == 0) {
echo "\nOK\n";
} else {
if ($result->failureCount() + $result->errorCount()) {
echo "FAILURES!!!\n";
} else {
echo "\nOK\n";
}

echo "Test cases run: " . $result->count() .
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/CakeNumber.php
Expand Up @@ -241,7 +241,7 @@ public static function currency($number, $currency = 'USD', $options = array())
$result = $options['before'] = $options['after'] = null;

$symbolKey = 'whole';
if ($number == 0 ) {
if (!$number) {
if ($options['zero'] !== 0 ) {
return $options['zero'];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/CakeTime.php
Expand Up @@ -766,7 +766,7 @@ public static function timeAgoInWords($dateTime, $options = array()) {
}
}

if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) {
if (!$months && $years >= 1 && $diff < ($years * 31536000)) {
$months = 11;
$years--;
}
Expand Down Expand Up @@ -795,7 +795,7 @@ public static function timeAgoInWords($dateTime, $options = array()) {
}
$diff = $futureTime - $pastTime;

if ($diff == 0) {
if (!$diff) {
return __d('cake', 'just now', 'just now');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Debugger.php
Expand Up @@ -475,7 +475,7 @@ protected static function _export($var, $depth, $indent) {
case 'float':
return '(float) ' . $var;
case 'string':
if (trim($var) == '') {
if (!trim($var)) {
return "''";
}
return "'" . $var . "'";
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/String.php
Expand Up @@ -134,7 +134,7 @@ public static function tokenize($data, $separator = ',', $leftBound = '(', $righ
}
if ($tmpOffset !== -1) {
$buffer .= substr($data, $offset, ($tmpOffset - $offset));
if ($data{$tmpOffset} == $separator && $depth == 0) {
if (!$depth && $data{$tmpOffset} == $separator) {
$results[] = $buffer;
$buffer = '';
} else {
Expand Down

0 comments on commit 22a2e1b

Please sign in to comment.