Skip to content

Commit

Permalink
ENGCOM-3190: Replace intval() function by using direct type casting t…
Browse files Browse the repository at this point in the history
…o (int) #18608
  • Loading branch information
Stanislav Idolov authored Oct 17, 2018
2 parents c6d0987 + 712830e commit e233c2d
Show file tree
Hide file tree
Showing 31 changed files with 49 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ protected function _prepareForm()
*/
protected function _getSetId()
{
return intval(
return (int)(
$this->getRequest()->getParam('id')
) > 0 ? intval(
) > 0 ? (int)(
$this->getRequest()->getParam('id')
) : $this->_typeFactory->create()->load(
$this->_coreRegistry->registry('entityType')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function getCollection(\Magento\Catalog\Model\Product $product, $type)
}

usort($sorterItems, function ($itemA, $itemB) {
$posA = intval($itemA['position']);
$posB = intval($itemB['position']);
$posA = (int)$itemA['position'];
$posB = (int)$itemB['position'];

return $posA <=> $posB;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ protected function getItemsPerPage()
// Maximal Products limit
$maxProductsLimit = 5000;

$this->_itemsPerPage = intval(
$this->_itemsPerPage = (int)(
($memoryLimit * $memoryUsagePercent - memory_get_usage(true)) / $memoryPerProduct
);
if ($this->_itemsPerPage < $minProductsLimit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function afterSave()
$frequencyMonthly = \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY;

$cronExprArray = [
intval($time[1]), # Minute
intval($time[0]), # Hour
(int)$time[1], # Minute
(int)$time[0], # Hour
$frequency == $frequencyMonthly ? '1' : '*', # Day of the Month
'*', # Month of the Year
$frequency == $frequencyWeekly ? '1' : '*', # Day of the Week
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Config/Model/Config/Backend/Log/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function afterSave()

if ($enabled) {
$cronExprArray = [
intval($time[1]), # Minute
intval($time[0]), # Hour
(int)$time[1], # Minute
(int)$time[0], # Hour
$frequency == $frequencyMonthly ? '1' : '*', # Day of the Month
'*', # Month of the Year
$frequency == $frequencyWeekly ? '1' : '*', # Day of the Week
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Cron/Model/Config/Backend/Product/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function afterSave()
$frequency = $this->getData('groups/productalert_cron/fields/frequency/value');

$cronExprArray = [
intval($time[1]), //Minute
intval($time[0]), //Hour
(int)$time[1], //Minute
(int)$time[0], //Hour
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', //Day of the Month
'*', //Month of the Year
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', //Day of the Week
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Cron/Model/Config/Backend/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function afterSave()
$frequency = $this->getData('groups/generate/fields/frequency/value');

$cronExprArray = [
intval($time[1]), //Minute
intval($time[0]), //Hour
(int)$time[1], //Minute
(int)$time[0], //Hour
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', //Day of the Month
'*', //Month of the Year
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', //# Day of the Week
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ protected function getOnlineMinutesInterval()
'customer/online_customers/online_minutes_interval',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
return intval($configValue) > 0 ? intval($configValue) : self::DEFAULT_ONLINE_MINUTES_INTERVAL;
return (int)$configValue > 0 ? (int)$configValue : self::DEFAULT_ONLINE_MINUTES_INTERVAL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Model/Renderer/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function render(AbstractElement $element)
$regionCollection = self::$_regionCollections[$countryId];
}

$regionId = intval($element->getForm()->getElement('region_id')->getValue());
$regionId = (int)$element->getForm()->getElement('region_id')->getValue();

$htmlAttributes = $element->getHtmlAttributes();
foreach ($htmlAttributes as $key => $attribute) {
Expand Down
8 changes: 3 additions & 5 deletions app/code/Magento/Customer/Model/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,9 @@ public function clean()
*/
public function getOnlineInterval()
{
$configValue = intval(
$this->scopeConfig->getValue(
static::XML_PATH_ONLINE_INTERVAL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
$configValue = (int)$this->scopeConfig->getValue(
static::XML_PATH_ONLINE_INTERVAL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
return $configValue ?: static::DEFAULT_ONLINE_MINUTES_INTERVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Directory/Block/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function getRegionHtmlSelect()
)->setClass(
'required-entry validate-state'
)->setValue(
intval($this->getRegionId())
(int)$this->getRegionId()
)->setOptions(
$options
)->getHtml();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function loadByCode(AbstractModel $object, $entityTypeId, $code)
*/
private function _getMaxSortOrder(AbstractModel $object)
{
if (intval($object->getAttributeGroupId()) > 0) {
if ((int)$object->getAttributeGroupId() > 0) {
$connection = $this->getConnection();
$bind = [
':attribute_set_id' => $object->getAttributeSetId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function cleanIndex($storeId, $mappedIndexerId)

// prepare new index name and increase version
$indexPattern = $this->indexNameResolver->getIndexPattern($storeId, $mappedIndexerId);
$version = intval(str_replace($indexPattern, '', $indexName));
$version = (int)(str_replace($indexPattern, '', $indexName));
$newIndexName = $indexPattern . ++$version;

// remove index if already exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function getAggregation(
$queryResult = $this->connectionManager->getConnection()
->query($query);
foreach ($queryResult['aggregations']['prices']['buckets'] as $bucket) {
$key = intval($bucket['key'] / $range + 1);
$key = (int)($bucket['key'] / $range + 1);
$result[$key] = $bucket['doc_count'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ protected function getProductInfo(\Magento\Framework\DataObject $buyRequest, $pr
if ($isStrictProcessMode && !$subProduct->getQty()) {
return __('Please specify the quantity of product(s).')->render();
}
$productsInfo[$subProduct->getId()] = intval($subProduct->getQty());
$productsInfo[$subProduct->getId()] = (int)$subProduct->getQty();
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Paypal/Model/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ protected function _buildQuery($request)
*/
protected function _filterQty($value)
{
return intval($value);
return (int)$value;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Paypal/Model/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ public function void(\Magento\Payment\Model\InfoInterface $payment)
public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
{
$authorizationTransaction = $payment->getAuthorizationTransaction();
$authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period')));
$maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number')));
$authorizationPeriod = abs((int)$this->getConfigData('authorization_honor_period'));
$maxAuthorizationNumber = abs((int)$this->getConfigData('child_authorization_number'));
$order = $payment->getOrder();
$isAuthorizationCreated = false;

Expand Down Expand Up @@ -750,7 +750,7 @@ public function canCapture()
return false;
}

$orderValidPeriod = abs(intval($this->getConfigData('order_valid_period')));
$orderValidPeriod = abs((int)$this->getConfigData('order_valid_period'));

$dateCompass = new \DateTime($orderTransaction->getCreatedAt());
$dateCompass->modify('+' . $orderValidPeriod . ' days');
Expand Down Expand Up @@ -805,7 +805,7 @@ protected function _callDoAuthorize($amount, $payment, $parentTransactionId)
*/
protected function _isTransactionExpired(Transaction $transaction, $period)
{
$period = intval($period);
$period = (int)$period;
if (0 == $period) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Paypal/Model/Report/Settlement.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private function formatDateTimeColumns($lineItem)
*/
private function formatAmountColumn($lineItem)
{
return intval($lineItem) / 100;
return (int)$lineItem / 100;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions app/code/Magento/Persistent/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ public function isShoppingCartPersist($store = null)
*/
public function getLifeTime($store = null)
{
$lifeTime = intval(
$this->scopeConfig->getValue(
self::XML_PATH_LIFE_TIME,
ScopeInterface::SCOPE_STORE,
$store
)
$lifeTime = (int)$this->scopeConfig->getValue(
self::XML_PATH_LIFE_TIME,
ScopeInterface::SCOPE_STORE,
$store
);
return $lifeTime < 0 ? 0 : $lifeTime;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Persistent/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function deleteExpired($websiteId = null)
$lifetime = $this->_coreConfig->getValue(
\Magento\Persistent\Helper\Data::XML_PATH_LIFE_TIME,
'website',
intval($websiteId)
(int)$websiteId
);

if ($lifetime) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Quote/Model/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ public function isVirtual()
*/
public function getIsVirtual()
{
return intval($this->isVirtual());
return (int)$this->isVirtual();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Review/Block/Adminhtml/Rating/Detailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public function getRating()
)->setStoreFilter(
$stores
)->setPositionOrder()->load()->addOptionToItems();
if (intval($this->getRequest()->getParam('id'))) {
if ((int)$this->getRequest()->getParam('id')) {
$this->_voteCollection = $this->_votesFactory->create()->setReviewFilter(
intval($this->getRequest()->getParam('id'))
(int)$this->getRequest()->getParam('id')
)->addOptionInfo()->load()->addRatingOptions();
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Review/Block/Rating/Entity/Detailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
protected function _toHtml()
{
$entityId = $this->_request->getParam('id');
if (intval($entityId) <= 0) {
if ((int)$entityId <= 0) {
return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute()
{
$response = new DataObject();
$id = $this->getRequest()->getParam('id');
if (intval($id) > 0) {
if ((int)$id > 0) {
$product = $this->productRepository->getById($id);
$response->setId($id);
$response->addData($product->getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testGetLogoutReasonCookie()
)
->willReturn($cookie);

$this->assertEquals(intval($cookie), $this->model->getLogoutReasonCookie());
$this->assertEquals((int)$cookie, $this->model->getLogoutReasonCookie());
}

/**
Expand All @@ -114,7 +114,7 @@ public function testSetLogoutReasonCookie()
->method('setPublicCookie')
->with(
SecurityCookie::LOGOUT_REASON_CODE_COOKIE_NAME,
intval($status),
(int)$status,
$this->cookieMetadataMock
)
->willReturnSelf();
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Tax/Block/Adminhtml/Rate/Toolbar/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function _prepareLayout()
['label' => __('Reset'), 'onclick' => 'window.location.reload()', 'class' => 'reset']
);

$rate = intval($this->getRequest()->getParam('rate'));
$rate = (int)$this->getRequest()->getParam('rate');
if ($rate) {
$this->buttonList->add(
'delete',
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Theme/Block/Html/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public function getJump()
*/
public function setFrameLength($frame)
{
$frame = abs(intval($frame));
$frame = abs((int)$frame);
if ($frame == 0) {
$frame = $this->_frameLength;
}
Expand All @@ -600,7 +600,7 @@ public function setFrameLength($frame)
*/
public function setJump($jump)
{
$jump = abs(intval($jump));
$jump = abs((int)$jump);
if ($this->getJump() != $jump) {
$this->_setFrameInitialized(false);
$this->_jump = $jump;
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/User/Block/Buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function _prepareLayout()
['label' => __('Reset'), 'onclick' => 'window.location.reload()', 'class' => 'reset']
);

if (intval($this->getRequest()->getParam('rid'))) {
if ((int)$this->getRequest()->getParam('rid')) {
$this->getToolbar()->addChild(
'deleteButton',
\Magento\Backend\Block\Widget\Button::class,
Expand Down Expand Up @@ -113,7 +113,7 @@ public function getSaveButtonHtml()
*/
public function getDeleteButtonHtml()
{
if (intval($this->getRequest()->getParam('rid')) == 0) {
if ((int)$this->getRequest()->getParam('rid') == 0) {
return;
}
return $this->getChildHtml('deleteButton');
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/User/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function beforeSave()
}

if ($this->getIsActive() !== null) {
$data['is_active'] = intval($this->getIsActive());
$data['is_active'] = (int)$this->getIsActive();
}

$this->addData($data);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Wishlist/Helper/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getCustomer()
if ($this->_customer === null) {
$params = $this->urlDecoder->decode($this->_getRequest()->getParam('data'));
$data = explode(',', $params);
$customerId = abs(intval($data[0]));
$customerId = abs((int)$data[0]);
if ($customerId && ($customerId == $this->_customerSession->getCustomerId())) {
$this->_customer = $this->_customerRepository->getById($customerId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public function addDaysFilter($constraints)

if (isset($constraints['to'])) {
$firstDay = new \DateTime();
$firstDay->modify('-' . $gmtOffset . ' second')->modify('-' . (intval($constraints['to']) + 1) . ' day');
$firstDay->modify('-' . $gmtOffset . ' second')->modify('-' . ((int)($constraints['to']) + 1) . ' day');
$filter['from'] = $firstDay;
}

Expand Down

0 comments on commit e233c2d

Please sign in to comment.