Skip to content

Commit

Permalink
converting if ($foo != null) to if ($foo)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Sep 21, 2012
1 parent f5a8eb6 commit b1f26b5
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/CookieComponent.php
Expand Up @@ -507,7 +507,7 @@ protected function _explode($string) {
$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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -398,7 +398,7 @@ public function isDelete() {
* @return string Prototype version of component making Ajax call * @return string Prototype version of component making Ajax call
*/ */
public function getAjaxVersion() { public function getAjaxVersion() {
if (env('HTTP_X_PROTOTYPE_VERSION') != null) { if (env('HTTP_X_PROTOTYPE_VERSION')) {
return env('HTTP_X_PROTOTYPE_VERSION'); return env('HTTP_X_PROTOTYPE_VERSION');
} }
return false; return false;
Expand Down Expand Up @@ -672,7 +672,7 @@ public function respondAs($type, $options = array()) {
$cType = $type; $cType = $type;
} }


if ($cType != null) { if ($cType) {
if (empty($this->request->params['requested'])) { if (empty($this->request->params['requested'])) {
$this->response->type($cType); $this->response->type($cType);
} }
Expand Down
17 changes: 9 additions & 8 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -967,14 +967,15 @@ public function render($view = null, $layout = null) {
* @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);
} $referer = $this->request->referer($local);
return $referer; if ($referer == '/' && $default) {
return Router::url($default, true);
} }
return '/'; return $referer;
} }


/** /**
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
$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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -131,7 +131,7 @@ public static function init($base = null) {
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);
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -175,7 +175,7 @@ public function enabled() {
*/ */
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']));
Expand Down Expand Up @@ -280,7 +280,7 @@ public function getCharsetName($name) {
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);
Expand Down
20 changes: 10 additions & 10 deletions lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -146,7 +146,7 @@ public function enabled() {
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;
} }


Expand All @@ -156,17 +156,17 @@ public function listSources($data = null) {


if (!$result) { if (!$result) {
return array(); return array();
} else { }
$tables = array();


foreach ($result as $item) { $tables = array();
$tables[] = $item->name;
}


$result->closeCursor(); foreach ($result as $item) {
parent::listSources($tables); $tables[] = $item->name;
return $tables;
} }

$result->closeCursor();
parent::listSources($tables);
return $tables;
} }


/** /**
Expand Down Expand Up @@ -671,7 +671,7 @@ public function length($real) {
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;
Expand Down
18 changes: 9 additions & 9 deletions lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -136,22 +136,22 @@ public function enabled() {
*/ */
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->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false); $result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false);


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


/** /**
Expand All @@ -163,7 +163,7 @@ public function listSources($data = null) {
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();
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -184,7 +184,7 @@ public function listSources($data = null) {
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();
Expand Down Expand Up @@ -619,7 +619,7 @@ public function fetchResult() {
*/ */
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))
); );
Expand Down
9 changes: 4 additions & 5 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -670,7 +670,7 @@ public function fetchAll($sql, $params = array(), $options = array()) {


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()) {
Expand Down Expand Up @@ -1407,10 +1407,9 @@ protected function _mergeAssociation(&$data, &$merge, $association, $type, $self
} }
} }
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])) {
Expand Down Expand Up @@ -2513,7 +2512,7 @@ public function conditionKeysToString($conditions, $quoteValues = true, $model =
$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;
} }
Expand Down
9 changes: 4 additions & 5 deletions lib/Cake/Model/Model.php
Expand Up @@ -1389,7 +1389,7 @@ public function hasField($name, $checkVirtual = false) {
$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;
Expand Down Expand Up @@ -1499,7 +1499,7 @@ public function create($data = array(), $filterKey = false) {
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;
} }


Expand All @@ -1515,9 +1515,8 @@ public function read($fields = null, $id = null) {
'fields' => $fields 'fields' => $fields
)); ));
return $this->data; return $this->data;
} else {
return false;
} }
return false;
} }


/** /**
Expand Down Expand Up @@ -3151,7 +3150,7 @@ public function getAffectedRows() {
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Permission.php
Expand Up @@ -198,7 +198,7 @@ public function allow($aro, $aco, $actions = "*", $value = 1) {
} }
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']);
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Network/CakeRequest.php
Expand Up @@ -364,17 +364,17 @@ protected function _processFileData($path, $data, $field) {
* @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)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/CakeSocket.php
Expand Up @@ -121,7 +121,7 @@ public function __construct($config = array()) {
* @throws SocketException * @throws SocketException
*/ */
public function connect() { public function connect() {
if ($this->connection != null) { if ($this->connection) {
$this->disconnect(); $this->disconnect();
} }


Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Router.php
Expand Up @@ -1073,7 +1073,7 @@ public static function &currentRoute() {
* @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, '/');
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -58,7 +58,7 @@ public function testInsertAnotherHabtmRecordWithSameForeignKey() {
$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(
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -1164,7 +1164,7 @@ public function testSendRenderWithImage() {
$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');
} }


Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/CakeTime.php
Expand Up @@ -903,7 +903,7 @@ public static function isWithinNext($timeInterval, $dateString, $timezone = null
*/ */
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(
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Set.php
Expand Up @@ -827,7 +827,7 @@ public static function combine($data, $path1 = null, $path2 = null, $groupPath =
} }
} }


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);
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -951,13 +951,12 @@ public function para($class, $text, $options = array()) {
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);
} }
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/PaginatorHelper.php
Expand Up @@ -536,7 +536,7 @@ protected function _hasPage($model, $page) {
* @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'])) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/RssHelper.php
Expand Up @@ -167,7 +167,7 @@ public function channel($attrib = array(), $elements = array(), $content = null)
* @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);
} }


Expand Down

0 comments on commit b1f26b5

Please sign in to comment.