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

Type casting and minor fixes in preparation for declare strict_types=1 #3648

Merged
merged 15 commits into from
May 6, 2024
Merged
2 changes: 1 addition & 1 deletion app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public static function isInstalled($options = [])
if (is_readable($localConfigFile)) {
$localConfig = simplexml_load_file($localConfigFile);
date_default_timezone_set('UTC');
if (($date = $localConfig->global->install->date) && strtotime($date)) {
if (($date = $localConfig->global->install->date) && strtotime((string)$date)) {
self::$_isInstalled = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public function getEscapedValue($index = null)
return null;
}

return number_format($value, 2, null, '');
return number_format((float)$value, 2, null, '');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function renderProperty()

if ($this->getColumn()->hasData('width')) {
$customWidth = $this->getColumn()->getData('width');
if (($customWidth === null) || (preg_match('/^[0-9]+%?$/', $customWidth))) {
if (($customWidth === null) || (preg_match('/^[0-9]+%?$/', (string)$customWidth))) {
$width = $customWidth;
} elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
$width = (int)$matches[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public function contentsAction()
$this->loadLayout('empty');
$this->renderLayout();
} catch (Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
if (Mage::getIsDeveloperMode()) {
$result = ['error' => true, 'message' => $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()];
} else {
$result = ['error' => true, 'message' => $e->getMessage()];
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
Expand All @@ -88,7 +92,11 @@ public function newFolderAction()
$path = $this->getStorage()->getSession()->getCurrentPath();
$result = $this->getStorage()->createDirectory($name, $path);
} catch (Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
if (Mage::getIsDeveloperMode()) {
$result = ['error' => true, 'message' => $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()];
} else {
$result = ['error' => true, 'message' => $e->getMessage()];
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
Expand All @@ -99,7 +107,11 @@ public function deleteFolderAction()
$path = $this->getStorage()->getSession()->getCurrentPath();
$this->getStorage()->deleteDirectory($path);
} catch (Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
if (Mage::getIsDeveloperMode()) {
$result = ['error' => true, 'message' => $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()];
} else {
$result = ['error' => true, 'message' => $e->getMessage()];
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
Expand Down Expand Up @@ -128,7 +140,11 @@ public function deleteFilesAction()
}
}
} catch (Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
if (Mage::getIsDeveloperMode()) {
$result = ['error' => true, 'message' => $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()];
} else {
$result = ['error' => true, 'message' => $e->getMessage()];
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
Expand All @@ -144,7 +160,11 @@ public function uploadAction()
$targetPath = $this->getStorage()->getSession()->getCurrentPath();
$result = $this->getStorage()->uploadFile($targetPath, $this->getRequest()->getParam('type'));
} catch (Exception $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
if (Mage::getIsDeveloperMode()) {
$result = ['errorcode' => $e->getCode(), 'error' => $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()];
} else {
$result = ['errorcode' => $e->getCode(), 'error' => $e->getMessage()];
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ public function saveAction()
} catch (Exception $e) {
$session->addException(
$e,
Mage::helper('adminhtml')->__('An error occurred while saving this configuration:') . ' '
. $e->getMessage()
Mage::helper('adminhtml')->__('An error occurred while saving this configuration:') . ' ' . (Mage::getIsDeveloperMode() ? $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() : $e->getMessage())
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Cms/Helper/Wysiwyg/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function getCurrentPath()
$node = $this->_getRequest()->getParam($this->getTreeNodeName());
if ($node) {
$path = realpath($this->convertIdToPath($node));
if (is_dir($path) && stripos($path, $currentPath) !== false) {
if ($path && is_dir($path) && stripos($path, $currentPath) !== false) {
$currentPath = $path;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Helper/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function getAcceptedSaveCookiesWebsiteIds()
protected function _getAcceptedSaveCookiesWebsites()
{
$serializedList = $this->_cookieModel->get(self::IS_USER_ALLOWED_SAVE_COOKIE);
$unSerializedList = json_decode($serializedList, true);
$unSerializedList = $serializedList ? json_decode($serializedList, true) : null;
return is_array($unSerializedList) ? $unSerializedList : [];
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ protected function _makeEventsLowerCase($area, Varien_Simplexml_Config $mergeMod
$newEventName = strtolower($oldName);
if (!isset($events->$newEventName)) {
/** @var Mage_Core_Model_Config_Element $newNode */
$newNode = $events->addChild($newEventName, $event);
$newNode = $events->addChild($newEventName, (string)$event);
$newNode->extend($event);
}
unset($events->$oldName);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Config/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function is($var, $value = true)
}
}

return !empty($flag) && (strcasecmp($value, (string)$flag) === 0);
return !empty($flag) && (strcasecmp((string)$value, (string)$flag) === 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function gmtDate($format = null, $input = null)
return false;
}

return date($format, $date);
return date($format, (int)$date);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function generateXml()
continue;
}
if (!isset($block->attributes()->ignore)) {
$block->addAttribute('ignore', true);
$block->addAttribute('ignore', 'true');
fballiano marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions app/code/core/Mage/Core/Model/Layout/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public function isValid($value)
try {
$value = new Varien_Simplexml_Element('<config>' . $value . '</config>');
} catch (Exception $e) {
if (Mage::getIsDeveloperMode()) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
throw new Exception($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
}
$this->_error(self::XML_INVALID);
return false;
}
Expand All @@ -158,6 +161,9 @@ public function isValid($value)
try {
$this->validateTemplatePath($templatePaths);
} catch (Exception $e) {
if (Mage::getIsDeveloperMode()) {
throw new Exception($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
}
$this->_error(self::INVALID_TEMPLATE_PATH);
return false;
}
Expand Down Expand Up @@ -233,9 +239,9 @@ public function validateTemplatePath(array $templatePaths)
/** @var Varien_Simplexml_Element $path */
foreach ($templatePaths as $path) {
if ($path->hasChildren()) {
$path = stripcslashes(trim((string) $path->children(), '"'));
$path = stripcslashes(trim((string)$path->children(), '"'));
}
if (strpos($path, '..' . DS) !== false) {
if (strpos((string)$path, '..' . DS) !== false) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
throw new Exception();
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Resource/Helper/Mysql4.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function prepareColumnsList(Varien_Db_Select $select, $groupByCondition =
list($correlationName, $column, $alias) = $columnEntry;
if ($column instanceof Zend_Db_Expr) {
if ($alias !== null) {
if (preg_match('/(^|[^a-zA-Z_])^(SELECT)?(SUM|MIN|MAX|AVG|COUNT)\s*\(/i', $column, $matches)) {
if (preg_match('/(^|[^a-zA-Z_])^(SELECT)?(SUM|MIN|MAX|AVG|COUNT)\s*\(/i', (string)$column, $matches)) {
$column = $this->prepareColumn($column, $groupByCondition);
}
$preparedColumns[strtoupper($alias)] = [null, $column, $alias];
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function start($sessionName = null)
// no break
default:
session_save_path($this->getSessionSavePath());
session_module_name($moduleName);
session_module_name((string)$moduleName);
fballiano marked this conversation as resolved.
Show resolved Hide resolved
break;
}

Expand All @@ -105,7 +105,7 @@ public function start($sessionName = null)

// session cookie params
$cookieParams = [
'lifetime' => $cookie->getLifetime(),
'lifetime' => (int)$cookie->getLifetime(),
'path' => $cookie->getPath(),
'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
Expand Down
3 changes: 3 additions & 0 deletions app/code/core/Mage/Core/Model/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ protected function _loadCache()
return false;
}
$data = Mage::app()->loadCache($this->getCacheId());
if (!$data) {
return false;
}
$data = unserialize($data, ['allowed_classes' => false]);
return $data;
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Customer/Model/Address/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function getFormats()
foreach ($this->getNode('formats')->children() as $typeCode => $typeConfig) {
$path = sprintf('%s%s', self::XML_PATH_ADDRESS_TEMPLATE, $typeCode);
$type = new Varien_Object();
$htmlEscape = strtolower($typeConfig->htmlEscape);
$htmlEscape = strtolower((string)$typeConfig->htmlEscape);
$htmlEscape = !($htmlEscape == 'false' || $htmlEscape == '0' || $htmlEscape == 'no'
|| !strlen($typeConfig->htmlEscape));
|| !strlen((string)$typeConfig->htmlEscape));
fballiano marked this conversation as resolved.
Show resolved Hide resolved
$type->setCode($typeCode)
->setTitle((string)$typeConfig->title)
->setDefaultFormat(Mage::getStoreConfig($path, $store))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function _initSelect()
'scope_table.%s',
'main_table.%s'
);
$expression = sprintf($expression, $columnName, $columnName, $columnName);
$expression = sprintf((string)$expression, $columnName, $columnName, $columnName);
$this->addFilterToMap($columnName, $expression);
$scopeColumns[$alias] = $columnName;
} elseif (isset($extraColumns[$columnName])) {
Expand All @@ -161,7 +161,7 @@ protected function _initSelect()
'scope_table.%s',
'additional_table.%s'
);
$expression = sprintf($expression, $columnName, $columnName, $columnName);
$expression = sprintf((string)$expression, $columnName, $columnName, $columnName);
$this->addFilterToMap($columnName, $expression);
$scopeColumns[$alias] = $columnName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function _beforeLoad()
$code = sprintf('scope_%s', $columnName);
$expression = $connection->getCheckSql('sa.%s IS NULL', 'ea.%s', 'sa.%s');
$saColumns[$code] = new Zend_Db_Expr(sprintf(
$expression,
(string)$expression,
$columnName,
$columnName,
$columnName
Expand All @@ -213,7 +213,7 @@ protected function _beforeLoad()
$code = sprintf('scope_%s', $columnName);
$expression = $connection->getCheckSql('sa.%s IS NULL', 'ca.%s', 'sa.%s');
$saColumns[$code] = new Zend_Db_Expr(sprintf(
$expression,
(string)$expression,
$columnName,
$columnName,
$columnName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_productName = urlencode(trim($_helper->productAttribute($_product, $_product->getName(), 'name')))?>
<?php $_productImageUrl = urlencode(trim($this->helper('catalog/image')->init($_product, 'image')))?>
<?php $_productImageUrl = urlencode(trim((string)$this->helper('catalog/image')->init($_product, 'image')))?>
<?php $_productUrl = urlencode(trim($_product->getProductUrl()))?>
<li>
<?php $_u = 'p[url]=' . $_productUrl . '&p[images][0]=' . $_productImageUrl . '&p[title]=' . $_productName . '&p[summary]=' . urlencode(trim($_helper->productAttribute($_product, nl2br($_product->getShortDescription() ?? ''), 'short_description'))); ?>
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Data/Form/Element/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function removeClass($class)
*/
protected function _escape($string)
{
return htmlspecialchars($string, ENT_COMPAT);
return htmlspecialchars((string)$string, ENT_COMPAT);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Varien/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public function query($sql, $bind = [])
*/
protected function _prepareQuery(&$sql, &$bind = [])
{
$sql = (string) $sql;
$sql = (string)$sql;
if (!is_array($bind)) {
$bind = [$bind];
}
Expand Down Expand Up @@ -3071,7 +3071,7 @@ protected function _prepareQuotedSqlCondition($text, $value, $fieldName)
{
$value = is_string($value) ? str_replace("\0", '', $value) : $value;
$sql = $this->quoteInto($text, $value);
return str_replace('{{fieldName}}', $fieldName, $sql);
return str_replace('{{fieldName}}', (string)$fieldName, $sql);
}

/**
Expand All @@ -3085,7 +3085,7 @@ protected function _prepareQuotedSqlCondition($text, $value, $fieldName)
*/
protected function _transformStringSqlCondition($conditionKey, $value)
{
$value = str_replace("\0", '', (string) $value);
$value = str_replace("\0", '', (string)$value);
if ($value == '') {
return ($conditionKey == 'seq') ? 'null' : 'notnull';
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Db/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ protected function _resetJoinLeft()
*/
protected function _findTableInCond($table, $cond)
{
$cond = (string)$cond;
$quote = $this->_adapter->getQuoteIdentifierSymbol();

if (strpos($cond, $quote . $table . $quote . '.') !== false) {
Expand All @@ -226,7 +227,6 @@ protected function _findTableInCond($table, $cond)
$needle = [];
while (is_integer($result)) {
$result = strpos($cond, $table . '.', $position);

if (is_integer($result)) {
$needle[] = $result;
$position = ($result + strlen($table) + 1);
Expand Down
12 changes: 7 additions & 5 deletions lib/Varien/Simplexml/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,13 @@ public function loadCache()
}

$xmlString = $this->_loadCache($this->getCacheId());
$xml = simplexml_load_string($xmlString, $this->_elementClass);
if ($xml) {
$this->_xml = $xml;
$this->setCacheSaved(true);
return true;
if ($xmlString) {
$xml = simplexml_load_string($xmlString, $this->_elementClass);
if ($xml) {
$this->_xml = $xml;
$this->setCacheSaved(true);
return true;
}
}

return false;
Expand Down
Loading