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

Replace intval() function by using direct type casting to (int) #18764

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -162,22 +162,22 @@ protected function getQuoteItemTotalsData(\Magento\Quote\Model\Quote $quote)
$item = array_shift($items);
return [
ItemTotals::KEY_ITEM_ID => $item->getItemId(),
ItemTotals::KEY_PRICE => intval($item->getPrice()),
ItemTotals::KEY_BASE_PRICE => intval($item->getBasePrice()),
ItemTotals::KEY_PRICE => (int)$item->getPrice(),
ItemTotals::KEY_BASE_PRICE => (int)$item->getBasePrice(),
ItemTotals::KEY_QTY => $item->getQty(),
ItemTotals::KEY_ROW_TOTAL => intval($item->getRowTotal()),
ItemTotals::KEY_BASE_ROW_TOTAL => intval($item->getBaseRowTotal()),
ItemTotals::KEY_ROW_TOTAL_WITH_DISCOUNT => intval($item->getRowTotalWithDiscount()),
ItemTotals::KEY_TAX_AMOUNT => intval($item->getTaxAmount()),
ItemTotals::KEY_BASE_TAX_AMOUNT => intval($item->getBaseTaxAmount()),
ItemTotals::KEY_TAX_PERCENT => intval($item->getTaxPercent()),
ItemTotals::KEY_DISCOUNT_AMOUNT => intval($item->getDiscountAmount()),
ItemTotals::KEY_BASE_DISCOUNT_AMOUNT => intval($item->getBaseDiscountAmount()),
ItemTotals::KEY_DISCOUNT_PERCENT => intval($item->getDiscountPercent()),
ItemTotals::KEY_PRICE_INCL_TAX => intval($item->getPriceInclTax()),
ItemTotals::KEY_BASE_PRICE_INCL_TAX => intval($item->getBasePriceInclTax()),
ItemTotals::KEY_ROW_TOTAL_INCL_TAX => intval($item->getRowTotalInclTax()),
ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => intval($item->getBaseRowTotalInclTax()),
ItemTotals::KEY_ROW_TOTAL => (int)$item->getRowTotal(),
ItemTotals::KEY_BASE_ROW_TOTAL => (int)$item->getBaseRowTotal(),
ItemTotals::KEY_ROW_TOTAL_WITH_DISCOUNT => (int)$item->getRowTotalWithDiscount(),
ItemTotals::KEY_TAX_AMOUNT => (int)$item->getTaxAmount(),
ItemTotals::KEY_BASE_TAX_AMOUNT => (int)$item->getBaseTaxAmount(),
ItemTotals::KEY_TAX_PERCENT => (int)$item->getTaxPercent(),
ItemTotals::KEY_DISCOUNT_AMOUNT => (int)$item->getDiscountAmount(),
ItemTotals::KEY_BASE_DISCOUNT_AMOUNT => (int)$item->getBaseDiscountAmount(),
ItemTotals::KEY_DISCOUNT_PERCENT => (int)$item->getDiscountPercent(),
ItemTotals::KEY_PRICE_INCL_TAX => (int)$item->getPriceInclTax(),
ItemTotals::KEY_BASE_PRICE_INCL_TAX => (int)$item->getBasePriceInclTax(),
ItemTotals::KEY_ROW_TOTAL_INCL_TAX => (int)$item->getRowTotalInclTax(),
ItemTotals::KEY_BASE_ROW_TOTAL_INCL_TAX => (int)$item->getBaseRowTotalInclTax(),
ItemTotals::KEY_WEEE_TAX_APPLIED_AMOUNT => $item->getWeeeTaxAppliedAmount(),
ItemTotals::KEY_WEEE_TAX_APPLIED => $item->getWeeeTaxApplied(),
ItemTotals::KEY_NAME => $item->getName(),
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ protected function generateFixtureXml(array $config)
foreach ($fields as $fieldName => $fieldValue) {
$field = $this->dom->createElement('field');
$field->setAttribute('name', $fieldName);
$field->setAttribute('is_required', intval($fieldValue['is_required']));
$field->setAttribute('is_required', (int)$fieldValue['is_required']);
$fixture->appendChild($field);
}

Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ function (&$item, $key, $formattingOptions) {
protected function prepareUrlKey($urlKey)
{
preg_match("~\d+$~", $urlKey, $matches);
$key = intval($matches[0]) + 1;
$key = (int)$matches[0] + 1;
return str_replace($matches[0], $key, $urlKey);
}

Original file line number Diff line number Diff line change
@@ -411,7 +411,7 @@ protected function prepareQuantityAndStockStatus()
: ['is_in_stock' => 'In Stock'];

if (!isset($quantityAndStockStatus['is_in_stock'])) {
$qty = isset($quantityAndStockStatus['qty']) ? intval($quantityAndStockStatus['qty']) : null;
$qty = isset($quantityAndStockStatus['qty']) ? (int)$quantityAndStockStatus['qty'] : null;
$quantityAndStockStatus['is_in_stock'] = 0 === $qty ? 'Out of Stock' : 'In Stock';
}

Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ protected function prepareFixtureData(array $data, array $sortFields = [])
protected function prepareUrlKey($urlKey)
{
preg_match("~\d+$~", $urlKey, $matches);
$key = intval($matches[0]) + 1;
$key = (int)$matches[0] + 1;
return str_replace($matches[0], $key, $urlKey);
}

Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ protected function getStoreGroupIdByGroupName($storeName)
throw new \Exception('Cannot find store group id');
}

return intval($matches[1]);
return (int)$matches[1];
}

