Skip to content

Commit

Permalink
Replace intval() function by using direct type casting to (int)
Browse files Browse the repository at this point in the history
  • Loading branch information
gelanivishal committed Oct 23, 2018
1 parent 7fc1ef6 commit 937f5bc
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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

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

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

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pub/errors/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions setup/src/Magento/Setup/Model/PhpReadinessCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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'] = [
Expand Down

0 comments on commit 937f5bc

Please sign in to comment.