Skip to content
This repository
Browse code

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

  • Loading branch information...
commit b1f26b59a39ea753b1557b2acd01248a412b2a95 1 parent f5a8eb6
Carl Sutton authored September 21, 2012
2  lib/Cake/Controller/Component/CookieComponent.php
@@ -507,7 +507,7 @@ protected function _explode($string) {
507 507
 		$first = substr($string, 0, 1);
508 508
 		if ($first === '{' || $first === '[') {
509 509
 			$ret = json_decode($string, true);
510  
-			return ($ret != null) ? $ret : $string;
  510
+			return ($ret) ? $ret : $string;
511 511
 		}
512 512
 		$array = array();
513 513
 		foreach (explode(',', $string) as $pair) {
4  lib/Cake/Controller/Component/RequestHandlerComponent.php
@@ -398,7 +398,7 @@ public function isDelete() {
398 398
  * @return string Prototype version of component making Ajax call
399 399
  */
400 400
 	public function getAjaxVersion() {
401  
-		if (env('HTTP_X_PROTOTYPE_VERSION') != null) {
  401
+		if (env('HTTP_X_PROTOTYPE_VERSION')) {
402 402
 			return env('HTTP_X_PROTOTYPE_VERSION');
403 403
 		}
404 404
 		return false;
@@ -672,7 +672,7 @@ public function respondAs($type, $options = array()) {
672 672
 			$cType = $type;
673 673
 		}
674 674
 
675  
-		if ($cType != null) {
  675
+		if ($cType) {
676 676
 			if (empty($this->request->params['requested'])) {
677 677
 				$this->response->type($cType);
678 678
 			}
17  lib/Cake/Controller/Controller.php
@@ -967,14 +967,15 @@ public function render($view = null, $layout = null) {
967 967
  * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::referer
968 968
  */
969 969
 	public function referer($default = null, $local = false) {
970  
-		if ($this->request) {
971  
-			$referer = $this->request->referer($local);
972  
-			if ($referer == '/' && $default != null) {
973  
-				return Router::url($default, true);
974  
-			}
975  
-			return $referer;
  970
+		if(!$this->request) {
  971
+			return '/';
  972
+		}
  973
+
  974
+		$referer = $this->request->referer($local);
  975
+		if ($referer == '/' && $default) {
  976
+			return Router::url($default, true);
976 977
 		}
977  
-		return '/';
  978
+		return $referer;
978 979
 	}
979 980
 
980 981
 /**
@@ -1062,7 +1063,7 @@ public function postConditions($data = array(), $op = null, $bool = 'AND', $excl
1062 1063
 				$cond[$key] = $value;
1063 1064
 			}
1064 1065
 		}
1065  
-		if ($bool != null && strtoupper($bool) != 'AND') {
  1066
+		if ($bool && strtoupper($bool) != 'AND') {
1066 1067
 			$cond = array($bool => $cond);
1067 1068
 		}
1068 1069
 		return $cond;
2  lib/Cake/Model/Datasource/CakeSession.php
@@ -131,7 +131,7 @@ public static function init($base = null) {
131 131
 		self::$time = time();
132 132
 
133 133
 		$checkAgent = Configure::read('Session.checkAgent');
134  
-		if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT') != null) {
  134
+		if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT')) {
135 135
 			self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
136 136
 		}
137 137
 		self::_setPath($base);
4  lib/Cake/Model/Datasource/Database/Mysql.php
@@ -175,7 +175,7 @@ public function enabled() {
175 175
  */
176 176
 	public function listSources($data = null) {
177 177
 		$cache = parent::listSources();
178  
-		if ($cache != null) {
  178
+		if ($cache) {
179 179
 			return $cache;
180 180
 		}
181 181
 		$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
@@ -280,7 +280,7 @@ public function getCharsetName($name) {
280 280
 	public function describe($model) {
281 281
 		$key = $this->fullTableName($model, false);
282 282
 		$cache = parent::describe($key);
283  
-		if ($cache != null) {
  283
+		if ($cache) {
284 284
 			return $cache;
285 285
 		}
286 286
 		$table = $this->fullTableName($model);
20  lib/Cake/Model/Datasource/Database/Postgres.php
@@ -146,7 +146,7 @@ public function enabled() {
146 146
 	public function listSources($data = null) {
147 147
 		$cache = parent::listSources();
148 148
 
149  
-		if ($cache != null) {
  149
+		if ($cache) {
150 150
 			return $cache;
151 151
 		}
152 152
 
@@ -156,17 +156,17 @@ public function listSources($data = null) {
156 156
 
157 157
 		if (!$result) {
158 158
 			return array();
159  
-		} else {
160  
-			$tables = array();
  159
+		}
161 160
 
162  
-			foreach ($result as $item) {
163  
-				$tables[] = $item->name;
164  
-			}
  161
+		$tables = array();
165 162
 
166  
-			$result->closeCursor();
167  
-			parent::listSources($tables);
168  
-			return $tables;
  163
+		foreach ($result as $item) {
  164
+			$tables[] = $item->name;
169 165
 		}
  166
+
  167
+		$result->closeCursor();
  168
+		parent::listSources($tables);
  169
+		return $tables;
170 170
 	}
171 171
 
172 172
 /**
@@ -671,7 +671,7 @@ public function length($real) {
671 671
 		if ($col == 'uuid') {
672 672
 			return 36;
673 673
 		}
674  
-		if ($limit != null) {
  674
+		if ($limit) {
675 675
 			return intval($limit);
676 676
 		}
677 677
 		return null;
18  lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -136,7 +136,7 @@ public function enabled() {
136 136
  */
137 137
 	public function listSources($data = null) {
138 138
 		$cache = parent::listSources();
139  
-		if ($cache != null) {
  139
+		if ($cache) {
140 140
 			return $cache;
141 141
 		}
142 142
 
@@ -144,14 +144,14 @@ public function listSources($data = null) {
144 144
 
145 145
 		if (!$result || empty($result)) {
146 146
 			return array();
147  
-		} else {
148  
-			$tables = array();
149  
-			foreach ($result as $table) {
150  
-				$tables[] = $table[0]['name'];
151  
-			}
152  
-			parent::listSources($tables);
153  
-			return $tables;
154 147
 		}
  148
+
  149
+		$tables = array();
  150
+		foreach ($result as $table) {
  151
+			$tables[] = $table[0]['name'];
  152
+		}
  153
+		parent::listSources($tables);
  154
+		return $tables;
155 155
 	}
156 156
 
157 157
 /**
@@ -163,7 +163,7 @@ public function listSources($data = null) {
163 163
 	public function describe($model) {
164 164
 		$table = $this->fullTableName($model, false, false);
165 165
 		$cache = parent::describe($table);
166  
-		if ($cache != null) {
  166
+		if ($cache) {
167 167
 			return $cache;
168 168
 		}
169 169
 		$fields = array();
4  lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -184,7 +184,7 @@ public function listSources($data = null) {
184 184
 	public function describe($model) {
185 185
 		$table = $this->fullTableName($model, false);
186 186
 		$cache = parent::describe($table);
187  
-		if ($cache != null) {
  187
+		if ($cache) {
188 188
 			return $cache;
189 189
 		}
190 190
 		$fields = array();
@@ -619,7 +619,7 @@ public function fetchResult() {
619 619
  */
620 620
 	public function insertMulti($table, $fields, $values) {
621 621
 		$primaryKey = $this->_getPrimaryKey($table);
622  
-		$hasPrimaryKey = $primaryKey != null && (
  622
+		$hasPrimaryKey = $primaryKey && (
623 623
 			(is_array($fields) && in_array($primaryKey, $fields)
624 624
 			|| (is_string($fields) && strpos($fields, $this->startQuote . $primaryKey . $this->endQuote) !== false))
625 625
 		);
9  lib/Cake/Model/Datasource/DboSource.php
@@ -670,7 +670,7 @@ public function fetchAll($sql, $params = array(), $options = array()) {
670 670
 
671 671
 			if ($this->hasResult()) {
672 672
 				$first = $this->fetchRow();
673  
-				if ($first != null) {
  673
+				if ($first) {
674 674
 					$out[] = $first;
675 675
 				}
676 676
 				while ($item = $this->fetchResult()) {
@@ -1407,10 +1407,9 @@ protected function _mergeAssociation(&$data, &$merge, $association, $type, $self
1407 1407
 					}
1408 1408
 				}
1409 1409
 				if (!isset($data[$association])) {
1410  
-					if ($merge[0][$association] != null) {
  1410
+					$data[$association] = array();
  1411
+					if ($merge[0][$association]) {
1411 1412
 						$data[$association] = $merge[0][$association];
1412  
-					} else {
1413  
-						$data[$association] = array();
1414 1413
 					}
1415 1414
 				} else {
1416 1415
 					if (is_array($merge[0][$association])) {
@@ -2513,7 +2512,7 @@ public function conditionKeysToString($conditions, $quoteValues = true, $model =
2513 2512
 					$data = $this->_parseKey($model, trim($key), $value);
2514 2513
 				}
2515 2514
 
2516  
-				if ($data != null) {
  2515
+				if ($data) {
2517 2516
 					$out[] = $data;
2518 2517
 					$data = null;
2519 2518
 				}
9  lib/Cake/Model/Model.php
@@ -1389,7 +1389,7 @@ public function hasField($name, $checkVirtual = false) {
1389 1389
 			$this->schema();
1390 1390
 		}
1391 1391
 
1392  
-		if ($this->_schema != null) {
  1392
+		if ($this->_schema) {
1393 1393
 			return isset($this->_schema[$name]);
1394 1394
 		}
1395 1395
 		return false;
@@ -1499,7 +1499,7 @@ public function create($data = array(), $filterKey = false) {
1499 1499
 	public function read($fields = null, $id = null) {
1500 1500
 		$this->validationErrors = array();
1501 1501
 
1502  
-		if ($id != null) {
  1502
+		if ($id) {
1503 1503
 			$this->id = $id;
1504 1504
 		}
1505 1505
 
@@ -1515,9 +1515,8 @@ public function read($fields = null, $id = null) {
1515 1515
 				'fields' => $fields
1516 1516
 			));
1517 1517
 			return $this->data;
1518  
-		} else {
1519  
-			return false;
1520 1518
 		}
  1519
+		return false;
1521 1520
 	}
1522 1521
 
1523 1522
 /**
@@ -3151,7 +3150,7 @@ public function getAffectedRows() {
3151 3150
 	public function setDataSource($dataSource = null) {
3152 3151
 		$oldConfig = $this->useDbConfig;
3153 3152
 
3154  
-		if ($dataSource != null) {
  3153
+		if ($dataSource) {
3155 3154
 			$this->useDbConfig = $dataSource;
3156 3155
 		}
3157 3156
 		$db = ConnectionManager::getDataSource($this->useDbConfig);
2  lib/Cake/Model/Permission.php
@@ -198,7 +198,7 @@ public function allow($aro, $aco, $actions = "*", $value = 1) {
198 198
 		}
199 199
 		list($save['aro_id'], $save['aco_id']) = array($perms['aro'], $perms['aco']);
200 200
 
201  
-		if ($perms['link'] != null && !empty($perms['link'])) {
  201
+		if ($perms['link'] && !empty($perms['link'])) {
202 202
 			$save['id'] = $perms['link'][0][$this->alias]['id'];
203 203
 		} else {
204 204
 			unset($save['id']);
6  lib/Cake/Network/CakeRequest.php
@@ -364,17 +364,17 @@ protected function _processFileData($path, $data, $field) {
364 364
  * @return string The client IP.
365 365
  */
366 366
 	public function clientIp($safe = true) {
367  
-		if (!$safe && env('HTTP_X_FORWARDED_FOR') != null) {
  367
+		if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
368 368
 			$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
369 369
 		} else {
370  
-			if (env('HTTP_CLIENT_IP') != null) {
  370
+			if (env('HTTP_CLIENT_IP')) {
371 371
 				$ipaddr = env('HTTP_CLIENT_IP');
372 372
 			} else {
373 373
 				$ipaddr = env('REMOTE_ADDR');
374 374
 			}
375 375
 		}
376 376
 
377  
-		if (env('HTTP_CLIENTADDRESS') != null) {
  377
+		if (env('HTTP_CLIENTADDRESS')) {
378 378
 			$tmpipaddr = env('HTTP_CLIENTADDRESS');
379 379
 
380 380
 			if (!empty($tmpipaddr)) {
2  lib/Cake/Network/CakeSocket.php
@@ -121,7 +121,7 @@ public function __construct($config = array()) {
121 121
  * @throws SocketException
122 122
  */
123 123
 	public function connect() {
124  
-		if ($this->connection != null) {
  124
+		if ($this->connection) {
125 125
 			$this->disconnect();
126 126
 		}
127 127
 
2  lib/Cake/Routing/Router.php
@@ -1073,7 +1073,7 @@ public static function &currentRoute() {
1073 1073
  * @return string base url with plugin name removed if present
1074 1074
  */
1075 1075
 	public static function stripPlugin($base, $plugin = null) {
1076  
-		if ($plugin != null) {
  1076
+		if ($plugin) {
1077 1077
 			$base = preg_replace('/(?:' . $plugin . ')/', '', $base);
1078 1078
 			$base = str_replace('//', '', $base);
1079 1079
 			$pos1 = strrpos($base, '/');
2  lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -58,7 +58,7 @@ public function testInsertAnotherHabtmRecordWithSameForeignKey() {
58 58
 		$lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID();
59 59
 		$data['id'] = $lastInsertId;
60 60
 		$this->assertEquals(array('JoinAsJoinB' => $data), $result);
61  
-		$this->assertTrue($lastInsertId != null);
  61
+		$this->assertTrue($lastInsertId);
62 62
 
63 63
 		$result = $TestModel->JoinAsJoinB->findById(1);
64 64
 		$expected = array(
2  lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -1164,7 +1164,7 @@ public function testSendRenderWithImage() {
1164 1164
 		$this->CakeEmail->emailFormat('html');
1165 1165
 		$server = env('SERVER_NAME') ? env('SERVER_NAME') : 'localhost';
1166 1166
 
1167  
-		if (env('SERVER_PORT') != null && env('SERVER_PORT') != 80) {
  1167
+		if (env('SERVER_PORT') && env('SERVER_PORT') != 80) {
1168 1168
 			$server .= ':' . env('SERVER_PORT');
1169 1169
 		}
1170 1170
 
2  lib/Cake/Utility/CakeTime.php
@@ -903,7 +903,7 @@ public static function isWithinNext($timeInterval, $dateString, $timezone = null
903 903
  */
904 904
 	public static function gmt($dateString = null) {
905 905
 		$time = time();
906  
-		if ($dateString != null) {
  906
+		if ($dateString) {
907 907
 			$time = self::fromString($dateString);
908 908
 		}
909 909
 		return gmmktime(
2  lib/Cake/Utility/Set.php
@@ -827,7 +827,7 @@ public static function combine($data, $path1 = null, $path2 = null, $groupPath =
827 827
 			}
828 828
 		}
829 829
 
830  
-		if ($groupPath != null) {
  830
+		if ($groupPath) {
831 831
 			$group = Set::extract($data, $groupPath);
832 832
 			if (!empty($group)) {
833 833
 				$c = count($keys);
5  lib/Cake/View/Helper/HtmlHelper.php
@@ -951,13 +951,12 @@ public function para($class, $text, $options = array()) {
951 951
 		if (isset($options['escape'])) {
952 952
 			$text = h($text);
953 953
 		}
954  
-		if ($class != null && !empty($class)) {
  954
+		if ($class && !empty($class)) {
955 955
 			$options['class'] = $class;
956 956
 		}
  957
+		$tag = 'para';
957 958
 		if ($text === null) {
958 959
 			$tag = 'parastart';
959  
-		} else {
960  
-			$tag = 'para';
961 960
 		}
962 961
 		return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
963 962
 	}
2  lib/Cake/View/Helper/PaginatorHelper.php
@@ -536,7 +536,7 @@ protected function _hasPage($model, $page) {
536 536
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel
537 537
  */
538 538
 	public function defaultModel() {
539  
-		if ($this->_defaultModel != null) {
  539
+		if ($this->_defaultModel) {
540 540
 			return $this->_defaultModel;
541 541
 		}
542 542
 		if (empty($this->request->params['paging'])) {
2  lib/Cake/View/Helper/RssHelper.php
@@ -167,7 +167,7 @@ public function channel($attrib = array(), $elements = array(), $content = null)
167 167
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::items
168 168
  */
169 169
 	public function items($items, $callback = null) {
170  
-		if ($callback != null) {
  170
+		if ($callback) {
171 171
 			$items = array_map($callback, $items);
172 172
 		}
173 173
 

0 notes on commit b1f26b5

Please sign in to comment.
Something went wrong with that request. Please try again.