Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced === null with is_null() #4247

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
'function_declaration' => true,
// Code MUST use configured indentation type.
'indentation_type' => true,
// Replaces is_null($var) expression with null === $var.
'is_null' => false,
// All PHP files must use same line ending.
'line_ending' => true,
// Use && and || logical operators instead of and and or.
Expand Down
45 changes: 25 additions & 20 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2780,6 +2780,16 @@ parameters:
count: 1
path: app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php

-
message: "#^Call to function is_null\\(\\) with \\(int\\|string\\) will always evaluate to false\\.$#"
count: 1
path: app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php

-
message: "#^Parameter \\#1 \\$key of method Varien_Object\\:\\:getData\\(\\) expects string, true given\\.$#"
count: 1
path: app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php

-
message: "#^Variable \\$options might not be defined\\.$#"
count: 1
Expand Down Expand Up @@ -3581,12 +3591,12 @@ parameters:
path: app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php

-
message: "#^Strict comparison using \\!\\=\\= between array\\<string, mixed\\> and null will always evaluate to true\\.$#"
count: 2
message: "#^Parameter \\#1 \\$obj of function get_object_vars expects object, false given\\.$#"
count: 1
path: app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
message: "#^Parameter \\#1 \\$obj of function get_object_vars expects object, true given\\.$#"
count: 1
path: app/code/core/Mage/Checkout/Model/Cart/Customer/Api/V2.php

Expand All @@ -3596,12 +3606,7 @@ parameters:
path: app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php

-
message: "#^Strict comparison using \\!\\=\\= between array\\<string, mixed\\> and null will always evaluate to true\\.$#"
count: 1
path: app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
message: "#^Parameter \\#1 \\$obj of function get_object_vars expects object, true given\\.$#"
count: 1
path: app/code/core/Mage/Checkout/Model/Cart/Payment/Api/V2.php

Expand Down Expand Up @@ -4481,12 +4486,7 @@ parameters:
path: app/code/core/Mage/Customer/Model/Customer/Api/V2.php

-
message: "#^Strict comparison using \\!\\=\\= between array\\<string, mixed\\> and null will always evaluate to true\\.$#"
count: 1
path: app/code/core/Mage/Customer/Model/Customer/Api/V2.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
message: "#^Parameter \\#1 \\$obj of function get_object_vars expects object, true given\\.$#"
count: 1
path: app/code/core/Mage/Customer/Model/Customer/Api/V2.php

Expand Down Expand Up @@ -5280,6 +5280,11 @@ parameters:
count: 1
path: app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php

-
message: "#^Call to function is_null\\(\\) with \\(int\\|string\\) will always evaluate to false\\.$#"
count: 1
path: app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php

-
message: "#^Method Mage_Eav_Model_Entity_Attribute_Source_Interface\\:\\:getAllOptions\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
Expand Down Expand Up @@ -5380,11 +5385,6 @@ parameters:
count: 1
path: app/code/core/Mage/Index/Model/Lock.php

-
message: "#^Strict comparison using \\=\\=\\= between mixed and null will always evaluate to false\\.$#"
count: 1
path: app/code/core/Mage/Index/Model/Lock.php

-
message: "#^Method Mage_Core_Model_Resource\\:\\:getConnection\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
Expand Down Expand Up @@ -5540,6 +5540,11 @@ parameters:
count: 4
path: app/code/core/Mage/Oauth/Model/Resource/Token/Collection.php

-
message: "#^Parameter \\#1 \\$value of method Mage_Oauth_Model_Consumer_Validator_KeyLength\\:\\:isValid\\(\\) expects string, true given\\.$#"
count: 1
path: app/code/core/Mage/Oauth/Model/Token.php

