converting if ($foo != null) to if ($foo)

This commit is contained in:
dogmatic69 2012-09-21 23:30:43 +01:00
parent f5a8eb6bbf
commit b1f26b59a3
21 changed files with 60 additions and 62 deletions

View file

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

View file

@ -398,7 +398,7 @@ class RequestHandlerComponent extends Component {
* @return string Prototype version of component making Ajax call
*/
public function getAjaxVersion() {
if (env('HTTP_X_PROTOTYPE_VERSION') != null) {
if (env('HTTP_X_PROTOTYPE_VERSION')) {
return env('HTTP_X_PROTOTYPE_VERSION');
}
return false;
@ -672,7 +672,7 @@ class RequestHandlerComponent extends Component {
$cType = $type;
}
if ($cType != null) {
if ($cType) {
if (empty($this->request->params['requested'])) {
$this->response->type($cType);
}

View file

@ -967,14 +967,15 @@ class Controller extends Object implements CakeEventListener {
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer
*/
public function referer($default = null, $local = false) {
if ($this->request) {
$referer = $this->request->referer($local);
if ($referer == '/' && $default != null) {
return Router::url($default, true);
}
return $referer;
if(!$this->request) {
return '/';
}
return '/';
$referer = $this->request->referer($local);
if ($referer == '/' && $default) {
return Router::url($default, true);
}
return $referer;
}
/**
@ -1062,7 +1063,7 @@ class Controller extends Object implements CakeEventListener {
$cond[$key] = $value;
}
}
if ($bool != null && strtoupper($bool) != 'AND') {
if ($bool && strtoupper($bool) != 'AND') {
$cond = array($bool => $cond);
}
return $cond;

View file

@ -131,7 +131,7 @@ class CakeSession {
self::$time = time();
$checkAgent = Configure::read('Session.checkAgent');
if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT') != null) {
if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT')) {
self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
}
self::_setPath($base);

View file

@ -175,7 +175,7 @@ class Mysql extends DboSource {
*/
public function listSources($data = null) {
$cache = parent::listSources();
if ($cache != null) {
if ($cache) {
return $cache;
}
$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
@ -280,7 +280,7 @@ class Mysql extends DboSource {
public function describe($model) {
$key = $this->fullTableName($model, false);
$cache = parent::describe($key);
if ($cache != null) {
if ($cache) {
return $cache;
}
$table = $this->fullTableName($model);

View file

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

View file

@ -136,7 +136,7 @@ class Sqlite extends DboSource {
*/
public function listSources($data = null) {
$cache = parent::listSources();
if ($cache != null) {
if ($cache) {
return $cache;
}
@ -144,14 +144,14 @@ class Sqlite extends DboSource {
if (!$result || empty($result)) {
return array();
} else {
$tables = array();
foreach ($result as $table) {
$tables[] = $table[0]['name'];
}
parent::listSources($tables);
return $tables;
}
$tables = array();
foreach ($result as $table) {
$tables[] = $table[0]['name'];
}
parent::listSources($tables);
return $tables;
}
/**
@ -163,7 +163,7 @@ class Sqlite extends DboSource {
public function describe($model) {
$table = $this->fullTableName($model, false, false);
$cache = parent::describe($table);
if ($cache != null) {
if ($cache) {
return $cache;
}
$fields = array();

View file

@ -184,7 +184,7 @@ class Sqlserver extends DboSource {
public function describe($model) {
$table = $this->fullTableName($model, false);
$cache = parent::describe($table);
if ($cache != null) {
if ($cache) {
return $cache;
}
$fields = array();
@ -619,7 +619,7 @@ class Sqlserver extends DboSource {
*/
public function insertMulti($table, $fields, $values) {
$primaryKey = $this->_getPrimaryKey($table);
$hasPrimaryKey = $primaryKey != null && (
$hasPrimaryKey = $primaryKey && (
(is_array($fields) && in_array($primaryKey, $fields)
|| (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false))
);

View file

@ -670,7 +670,7 @@ class DboSource extends DataSource {
if ($this->hasResult()) {
$first = $this->fetchRow();
if ($first != null) {
if ($first) {
$out[] = $first;
}
while ($item = $this->fetchResult()) {
@ -1407,10 +1407,9 @@ class DboSource extends DataSource {
}
}
if (!isset($data[$association])) {
if ($merge[0][$association] != null) {
$data[$association] = array();
if ($merge[0][$association]) {
$data[$association] = $merge[0][$association];
} else {
$data[$association] = array();
}
} else {
if (is_array($merge[0][$association])) {
@ -2513,7 +2512,7 @@ class DboSource extends DataSource {
$data = $this->_parseKey($model, trim($key), $value);
}
if ($data != null) {
if ($data) {
$out[] = $data;
$data = null;
}

View file

@ -1389,7 +1389,7 @@ class Model extends Object implements CakeEventListener {
$this->schema();
}
if ($this->_schema != null) {
if ($this->_schema) {
return isset($this->_schema[$name]);
}
return false;
@ -1499,7 +1499,7 @@ class Model extends Object implements CakeEventListener {
public function read($fields = null, $id = null) {
$this->validationErrors = array();
if ($id != null) {
if ($id) {
$this->id = $id;
}
@ -1515,9 +1515,8 @@ class Model extends Object implements CakeEventListener {
'fields' => $fields
));
return $this->data;
} else {
return false;
}
return false;
}
/**
@ -3151,7 +3150,7 @@ class Model extends Object implements CakeEventListener {
public function setDataSource($dataSource = null) {
$oldConfig = $this->useDbConfig;
if ($dataSource != null) {
if ($dataSource) {
$this->useDbConfig = $dataSource;
}
$db = ConnectionManager::getDataSource($this->useDbConfig);

View file

@ -198,7 +198,7 @@ class Permission extends AppModel {
}
list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']);
if ($perms['link'] != null && !empty($perms['link'])) {
if ($perms['link'] && !empty($perms['link'])) {
$save['id'] = $perms['link'][0][$this->alias]['id'];
} else {
unset($save['id']);

View file

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

View file

@ -121,7 +121,7 @@ class CakeSocket {
* @throws SocketException
*/
public function connect() {
if ($this->connection != null) {
if ($this->connection) {
$this->disconnect();
}

View file

@ -1073,7 +1073,7 @@ class Router {
* @return string base url with plugin name removed if present
*/
public static function stripPlugin($base, $plugin = null) {
if ($plugin != null) {
if ($plugin) {
$base = preg_replace('/(?:' . $plugin . ')/', '', $base);
$base = str_replace('//', '', $base);
$pos1 = strrpos($base, '/');

View file

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

View file

@ -1164,7 +1164,7 @@ class CakeEmailTest extends CakeTestCase {
$this->CakeEmail->emailFormat('html');
$server = env('SERVER_NAME') ? env('SERVER_NAME') : 'localhost';
if (env('SERVER_PORT') != null && env('SERVER_PORT') != 80) {
if (env('SERVER_PORT') && env('SERVER_PORT') != 80) {
$server .= ':' . env('SERVER_PORT');
}

View file

@ -903,7 +903,7 @@ class CakeTime {
*/
public static function gmt($dateString = null) {
$time = time();
if ($dateString != null) {
if ($dateString) {
$time = self::fromString($dateString);
}
return gmmktime(

View file

@ -827,7 +827,7 @@ class Set {
}
}
if ($groupPath != null) {
if ($groupPath) {
$group = Set::extract($data, $groupPath);
if (!empty($group)) {
$c = count($keys);

View file

@ -951,13 +951,12 @@ class HtmlHelper extends AppHelper {
if (isset($options['escape'])) {
$text = h($text);
}
if ($class != null && !empty($class)) {
if ($class && !empty($class)) {
$options['class'] = $class;
}
$tag = 'para';
if ($text === null) {
$tag = 'parastart';
} else {
$tag = 'para';
}
return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
}

View file

@ -536,7 +536,7 @@ class PaginatorHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel
*/
public function defaultModel() {
if ($this->_defaultModel != null) {
if ($this->_defaultModel) {
return $this->_defaultModel;
}
if (empty($this->request->params['paging'])) {

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
*/
public function items($items, $callback = null) {
if ($callback != null) {
if ($callback) {
$items = array_map($callback, $items);
}