Skip to content

Commit

Permalink
Merge pull request #1533 from dereuromark/master-null-checks
Browse files Browse the repository at this point in the history
unify null checks - avoid method call in favor of strict check
  • Loading branch information
markstory committed Aug 17, 2013
2 parents 7fe2395 + 6a14f37 commit 005699e
Show file tree
Hide file tree
Showing 37 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/ControllerTask.php
Expand Up @@ -407,7 +407,7 @@ protected function _doPropertyChoices($prompt, $example) {
* @return array Set of controllers
*/
public function listAll($useDbConfig = null) {
if (is_null($useDbConfig)) {
if ($useDbConfig === null) {
$useDbConfig = $this->connection;
}
$this->__tables = $this->Model->getAllTables($useDbConfig);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/FixtureTask.php
Expand Up @@ -219,7 +219,7 @@ public function bake($model, $useTable = false, $importOptions = array()) {
}

$tableInfo = $data['tables'][$useTable];
if (is_null($modelImport)) {
if ($modelImport === null) {
$schema = $this->_generateSchema($tableInfo);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -661,7 +661,7 @@ public function redirect($url = null) {
* @return string Redirect URL
*/
public function redirectUrl($url = null) {
if (!is_null($url)) {
if ($url !== null) {
$redir = $url;
$this->Session->write('Auth.redirect', $redir);
} elseif ($this->Session->check('Auth.redirect')) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Controller/Component/CookieComponent.php
Expand Up @@ -219,7 +219,7 @@ public function write($key, $value = null, $encrypt = true, $expires = null) {
$this->read();
}

if (is_null($encrypt)) {
if ($encrypt === null) {
$encrypt = true;
}
$this->_encrypted = $encrypt;
Expand Down Expand Up @@ -262,7 +262,7 @@ public function read($key = null) {
if (empty($this->_values[$this->name])) {
$this->_values[$this->name] = array();
}
if (is_null($key)) {
if ($key === null) {
return $this->_values[$this->name];
}

Expand Down Expand Up @@ -387,7 +387,7 @@ public function type($type = 'cipher') {
* @return integer Unix timestamp
*/
protected function _expire($expires = null) {
if (is_null($expires)) {
if ($expires === null) {
return $this->_expires;
}
$this->_reset = $this->_expires;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Core/CakePlugin.php
Expand Up @@ -228,7 +228,7 @@ public static function loaded($plugin = null) {
* @return void
*/
public static function unload($plugin = null) {
if (is_null($plugin)) {
if ($plugin === null) {
self::$_plugins = array();
} else {
unset(self::$_plugins[$plugin]);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/I18n/I18n.php
Expand Up @@ -161,7 +161,7 @@ public static function translate($singular, $plural = null, $domain = null, $cat
$_this->_lang = $lang;
}

if (is_null($domain)) {
if ($domain === null) {
$domain = self::$defaultDomain;
}
if ($domain === '') {
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -513,7 +513,7 @@ public function afterDelete(Model $Model) {
* @return mixed string or false
*/
protected function _getLocale(Model $Model) {
if (!isset($Model->locale) || is_null($Model->locale)) {
if (!isset($Model->locale) || $Model->locale === null) {
$I18n = I18n::getInstance();
$I18n->l10n->get(Configure::read('Config.language'));
$Model->locale = $I18n->l10n->locale;
Expand Down Expand Up @@ -588,7 +588,7 @@ public function bindTranslation(Model $Model, $fields, $reset = true) {

$this->_removeField($Model, $field);

if (is_null($association)) {
if ($association === null) {
if ($reset) {
$this->runtime[$Model->alias]['fields'][] = $field;
} else {
Expand Down Expand Up @@ -677,7 +677,7 @@ public function unbindTranslation(Model $Model, $fields = null) {

$this->_removeField($Model, $field);

if (!is_null($association) && (isset($Model->hasMany[$association]) || isset($Model->__backAssociation['hasMany'][$association]))) {
if ($association !== null && (isset($Model->hasMany[$association]) || isset($Model->__backAssociation['hasMany'][$association]))) {
$associations[] = $association;
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -307,7 +307,7 @@ public function children(Model $Model, $id = null, $direct = false, $fields = nu

extract($this->settings[$Model->alias]);

if (!is_null($overrideRecursive)) {
if ($overrideRecursive !== null) {
$recursive = $overrideRecursive;
}
if (!$order) {
Expand Down Expand Up @@ -353,7 +353,7 @@ public function children(Model $Model, $id = null, $direct = false, $fields = nu
public function generateTreeList(Model $Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
$overrideRecursive = $recursive;
extract($this->settings[$Model->alias]);
if (!is_null($overrideRecursive)) {
if ($overrideRecursive !== null) {
$recursive = $overrideRecursive;
}

Expand Down Expand Up @@ -415,7 +415,7 @@ public function getParentNode(Model $Model, $id = null, $fields = null, $recursi
$id = $Model->id;
}
extract($this->settings[$Model->alias]);
if (!is_null($overrideRecursive)) {
if ($overrideRecursive !== null) {
$recursive = $overrideRecursive;
}
$parentId = $Model->find('first', array('conditions' => array($Model->primaryKey => $id), 'fields' => array($parent), 'recursive' => -1));
Expand Down Expand Up @@ -448,7 +448,7 @@ public function getPath(Model $Model, $id = null, $fields = null, $recursive = n
$id = $Model->id;
}
extract($this->settings[$Model->alias]);
if (!is_null($overrideRecursive)) {
if ($overrideRecursive !== null) {
$recursive = $overrideRecursive;
}
$result = $Model->find('first', array('conditions' => array($Model->escapeField() => $id), 'fields' => array($left, $right), 'recursive' => $recursive));
Expand Down Expand Up @@ -817,7 +817,7 @@ public function verify(Model $Model) {
))));

foreach ($Model->find('all', array('conditions' => $scope, 'recursive' => 0)) as $instance) {
if (is_null($instance[$Model->alias][$left]) || is_null($instance[$Model->alias][$right])) {
if ($instance[$Model->alias][$left] === null || $instance[$Model->alias][$right] === null) {
$errors[] = array('node', $instance[$Model->alias][$Model->primaryKey],
'has invalid left or right values');
} elseif ($instance[$Model->alias][$left] == $instance[$Model->alias][$right]) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -366,7 +366,7 @@ public static function read($name = null) {
if (!self::start()) {
return false;
}
if (is_null($name)) {
if ($name === null) {
return self::_returnSessionVars();
}
if (empty($name)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -657,7 +657,7 @@ protected function _alterIndexes($table, $indexes) {
* @return string Formatted length part of an index field
*/
protected function _buildIndexSubPart($lengths, $column) {
if (is_null($lengths)) {
if ($lengths === null) {
return '';
}
if (!isset($lengths[$column])) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -748,11 +748,11 @@ public function fetchResult() {

switch ($type) {
case 'bool':
$resultRow[$table][$column] = is_null($row[$index]) ? null : $this->boolean($row[$index]);
$resultRow[$table][$column] = $row[$index] === null ? null : $this->boolean($row[$index]);
break;
case 'binary':
case 'bytea':
$resultRow[$table][$column] = is_null($row[$index]) ? null : stream_get_contents($row[$index]);
$resultRow[$table][$column] = $row[$index] === null ? null : stream_get_contents($row[$index]);
break;
default:
$resultRow[$table][$column] = $row[$index];
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -357,7 +357,7 @@ public function fetchResult() {
foreach ($this->map as $col => $meta) {
list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col];
if ($type === 'boolean' && !is_null($row[$col])) {
if ($type === 'boolean' && $row[$col] !== null) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -615,7 +615,7 @@ public function fetchResult() {
continue;
}
$resultRow[$table][$column] = $row[$col];
if ($type === 'boolean' && !is_null($row[$col])) {
if ($type === 'boolean' && $row[$col] !== null) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1035,7 +1035,7 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
$recursive = $queryData['recursive'];
}

if (!is_null($recursive)) {
if ($recursive !== null) {
$_recursive = $model->recursive;
$model->recursive = $recursive;
}
Expand Down Expand Up @@ -1123,7 +1123,7 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
}
}

if (!is_null($recursive)) {
if ($recursive !== null) {
$model->recursive = $_recursive;
}
return $resultSet;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -2693,7 +2693,7 @@ public function find($type = 'first', $query = array()) {
$this->id = $this->getID();

$query = $this->buildQuery($type, $query);
if (is_null($query)) {
if ($query === null) {
return null;
}

Expand Down
18 changes: 9 additions & 9 deletions lib/Cake/Network/CakeResponse.php
Expand Up @@ -514,7 +514,7 @@ protected function _setContentLength() {
*/
protected function _sendHeader($name, $value = null) {
if (!headers_sent()) {
if (is_null($value)) {
if ($value === null) {
header($name);
} else {
header("{$name}: {$value}");
Expand Down Expand Up @@ -560,7 +560,7 @@ protected function _sendContent($content) {
* @return array list of headers to be sent
*/
public function header($header = null, $value = null) {
if (is_null($header)) {
if ($header === null) {
return $this->_headers;
}
if (is_array($header)) {
Expand All @@ -574,7 +574,7 @@ public function header($header = null, $value = null) {
return $this->_headers;
}

if (!is_null($value)) {
if ($value !== null) {
$this->_headers[$header] = $value;
return $this->_headers;
}
Expand All @@ -592,7 +592,7 @@ public function header($header = null, $value = null) {
* @return string current message buffer if $content param is passed as null
*/
public function body($content = null) {
if (is_null($content)) {
if ($content === null) {
return $this->_body;
}
return $this->_body = $content;
Expand All @@ -607,7 +607,7 @@ public function body($content = null) {
* @throws CakeException When an unknown status code is reached.
*/
public function statusCode($code = null) {
if (is_null($code)) {
if ($code === null) {
return $this->_status;
}
if (!isset($this->_statusCodes[$code])) {
Expand Down Expand Up @@ -676,7 +676,7 @@ public function httpCodes($code = null) {
* @return mixed current content type or false if supplied an invalid content type
*/
public function type($contentType = null) {
if (is_null($contentType)) {
if ($contentType === null) {
return $this->_contentType;
}
if (is_array($contentType)) {
Expand Down Expand Up @@ -741,7 +741,7 @@ public function mapType($ctype) {
* @return string current charset
*/
public function charset($charset = null) {
if (is_null($charset)) {
if ($charset === null) {
return $this->_charset;
}
return $this->_charset = $charset;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ public function file($path, $options = array()) {

$extension = strtolower($file->ext());
$download = $options['download'];
if ((!$extension || $this->type($extension) === false) && is_null($download)) {
if ((!$extension || $this->type($extension) === false) && $download === null) {
$download = true;
}

Expand All @@ -1265,7 +1265,7 @@ public function file($path, $options = array()) {
if (!empty($contentType)) {
$this->type($contentType);
}
if (is_null($options['name'])) {
if ($options['name'] === null) {
$name = $file->name;
} else {
$name = $options['name'];
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Email/SmtpTransport.php
Expand Up @@ -231,7 +231,7 @@ protected function _generateSocket() {
* @throws SocketException
*/
protected function _smtpSend($data, $checkCode = '250') {
if (!is_null($data)) {
if ($data !== null) {
$this->_socket->write($data . "\r\n");
}
while ($checkCode !== false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Http/HttpSocket.php
Expand Up @@ -536,7 +536,7 @@ public function delete($uri = null, $data = array(), $request = array()) {
* @return mixed Either false on failure or a string containing the composed URL.
*/
public function url($url = null, $uriTemplate = null) {
if (is_null($url)) {
if ($url === null) {
$url = '/';
}
if (is_string($url)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Network/Http/HttpSocketResponse.php
Expand Up @@ -138,7 +138,7 @@ public function isOk() {
* @return boolean
*/
public function isRedirect() {
return in_array($this->code, array(301, 302, 303, 307)) && !is_null($this->getHeader('Location'));
return in_array($this->code, array(301, 302, 303, 307)) && $this->getHeader('Location') !== null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Routing/Router.php
Expand Up @@ -175,7 +175,7 @@ class Router {
* @throws RouterException
*/
public static function defaultRouteClass($routeClass = null) {
if (is_null($routeClass)) {
if ($routeClass === null) {
return self::$_routeClass;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/Cake/Test/Case/Model/ModelValidationTest.php
Expand Up @@ -588,7 +588,7 @@ public function testValidatesWithAssociations() {
$this->assertFalse($result, 'Save occurred even when with models failed. %s');
$this->assertEquals($expectedError, $JoinThing->validationErrors);
$count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id'])));
$this->assertSame($count, 0);
$this->assertSame(0, $count);

$data = array(
'Something' => array(
Expand Down Expand Up @@ -651,7 +651,7 @@ public function testValidatesWithModelsAndSaveAll() {
$this->assertEquals($expectedError, $JoinThing->validationErrors);

$count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id'])));
$this->assertSame($count, 0);
$this->assertSame(0, $count);

$joinRecords = $JoinThing->find('count', array(
'conditions' => array('JoinThing.something_id' => $data['Something']['id'])
Expand Down Expand Up @@ -692,11 +692,11 @@ public function testValidatesWithModelsAndSaveAllWithoutId() {
$Author->create();
$result = $Author->saveAll($data, array('validate' => 'first'));
$this->assertTrue($result);
$this->assertFalse(is_null($Author->id));
$this->assertNotNull($Author->id);

$id = $Author->id;
$count = $Author->find('count', array('conditions' => array('Author.id' => $id)));
$this->assertSame($count, 1);
$this->assertSame(1, $count);

$count = $Post->find('count', array(
'conditions' => array('Post.author_id' => $id)
Expand Down Expand Up @@ -2315,7 +2315,7 @@ public function testValidateAssociatedAtomicFalseDeepTrueWithErrors() {
),
),
);
$this->assertEquals($result, $expected);
$this->assertEquals($expected, $result);
}

/**
Expand Down Expand Up @@ -2376,7 +2376,7 @@ public function testValidateManyAtomicFalseDeepTrueWithErrors() {
),
),
);
$this->assertEquals($result, $expected);
$this->assertEquals($expected, $result);
}

}

0 comments on commit 005699e

Please sign in to comment.