-
message: "#^Parameter \\#1 \\$data of method Mage_Oauth_Adminhtml_Oauth_ConsumerController\\:\\:_setFormData\\(\\) expects array, null given\\.$#"
count: 2
Expand Down
4 changes: 2 additions & 2 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public static function throwException($message, $messageStorage = null)
*/
public static function app($code = '', $type = 'store', $options = [])
{
if (self::$_app === null) {
if (is_null(self::$_app)) {
self::$_app = new Mage_Core_Model_App();
self::setRoot();
self::$_events = new Varien_Event_Collection();
Expand Down Expand Up @@ -818,7 +818,7 @@ protected static function _setConfigModel($options = [])
*/
public static function isInstalled($options = [])
{
if (self::$_isInstalled === null) {
if (is_null(self::$_isInstalled)) {
self::setRoot();

if (is_string($options)) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Mage_Admin_Model_Acl extends Zend_Acl
*/
protected function _getRoleRegistry()
{
if ($this->_roleRegistry === null) {
if (is_null($this->_roleRegistry)) {
$this->_roleRegistry = Mage::getModel('admin/acl_role_registry');
}
return $this->_roleRegistry;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function getRoles()
*/
public function getRole()
{
if ($this->_role === null) {
if (is_null($this->_role)) {
$this->_role = Mage::getModel('admin/roles');
$roles = $this->getRoles();
if ($roles && isset($roles[0]) && $roles[0]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
public function getRootByIds($ids)
{
$root = Mage::registry('root');
if ($root === null) {
if (is_null($root)) {
$categoryTreeResource = Mage::getResourceSingleton('catalog/category_tree');
$ids = $categoryTreeResource->getExistingCategoryIdsBySpecifiedIds($ids);
$tree = $categoryTreeResource->loadByIds($ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected function _isParentSelectedCategory($node)
*/
protected function _getSelectedNodes()
{
if ($this->_selectedNodes === null) {
if (is_null($this->_selectedNodes)) {
$this->_selectedNodes = [];
$root = $this->getRoot();
foreach ($this->getCategoryIds() as $categoryId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function _sortValues($data)
*/
public function getCustomerGroups($groupId = null)
{
if ($this->_customerGroups === null) {
if (is_null($this->_customerGroups)) {
if (!Mage::helper('catalog')->isModuleEnabled('Mage_Customer')) {
return [];
}
Expand All @@ -139,7 +139,7 @@ public function getCustomerGroups($groupId = null)
}
}

if ($groupId !== null) {
if (!is_null($groupId)) {
return $this->_customerGroups[$groupId] ?? [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class Mage_Adminhtml_Block_Customer_Edit_Tab_Wishlist_Grid_Renderer_Description
public function render(Varien_Object $row)
{
$value = $row->getData($this->getColumn()->getIndex());
return $value !== null ? nl2br(htmlspecialchars($value)) : '';
return !is_null($value) ? nl2br(htmlspecialchars($value)) : '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function getForm()
public function getJsTemplateName()
{
$templateCode = $this->getModel()->getTemplateCode();
if ($templateCode === null) {
if (is_null($templateCode)) {
return '';
}
return addcslashes($this->escapeHtml($templateCode), "\"\r\n\\");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function _prepareForm()
'label' => Mage::helper('newsletter')->__('Sender Name'),
'title' => Mage::helper('newsletter')->__('Sender Name'),
'required' => true,
'value' => $model->getId() !== null
'value' => !is_null($model->getId())
? $model->getTemplateSenderName()
: $identityName,
]);
Expand All @@ -93,7 +93,7 @@ protected function _prepareForm()
'title' => Mage::helper('newsletter')->__('Sender Email'),
'class' => 'validate-email',
'required' => true,
'value' => $model->getId() !== null
'value' => !is_null($model->getId())
? $model->getTemplateSenderEmail()
: $identityEmail
]);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Report/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function _prepareCollection()

$collection->setStoreIds($storeIds);

if ($this->getSubReportSize() !== null) {
if (!is_null($this->getSubReportSize())) {
$collection->setPageSize($this->getSubReportSize());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Mage_Adminhtml_Block_Sales_Order_Creditmemo_Totals extends Mage_Adminhtml_

public function getCreditmemo()
{
if ($this->_creditmemo === null) {
if (is_null($this->_creditmemo)) {
if ($this->hasData('creditmemo')) {
$this->_creditmemo = $this->_getData('creditmemo');
} elseif (Mage::registry('current_creditmemo')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Mage_Adminhtml_Block_Sales_Order_Invoice_Totals extends Mage_Adminhtml_Blo

public function getInvoice()
{
if ($this->_invoice === null) {
if (is_null($this->_invoice)) {
if ($this->hasData('invoice')) {
$this->_invoice = $this->_getData('invoice');
} elseif (Mage::registry('current_invoice')) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Store/Switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function _toHtml()
*/
public function hasDefaultOption($hasDefaultOption = null)
{
if ($hasDefaultOption !== null) {
if (!is_null($hasDefaultOption)) {
$this->_hasDefaultOption = $hasDefaultOption;
}
return $this->_hasDefaultOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function _prepareArrayRow(Varien_Object $row)
*/
public function getArrayRows()
{
if ($this->_arrayRowsCache !== null) {
if (!is_null($this->_arrayRowsCache)) {
return $this->_arrayRowsCache;
}
$result = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function _getExtraJs($element, $tooltipsExist = false)
*/
protected function _getCollapseState($element)
{
if ($element->getExpanded() !== null) {
if (!is_null($element->getExpanded())) {
return 1;
}
$extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public function getAttributes($entityType)
*/
public function getValue($key, $default = '', $defaultNew = null)
{
if ($defaultNew !== null) {
if (!is_null($defaultNew)) {
if ($this->getProfileId() == 0) {
$default = $defaultNew;
}
}

$value = $this->getData($key);
return $this->escapeHtml($value !== null && strlen($value) > 0 ? $value : $default);
return $this->escapeHtml(!is_null($value) && strlen($value) > 0 ? $value : $default);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getFormKey()
*/
public function isOutputEnabled($moduleName = null)
{
if ($moduleName === null) {
if (is_null($moduleName)) {
$moduleName = $this->getModuleName();
}
return !Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function _setFormChild()
*/
public function getButtonsHtml($area = null)
{
if ($this->_buttonsHtml === null) {
if (is_null($this->_buttonsHtml)) {
$this->_buttonsHtml = parent::getButtonsHtml();
foreach (array_keys($this->_children) as $alias) {
if (str_contains($alias, '_button')) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Mage_Adminhtml_Block_Widget extends Mage_Adminhtml_Block_Template
{
public function getId()
{
if ($this->getData('id') === null) {
if (is_null($this->getData('id'))) {
$this->setData('id', Mage::helper('core')->uniqHash('id_'));
}
return $this->getData('id');
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ protected function _addColumnFilterToCollection($column)
call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
} else {
$cond = $column->getFilter()->getCondition();
if ($field && $cond !== null) {
if ($field && !is_null($cond)) {
$filtered = array_map(static function ($value) {
return is_object($value) ? $value->__toString() : $value;
}, is_array($cond) ? array_values($cond) : [$cond]);
Expand Down Expand Up @@ -1761,7 +1761,7 @@ public function getRowspan($item, $column)
*/
public function isColumnGrouped($column, $value = null)
{
if ($value === null) {
if (is_null($value)) {
if (is_object($column)) {
return in_array($column->getIndex(), $this->_groupedColumn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ public function renderProperty()

if ($this->getColumn()->hasData('width')) {
$customWidth = $this->getColumn()->getData('width');
if (($customWidth === null) || (preg_match('/^[0-9]+%?$/', (string)$customWidth))) {
if ((is_null($customWidth)) || (preg_match('/^[0-9]+%?$/', (string)$customWidth))) {
$width = $customWidth;
} elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
$width = (int)$matches[1];
}
}

if ($width !== null) {
if (!is_null($width)) {
$out .= ' width="' . $width . '"';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function removeItem($itemId)
*/
public function getUseSelectAll()
{
return $this->_getData('use_select_all') === null || $this->_getData('use_select_all');
return is_null($this->_getData('use_select_all')) || $this->_getData('use_select_all');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected function _beforeToHtml()
$this->_setActiveTab($activeTabId);
}

if ($this->_activeTab === null && !empty($this->_tabs)) {
if (is_null($this->_activeTab) && !empty($this->_tabs)) {
$this->_activeTab = (reset($this->_tabs))->getId();
}

Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ protected function _parseOptions(Mage_Sales_Model_Quote_Item $item, $additionalO

$parsedValue = $group->parseOptionValue($value, $productOptions[$label]['values']);

if ($parsedValue !== null) {
if (!is_null($parsedValue)) {
$newOptions[$optionId] = $parsedValue;
} else {
$newAdditionalOptions[] = [
Expand Down Expand Up @@ -1408,7 +1408,7 @@ public function _prepareCustomer()
if ($customerAddressId && $customer->getId()) {
$customer->getAddressItemById($customerAddressId)->addData($customerShippingAddress->getData());
} elseif (!empty($customerAddressId)
&& $customerBillingAddress !== null
&& !is_null($customerBillingAddress)
&& $this->getBillingAddress()->getCustomerAddressId() == $customerAddressId
) {
$customerBillingAddress->setIsDefaultShipping(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ protected function _initProductSave()
* Initialize product categories
*/
$categoryIds = $this->getRequest()->getPost('category_ids');
if ($categoryIds !== null) {
if (!is_null($categoryIds)) {
if (empty($categoryIds)) {
$categoryIds = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function editStoreAction()
$codeBase = Mage::helper('core')->__('Before modifying the store view code please make sure that it is not used in index.php.');
break;
}
if ($itemId !== null) {
if (!is_null($itemId)) {
$model->load($itemId);
}

Expand Down
Loading
Loading