/**
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ protected function getWebSiteIdByWebsiteName($websiteName)
throw new \Exception('Cannot find website id.');
}

return intval($matches[1]);
return (int)$matches[1];
}

/**
Original file line number Diff line number Diff line change
@@ -110,9 +110,9 @@ public function testGetCustomer()
\Magento\Customer\Api\Data\CustomerInterface::class
);
foreach ($expectedCustomerData as $property => $value) {
$expectedValue = is_numeric($value) ? intval($value) : $value;
$expectedValue = is_numeric($value) ? (int)$value : $value;
$actualValue = isset($actualCustomerData[$property]) ? $actualCustomerData[$property] : null;
$actualValue = is_numeric($actualValue) ? intval($actualValue) : $actualValue;
$actualValue = is_numeric($actualValue) ? (int)$actualValue : $actualValue;
$this->assertEquals($expectedValue, $actualValue);
}
}
2 changes: 1 addition & 1 deletion pub/errors/processor.php
Original file line number Diff line number Diff line change
@@ -466,7 +466,7 @@ protected function _setReportData($reportData)
public function saveReport($reportData)
{
$this->reportData = $reportData;
$this->reportId = abs(intval(microtime(true) * random_int(100, 1000)));
$this->reportId = abs((int)(microtime(true) * random_int(100, 1000)));
$this->_reportFile = $this->_reportDir . '/' . $this->reportId;
$this->_setReportData($reportData);

8 changes: 4 additions & 4 deletions setup/src/Magento/Setup/Model/PhpReadinessCheck.php
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ public function checkMemoryLimit()

$currentMemoryLimit = ini_get('memory_limit');

$currentMemoryInteger = intval($currentMemoryLimit);
$currentMemoryInteger = (int)$currentMemoryLimit;

if ($currentMemoryInteger > 0
&& $this->dataSize->convertSizeToBytes($currentMemoryLimit)
@@ -244,7 +244,7 @@ private function checkXDebugNestedLevel()

$currentExtensions = $this->phpInformation->getCurrent();
if (in_array('xdebug', $currentExtensions)) {
$currentXDebugNestingLevel = intval(ini_get('xdebug.max_nesting_level'));
$currentXDebugNestingLevel = (int)ini_get('xdebug.max_nesting_level');
$minimumRequiredXDebugNestedLevel = $this->phpInformation->getRequiredMinimumXDebugNestedLevel();

if ($minimumRequiredXDebugNestedLevel > $currentXDebugNestingLevel) {
@@ -286,7 +286,7 @@ private function checkPopulateRawPostSetting()

$data = [];
$error = false;
$iniSetting = intval(ini_get('always_populate_raw_post_data'));
$iniSetting = (int)ini_get('always_populate_raw_post_data');

$checkVersionConstraint = $this->versionParser->parseConstraints('~5.6.0');
$normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
@@ -302,7 +302,7 @@ private function checkPopulateRawPostSetting()
Please open your php.ini file and set always_populate_raw_post_data to -1.
If you need more help please call your hosting provider.',
PHP_VERSION,
intval(ini_get('always_populate_raw_post_data'))
(int)ini_get('always_populate_raw_post_data')
);

$data['always_populate_raw_post_data'] = [