From 3f83037595133cd4595c0e041b0e074d83d1c599 Mon Sep 17 00:00:00 2001 From: prolic Date: Tue, 22 Jan 2013 18:37:50 +0100 Subject: [PATCH 1/3] Replace all is_null($value) calls with null === $value or alternativly null !== $value for consistency in the framework --- library/Zend/Db/Sql/Delete.php | 2 +- library/Zend/Db/Sql/Insert.php | 2 +- library/Zend/Db/Sql/Predicate/Between.php | 4 ++-- library/Zend/Db/Sql/Select.php | 2 +- library/Zend/Db/Sql/Update.php | 6 +++--- library/Zend/Form/Element/Select.php | 2 +- library/Zend/Http/Client.php | 2 +- library/Zend/Http/Response/Stream.php | 2 +- library/Zend/View/Helper/Escaper/AbstractHelper.php | 2 +- library/Zend/View/Model/JsonModel.php | 2 +- library/Zend/View/Renderer/JsonRenderer.php | 2 +- library/Zend/XmlRpc/AbstractValue.php | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/library/Zend/Db/Sql/Delete.php b/library/Zend/Db/Sql/Delete.php index 780e3820c30..d023df9296a 100644 --- a/library/Zend/Db/Sql/Delete.php +++ b/library/Zend/Db/Sql/Delete.php @@ -128,7 +128,7 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) } elseif (is_string($pkey)) { // Otherwise, if still a string, do something intelligent with the PHP type provided - if (is_null($pvalue)) { + if (null === $pvalue) { // map PHP null to SQL IS NULL expression $predicate = new Predicate\IsNull($pkey, $pvalue); } elseif (is_array($pvalue)) { diff --git a/library/Zend/Db/Sql/Insert.php b/library/Zend/Db/Sql/Insert.php index 0be017d3bd7..dc020dbb28e 100644 --- a/library/Zend/Db/Sql/Insert.php +++ b/library/Zend/Db/Sql/Insert.php @@ -201,7 +201,7 @@ public function getSqlString(PlatformInterface $adapterPlatform = null) if ($value instanceof Expression) { $exprData = $this->processExpression($value, $adapterPlatform); $values[] = $exprData->getSql(); - } elseif (is_null($value)) { + } elseif (null === $value) { $values[] = 'NULL'; } else { $values[] = $adapterPlatform->quoteValue($value); diff --git a/library/Zend/Db/Sql/Predicate/Between.php b/library/Zend/Db/Sql/Predicate/Between.php index 31041df51d8..3d254ae457b 100644 --- a/library/Zend/Db/Sql/Predicate/Between.php +++ b/library/Zend/Db/Sql/Predicate/Between.php @@ -34,10 +34,10 @@ public function __construct($identifier = null, $minValue = null, $maxValue = nu if ($identifier) { $this->setIdentifier($identifier); } - if (!is_null($minValue)) { + if (null !== $minValue) { $this->setMinValue($minValue); } - if (!is_null($maxValue)) { + if (null !== $maxValue) { $this->setMaxValue($maxValue); } } diff --git a/library/Zend/Db/Sql/Select.php b/library/Zend/Db/Sql/Select.php index 53bf0c3a1c7..773f19d9514 100644 --- a/library/Zend/Db/Sql/Select.php +++ b/library/Zend/Db/Sql/Select.php @@ -261,7 +261,7 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) } elseif (is_string($pkey)) { // Otherwise, if still a string, do something intelligent with the PHP type provided - if (is_null($pvalue)) { + if (null === $pvalue) { // map PHP null to SQL IS NULL expression $predicate = new Predicate\IsNull($pkey, $pvalue); } elseif (is_array($pvalue)) { diff --git a/library/Zend/Db/Sql/Update.php b/library/Zend/Db/Sql/Update.php index e2a8d291625..311dc2a8415 100644 --- a/library/Zend/Db/Sql/Update.php +++ b/library/Zend/Db/Sql/Update.php @@ -123,7 +123,7 @@ public function set(array $values, $flag = self::VALUES_SET) */ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) { - if (is_null($predicate)) { + if (null === $predicate) { throw new Exception\InvalidArgumentException('Predicate cannot be null'); } @@ -149,7 +149,7 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) } elseif (is_string($pkey)) { // Otherwise, if still a string, do something intelligent with the PHP type provided - if (is_null($pvalue)) { + if (null === $pvalue) { // map PHP null to SQL IS NULL expression $predicate = new Predicate\IsNull($pkey, $pvalue); } elseif (is_array($pvalue)) { @@ -249,7 +249,7 @@ public function getSqlString(PlatformInterface $adapterPlatform = null) if ($value instanceof Expression) { $exprData = $this->processExpression($value, $adapterPlatform); $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $exprData->getSql(); - } elseif (is_null($value)) { + } elseif (null === $value) { $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = NULL'; } else { $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $adapterPlatform->quoteValue($value); diff --git a/library/Zend/Form/Element/Select.php b/library/Zend/Form/Element/Select.php index 646ab5c0923..810afc1425a 100644 --- a/library/Zend/Form/Element/Select.php +++ b/library/Zend/Form/Element/Select.php @@ -81,7 +81,7 @@ public function setValueOptions(array $options) $this->valueOptions = $options; // Update InArrayValidator validator haystack - if (!is_null($this->validator)) { + if (null !== $this->validator) { if ($this->validator instanceof InArrayValidator){ $validator = $this->validator; } diff --git a/library/Zend/Http/Client.php b/library/Zend/Http/Client.php index 94f1c8673ad..9c064611c23 100644 --- a/library/Zend/Http/Client.php +++ b/library/Zend/Http/Client.php @@ -582,7 +582,7 @@ public function setStream($streamfile = true) */ public function getStream() { - if (!is_null($this->streamName)) { + if (null !== $this->streamName) { return $this->streamName; } diff --git a/library/Zend/Http/Response/Stream.php b/library/Zend/Http/Response/Stream.php index 2ee235f03bd..88348e5543f 100644 --- a/library/Zend/Http/Response/Stream.php +++ b/library/Zend/Http/Response/Stream.php @@ -242,7 +242,7 @@ public function getRawBody() */ protected function readStream() { - if (!is_null($this->contentLength)) { + if (null !== $this->contentLength) { $bytes = $this->contentLength - $this->contentStreamed; } else { $bytes = -1; //Read the whole buffer diff --git a/library/Zend/View/Helper/Escaper/AbstractHelper.php b/library/Zend/View/Helper/Escaper/AbstractHelper.php index ca9d1ae04b8..47c07a90415 100644 --- a/library/Zend/View/Helper/Escaper/AbstractHelper.php +++ b/library/Zend/View/Helper/Escaper/AbstractHelper.php @@ -65,7 +65,7 @@ public function getEscaper() */ public function setEncoding($encoding) { - if (!is_null($this->escaper)) { + if (null !== $this->escaper) { throw new Exception\InvalidArgumentException( 'Character encoding settings cannot be changed once the Helper has been used or ' . ' if a Zend\Escaper\Escaper object (with preset encoding option) is set.' diff --git a/library/Zend/View/Model/JsonModel.php b/library/Zend/View/Model/JsonModel.php index 830b4559ff6..c114740eda6 100644 --- a/library/Zend/View/Model/JsonModel.php +++ b/library/Zend/View/Model/JsonModel.php @@ -67,7 +67,7 @@ public function serialize() $variables = ArrayUtils::iteratorToArray($variables); } - if (!is_null($this->jsonpCallback)) { + if (null !== $this->jsonpCallback) { return $this->jsonpCallback.'('.Json::encode($variables).');'; } return Json::encode($variables); diff --git a/library/Zend/View/Renderer/JsonRenderer.php b/library/Zend/View/Renderer/JsonRenderer.php index 8a1ed04c2b5..1f5fd49c179 100644 --- a/library/Zend/View/Renderer/JsonRenderer.php +++ b/library/Zend/View/Renderer/JsonRenderer.php @@ -107,7 +107,7 @@ public function setJsonpCallback($callback) */ public function hasJsonpCallback() { - return !is_null($this->jsonpCallback); + return null !== $this->jsonpCallback; } /** diff --git a/library/Zend/XmlRpc/AbstractValue.php b/library/Zend/XmlRpc/AbstractValue.php index ca625df376a..76e693589d4 100644 --- a/library/Zend/XmlRpc/AbstractValue.php +++ b/library/Zend/XmlRpc/AbstractValue.php @@ -257,7 +257,7 @@ public static function getXmlRpcTypeByValue($value) return self::XMLRPC_TYPE_DOUBLE; } elseif (is_bool($value)) { return self::XMLRPC_TYPE_BOOLEAN; - } elseif (is_null($value)) { + } elseif (null === $value) { return self::XMLRPC_TYPE_NIL; } elseif (is_string($value)) { return self::XMLRPC_TYPE_STRING; From af3e3d114adcf0a0c2dc14a19f698524834e0e4d Mon Sep 17 00:00:00 2001 From: prolic Date: Wed, 23 Jan 2013 12:30:01 +0100 Subject: [PATCH 2/3] added braces to null comparison --- library/Zend/View/Renderer/JsonRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Zend/View/Renderer/JsonRenderer.php b/library/Zend/View/Renderer/JsonRenderer.php index 1f5fd49c179..0f088a7ce48 100644 --- a/library/Zend/View/Renderer/JsonRenderer.php +++ b/library/Zend/View/Renderer/JsonRenderer.php @@ -107,7 +107,7 @@ public function setJsonpCallback($callback) */ public function hasJsonpCallback() { - return null !== $this->jsonpCallback; + return (null !== $this->jsonpCallback); } /** From 4801dff8ef2a81c91a938ca3c9417735a5e23980 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 25 Jan 2013 16:53:59 +0100 Subject: [PATCH 3/3] [#3520] Remove yoda conditions in null checks in DB - per @ralphschindler --- library/Zend/Db/Sql/Delete.php | 2 +- library/Zend/Db/Sql/Insert.php | 2 +- library/Zend/Db/Sql/Predicate/Between.php | 4 ++-- library/Zend/Db/Sql/Select.php | 2 +- library/Zend/Db/Sql/Update.php | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/Zend/Db/Sql/Delete.php b/library/Zend/Db/Sql/Delete.php index d023df9296a..7c7547180f0 100644 --- a/library/Zend/Db/Sql/Delete.php +++ b/library/Zend/Db/Sql/Delete.php @@ -128,7 +128,7 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) } elseif (is_string($pkey)) { // Otherwise, if still a string, do something intelligent with the PHP type provided - if (null === $pvalue) { + if ($pvalue === null) { // map PHP null to SQL IS NULL expression $predicate = new Predicate\IsNull($pkey, $pvalue); } elseif (is_array($pvalue)) { diff --git a/library/Zend/Db/Sql/Insert.php b/library/Zend/Db/Sql/Insert.php index dc020dbb28e..ecf1b49e26c 100644 --- a/library/Zend/Db/Sql/Insert.php +++ b/library/Zend/Db/Sql/Insert.php @@ -201,7 +201,7 @@ public function getSqlString(PlatformInterface $adapterPlatform = null) if ($value instanceof Expression) { $exprData = $this->processExpression($value, $adapterPlatform); $values[] = $exprData->getSql(); - } elseif (null === $value) { + } elseif ($value === null) { $values[] = 'NULL'; } else { $values[] = $adapterPlatform->quoteValue($value); diff --git a/library/Zend/Db/Sql/Predicate/Between.php b/library/Zend/Db/Sql/Predicate/Between.php index 3d254ae457b..8d62b866afa 100644 --- a/library/Zend/Db/Sql/Predicate/Between.php +++ b/library/Zend/Db/Sql/Predicate/Between.php @@ -34,10 +34,10 @@ public function __construct($identifier = null, $minValue = null, $maxValue = nu if ($identifier) { $this->setIdentifier($identifier); } - if (null !== $minValue) { + if ($minValue !== null) { $this->setMinValue($minValue); } - if (null !== $maxValue) { + if ($maxValue !== null) { $this->setMaxValue($maxValue); } } diff --git a/library/Zend/Db/Sql/Select.php b/library/Zend/Db/Sql/Select.php index 5d17776c0cf..928c4534c94 100644 --- a/library/Zend/Db/Sql/Select.php +++ b/library/Zend/Db/Sql/Select.php @@ -261,7 +261,7 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) } elseif (is_string($pkey)) { // Otherwise, if still a string, do something intelligent with the PHP type provided - if (null === $pvalue) { + if ($pvalue === null) { // map PHP null to SQL IS NULL expression $predicate = new Predicate\IsNull($pkey, $pvalue); } elseif (is_array($pvalue)) { diff --git a/library/Zend/Db/Sql/Update.php b/library/Zend/Db/Sql/Update.php index 311dc2a8415..2415d2f1678 100644 --- a/library/Zend/Db/Sql/Update.php +++ b/library/Zend/Db/Sql/Update.php @@ -123,7 +123,7 @@ public function set(array $values, $flag = self::VALUES_SET) */ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) { - if (null === $predicate) { + if ($predicate === null) { throw new Exception\InvalidArgumentException('Predicate cannot be null'); } @@ -149,7 +149,7 @@ public function where($predicate, $combination = Predicate\PredicateSet::OP_AND) } elseif (is_string($pkey)) { // Otherwise, if still a string, do something intelligent with the PHP type provided - if (null === $pvalue) { + if ($pvalue === null) { // map PHP null to SQL IS NULL expression $predicate = new Predicate\IsNull($pkey, $pvalue); } elseif (is_array($pvalue)) { @@ -249,7 +249,7 @@ public function getSqlString(PlatformInterface $adapterPlatform = null) if ($value instanceof Expression) { $exprData = $this->processExpression($value, $adapterPlatform); $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $exprData->getSql(); - } elseif (null === $value) { + } elseif ($value === null) { $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = NULL'; } else { $setSql[] = $adapterPlatform->quoteIdentifier($column) . ' = ' . $adapterPlatform->quoteValue($value);