Skip to content

Commit

Permalink
Merge branch 'main' into phpcs-ecg
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored Sep 6, 2024
2 parents 08277ed + 4e73e60 commit d9c0d14
Show file tree
Hide file tree
Showing 38 changed files with 156 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .ddev/commands/web/magerun
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Example: "ddev magerun"

if [ ! -f vendor/bin/n98-magerun ]; then
read -r -p "n98-magerun is not installed. Do you want to install it? [y/N] " INSTALL_MAGE
read -r -p "n98-magerun is not installed. Do you want to install it? [y/N] " INSTALL_MAGERUN
INSTALL_MAGERUN=${INSTALL_MAGERUN,,} # to lower
if [[ "${INSTALL_MAGERUN}" =~ ^(yes|y) ]]; then
composer require --dev n98/magerun:dev-develop
Expand Down
Empty file modified .ddev/commands/web/openmage-admin
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@
'phpstan':
- changed-files:
- any-glob-to-any-file: [
.phpstan*,
phpstan*,
.github/workflows/phpstan.yml
]
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ name: "CodeQL"

on:
workflow_call:
# Allow manually triggering the workflow.
workflow_dispatch:
push:
branches: [ "main", "next", "v19" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main", "next", "v19" ]
paths-ignore:
- '**/*.md'
- '**/*.txt'

jobs:
analyze:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@
.phpcs*.xml
!.phpcs*.xml.dist

# PhpStan
.phpstan*.neon
phpstan*.neon
!phpstan.dist.*.neon
!.phpstan.dist.neon
!.phpstan.dist.*.neon

# dev scripts loaded via composer
/shell/update-copyright.php
Expand Down
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'class_definition' => true,
// Remove extra spaces in a nullable typehint.
'compact_nullable_typehint' => true,
// Concatenation should be spaced according to configuration.
'concat_space' => ['spacing' => 'one'],
// The PHP constants `true`, `false`, and `null` MUST be written using the correct casing.
'constant_case' => true,
// Equal sign in declare statement should be surrounded by spaces or not following configuration.
Expand Down
5 changes: 5 additions & 0 deletions phpstan.dist.baseline.neon → .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3965,6 +3965,11 @@ parameters:
count: 1
path: app/code/core/Mage/Sales/Model/Entity/Quote/Address/Attribute/Frontend/Tax.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
path: app/code/core/Mage/Sales/Model/Order.php

-
message: "#^Variable \\$oldArea might not be defined\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion phpstan.dist.neon → .phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- vendor/macopedia/phpstan-magento1/extension.neon
- phpstan.dist.baseline.neon
- .phpstan.dist.baseline.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
magentoRootPath: %currentWorkingDirectory%
Expand Down
2 changes: 1 addition & 1 deletion app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public static function getStoreConfigAsInt(string $path, $store = null): int
* Retrieve config flag for store by path
*
* @param string $path
* @param mixed $store
* @param null|string|bool|int|Mage_Core_Model_Store $store
* @return bool
*/
public static function getStoreConfigFlag($path, $store = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function _prepareForm()

$fieldset->addField('req_text', 'note', [
'text' => '<ul class="messages"><li class="notice-msg"><ul><li>'
. $this->__('Only attributes with scope "Global", input type "Dropdown" and Use To Create Configurable Product "Yes" are available.')
. $this->__('Only attributes with scope "Global", input type "Dropdown" and Use To Create Configurable Product "Yes" are available.')
. '</li></ul></li></ul>'
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function initForm()
$form->getElement('website_id')->setAfterElementHtml(
'<script type="text/javascript">'
. "
var {$prefix}_websites = " . Mage::helper('core')->jsonEncode($websites) .";
var {$prefix}_websites = " . Mage::helper('core')->jsonEncode($websites) . ";
Validation.add(
'validate-website-has-store',
'" . Mage::helper('core')->jsQuoteEscape(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function _prepareLayout()
'name' => 'add_address_button',
'element_name' => 'add_address_button',
'disabled' => $this->isReadonly(),
'class' => 'add' . ($this->isReadonly() ? ' disabled' : ''),
'class' => 'add' . ($this->isReadonly() ? ' disabled' : ''),
'onclick' => 'customerAddresses.addNewAddress()'
])
);
Expand All @@ -75,7 +75,7 @@ protected function _prepareLayout()
'id' => 'cancel_add_address' . $this->getTemplatePrefix(),
'name' => 'cancel_address',
'element_name' => 'cancel_address',
'class' => 'cancel delete-address' . ($this->isReadonly() ? ' disabled' : ''),
'class' => 'cancel delete-address' . ($this->isReadonly() ? ' disabled' : ''),
'disabled' => $this->isReadonly(),
'onclick' => 'customerAddresses.cancelAdd(this)',
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function canSendCommentEmail()
/**
* Replace links in string
*
* @param array|string $data
* @param null|array $allowedTags
* @return string
* @param string|string[] $data
* @param array|null $allowedTags
* @return null|string|string[]
*/
public function escapeHtml($data, $allowedTags = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function isCustomerNotificationNotApplicable(Mage_Sales_Model_Order_Statu
/**
* Replace links in string
*
* @param array|string $data
* @param null|array $allowedTags
* @return string
* @param string|string[] $data
* @param array|null $allowedTags
* @return null|string|string[]
*/
public function escapeHtml($data, $allowedTags = null)
{
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Adminhtml/Helper/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public function applySalableProductTypesFilter($collection)
/**
* Escape string preserving links
*
* @param array|string $data
* @param null|array $allowedTags
* @return string
* @param string|string[] $data
* @param array|null $allowedTags
* @return null|string|string[]
*/
public function escapeHtmlWithLinks($data, $allowedTags = null)
{
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ public function setBaseFile($file)
// add misc params as a hash
$miscParams = [
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_backgroundColorStr,
'angle' . $this->_angle,
'quality' . $this->_quality
Expand Down
45 changes: 41 additions & 4 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object
/**
* @var Varien_Object
*/
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
private static $_transportObject;

/**
Expand Down Expand Up @@ -524,6 +525,7 @@ public function unsetCallChild($alias, $callback, $result, $params)
}

Mage::helper('core/security')->validateAgainstBlockMethodBlacklist($child, $callback, $params);
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if ($result == call_user_func_array([&$child, $callback], $params)) {
$this->unsetChild($alias);
}
Expand Down Expand Up @@ -863,7 +865,7 @@ public function getChildGroup($groupName, $callback = null, $skipEmptyResults =
*
* @param string $alias
* @param string $key
* @return mixed
* @return mixed|void
*/
public function getChildData($alias, $key = '')
{
Expand Down Expand Up @@ -1167,6 +1169,7 @@ public function getModuleName()
public function __()
{
$args = func_get_args();
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->getModuleName());
array_unshift($args, $expr);
return $this->_getApp()->getTranslator()->translate($args);
Expand All @@ -1187,15 +1190,49 @@ public function htmlEscape($data, $allowedTags = null)
/**
* Escape html entities
*
* @param string|array $data
* @param array $allowedTags
* @return string
* @param string|string[] $data
* @param array|null $allowedTags
* @return null|string|string[]
*/
public function escapeHtml($data, $allowedTags = null)
{
return $this->helper('core')->escapeHtml($data, $allowedTags);
}

/**
* Wrapper for escapeHtml() function with keeping original value
*
* @param string $data
* @param string[]|null $allowedTags
* @return Mage_Core_Model_Security_HtmlEscapedString
*
* @see Mage_Core_Model_Security_HtmlEscapedString::getUnescapedValue()
*/
public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
return new Mage_Core_Model_Security_HtmlEscapedString($data, $allowedTags);
}

/**
* Wrapper for escapeHtml() function with keeping original value
*
* @param string[] $data
* @param string[]|null $allowedTags
* @return Mage_Core_Model_Security_HtmlEscapedString[]
*
* @see Mage_Core_Model_Security_HtmlEscapedString::getUnescapedValue()
*/
public function escapeHtmlArrayAsObject(array $data, ?array $allowedTags = null): array
{
$result = [];
foreach ($data as $key => $string) {
$result[$key] = $this->escapeHtmlAsObject($string, $allowedTags);
}

return $result;
}

/**
* Wrapper for standard strip_tags() function with extra functionality for html entities
*
Expand Down
19 changes: 10 additions & 9 deletions app/code/core/Mage/Core/Helper/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ public function __()
}

/**
* @param array $data
* @param array $allowedTags
* @return mixed
* @param string|string[] $data
* @param array|null $allowedTags
* @return null|string|string[]
*
* @see self::escapeHtml()
* @deprecated after 1.4.0.0-rc1
*/
Expand All @@ -192,9 +193,9 @@ public function htmlEscape($data, $allowedTags = null)
/**
* Escape html entities
*
* @param string|array $data
* @param array $allowedTags
* @return mixed
* @param string|string[] $data
* @param array|null $allowedTags
* @return null|string|string[]
*/
public function escapeHtml($data, $allowedTags = null)
{
Expand Down Expand Up @@ -244,7 +245,7 @@ function ($matches) {
* Wrapper for standard strip_tags() function with extra functionality for html entities
*
* @param string $data
* @param string $allowableTags
* @param null|string|string[] $allowableTags
* @param bool $escape
* @return string
*/
Expand Down Expand Up @@ -320,9 +321,9 @@ public function escapeScriptIdentifiers($data)
/**
* Escape quotes in java script
*
* @param mixed $data
* @param string|string[] $data
* @param string $quote
* @return mixed
* @return string|string[]
*/
public function jsQuoteEscape($data, $quote = '\'')
{
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 @@ -419,7 +419,7 @@ protected function _translateLayoutNode($node, &$args)
* Save block in blocks registry
*
* @param string $name
* @param Mage_Core_Model_Layout $block
* @param Mage_Core_Block_Abstract $block
* @return $this
*/
public function setBlock($name, $block)
Expand Down
37 changes: 35 additions & 2 deletions app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,35 @@
declare(strict_types=1);

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category Mage
* @package Mage_Core
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Wrapper to escape a string value with a method to get the original string value
*
* @category Mage
* @package Mage_Core
*/
class Mage_Core_Model_Security_HtmlEscapedString implements Stringable
{
protected $originalValue;
protected $allowedTags;
/**
* @var string
*/
protected string $originalValue;

/**
* @var string[]|null
*/
protected ?array $allowedTags;

/**
* @param string $originalValue
Expand All @@ -20,6 +43,11 @@ public function __construct(string $originalValue, ?array $allowedTags = null)
$this->allowedTags = $allowedTags;
}

/**
* Get escaped html entities
*
* @return string
*/
public function __toString(): string
{
return (string) Mage::helper('core')->escapeHtml(
Expand All @@ -28,6 +56,11 @@ public function __toString(): string
);
}

/**
* Get un-escaped html entities
*
* @return string
*/
public function getUnescapedValue(): string
{
return $this->originalValue;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public function getTemplateFile($file, $type, $localeCode = null)
$localeCode = $this->getLocale();
}

$filePath = Mage::getBaseDir('locale') . DS
$filePath = Mage::getBaseDir('locale') . DS
. $localeCode . DS . 'template' . DS . $type . DS . $file;

if (!file_exists($filePath)) { // If no template specified for this locale, use store default
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Customer/controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ public function resetPasswordPostAction()
*/
protected function getCustomerId()
{
$customerId = $this->getRequest()->getQuery('id');
if (strlen($customerId) > 12) {
$customerId = $this->getRequest()->getQuery('id', false);
if (is_string($customerId) && strlen($customerId) > 12) {
$customerCollection = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect(['rp_customer_id'])
Expand Down
Loading

0 comments on commit d9c0d14

Please sign in to comment.