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

[WIP] Fixes ENV overriding config #4258

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
## Example: ddev phpunit-coverage

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --testdox
XDEBUG_MODE=coverage php vendor/bin/phpunit "$@" --testdox
disable_xdebug
2 changes: 1 addition & 1 deletion .ddev/commands/web/phpunit-coverage-local
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
## Example: ddev phpunit-coverage-local

enable_xdebug
XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage --testdox
XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage "$@" --testdox
disable_xdebug
14 changes: 14 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,19 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: "Restore result cache"
uses: actions/cache/restore@v4
with:
path: .phpstan.cache
key: "phpstan-result-cache-${{ runner.os }}-${{ matrix.php-versions }}-${{ github.run_id }}"
restore-keys: phpstan-result-cache-

- name: PHPStan Static Analysis
run: XDEBUG_MODE=off php vendor/bin/phpstan.phar analyze

- name: "Save result cache"
uses: actions/cache/save@v4
if: always()
with:
path: .phpstan.cache
key: "phpstan-result-cache-${{ runner.os }}-${{ matrix.php-versions }}-${{ github.run_id }}"
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
rector:
name: Validation
name: Rector
runs-on: [ubuntu-latest]

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
!.phpcs*.xml.dist

# PhpStan
.phpstan.cache
.phpstan*.neon
phpstan*.neon
!.phpstan.dist.neon
Expand Down
252 changes: 16 additions & 236 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ parameters:
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
treatPhpDocTypesAsCertain: false
tmpDir: .phpstan.cache
# universalObjectCratesClasses:
# - Varien_Object
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function _construct()
}

/**
* @return array|bool
* @return array|true
* @throws Exception
* @throws Zend_Validate_Exception
*/
Expand Down
9 changes: 7 additions & 2 deletions app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function getAclRole()
}

/**
* Authenticate user name and password and save loaded record
* Authenticate username and password and save loaded record
*
* @param string $username
* @param string $password
Expand All @@ -384,7 +384,7 @@ public function authenticate($username, $password)
$this->loadByUsername($username);
$sensitive = ($config) ? $username == $this->getUsername() : true;

if ($sensitive && $this->getId() && Mage::helper('core')->validateHash($password, $this->getPassword())) {
if ($sensitive && $this->getId() && $this->validatePasswordHash($password, $this->getPassword())) {
if ($this->getIsActive() != '1') {
Mage::throwException(Mage::helper('adminhtml')->__('This account is inactive.'));
}
Expand All @@ -411,6 +411,11 @@ public function authenticate($username, $password)
return $result;
}

public function validatePasswordHash(string $string1, string $string2): bool
{
return Mage::helper('core')->validateHash($string1, $string2);
}

/**
* Login user
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getProduct()
/**
* Get store ID of current product
*
* @return int
* @return string
*/
public function getStoreId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function isSingleStoreMode()
/**
* Getter for id of current store (the only one in single-store mode and current in multi-stores mode)
*
* @return int
* @return string
*/
protected function getStoreId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected function isSingleStoreMode()
/**
* Getter for id of current store (the only one in single-store mode and current in multi-stores mode)
*
* @return int
* @return string
*/
protected function getStoreId()
{
Expand Down
10 changes: 10 additions & 0 deletions app/code/core/Mage/Adminhtml/Block/System/Config/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function render(Varien_Data_Form_Element_Abstract $element)
$options = $element->getValues();

$addInheritCheckbox = false;
$checkboxLabel = '';
if ($element->getCanUseWebsiteValue()) {
$addInheritCheckbox = true;
$checkboxLabel = $this->__('Use Website');
Expand All @@ -55,6 +56,15 @@ public function render(Varien_Data_Form_Element_Abstract $element)
$checkboxLabel = $this->__('Use Default');
}

$envConfig = Mage::getConfig()->getEnvOverriddenConfigPaths();
$envConfigIds = array_combine(str_replace('/', '_', array_keys($envConfig)), array_values($envConfig));
if (array_key_exists($element->getId(), $envConfigIds)) {
$addInheritCheckbox = false;
$element->setDisabled(true);
$element->setScopeLabel('[ENV]]');
$element->setValue($envConfigIds[$element->getId()]);
}

if ($addInheritCheckbox) {
$inherit = $element->getInherit() == 1 ? 'checked="checked"' : '';
if ($inherit) {
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Adminhtml/Model/System/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Mage_Adminhtml_Model_System_Store extends Varien_Object
/**
* @var bool
*/
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
private $_isAdminScopeAllowed = true;

/**
Expand Down Expand Up @@ -122,6 +123,7 @@ public function getStoreValuesForForm($empty = false, $all = false)
];
}

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');

foreach ($this->_websiteCollection as $website) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function deleteStorePostAction()
*
* @param string $failPath redirect path if backup failed
* @param array $arguments
* @return $this
* @return $this|void
*/
protected function _backupDatabase($failPath, $arguments = [])
{
Expand All @@ -468,11 +468,11 @@ protected function _backupDatabase($failPath, $arguments = [])
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
$this->_redirect($failPath, $arguments);
return ;
return;
} catch (Exception $e) {
$this->_getSession()->addException($e, Mage::helper('backup')->__('Unable to create backup. Please, try again later.'));
$this->_redirect($failPath, $arguments);
return ;
return;
}
return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Api2/Model/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ protected function _critical($message, $code = null)
}
$code = $errors[$message];
}
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
throw new Mage_Api2_Exception($message, $code);
}

Expand Down Expand Up @@ -657,6 +658,7 @@ protected function _getCriticalErrors()
*/
protected function _error($message, $code)
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$this->getResponse()->setException(new Mage_Api2_Exception($message, $code));
return $this;
}
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Api2/Model/Route/ApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(
?Zend_Translate $translator = null,
$locale = null
) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
parent::__construct([Mage_Api2_Model_Route_Abstract::PARAM_ROUTE => str_replace('.php', '', basename(getenv('SCRIPT_FILENAME'))) . '/:api_type']);
}
}
1 change: 0 additions & 1 deletion app/code/core/Mage/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function getTotalBundleItemsPrice($product, $qty = null)
$selectionIds = unserialize($customOption->getValue(), ['allowed_classes' => false]);
/** @var Mage_Bundle_Model_Product_Type $productType */
$productType = $product->getTypeInstance(true);
/** @var Mage_Bundle_Model_Resource_Selection_Collection $selections */
$selections = $productType->getSelectionsByIds($selectionIds, $product);
$selections->addTierPriceData();
Mage::dispatchEvent('prepare_catalog_product_collection_prices', [
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Captcha/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function isEnabled(): bool
* Get Captcha
*
* @param string $formId
* @return Mage_Captcha_Model_Interface
* @return Mage_Captcha_Model_Zend
*/
public function getCaptcha($formId)
{
Expand All @@ -76,7 +76,7 @@ public function getCaptcha($formId)
/**
* Returns value of the node with respect to current area (frontend or backend)
*
* @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case insensitive)
* @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case-insensitive)
* @param Mage_Core_Model_Store $store
* @return Mage_Core_Model_Config_Element
*/
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
/**
* Breadcrumb Path cache
*
* @var string
* @var string|array<string, array<string, string|null>>
*/
protected $_categoryPath;

Expand Down Expand Up @@ -236,7 +236,7 @@ public function isPriceGlobal()
/**
* Indicate whether to save URL Rewrite History or not (create redirects to old URLs)
*
* @param int $storeId Store View
* @param null|string|bool|int|Mage_Core_Model_Store $storeId Store View
* @return bool
*/
public function shouldSaveUrlRewritesHistory($storeId = null)
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Api/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function _isAllowedAttribute($attribute, $attributes = null)
* it use seted session or admin store
*
* @param string|int $store
* @return int
* @return string
*/
protected function _getStoreId($store = null)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ protected function _getProduct($productId, $store = null, $identifierType = null
* Set current store for catalog.
*
* @param string|int $store
* @return int
* @return string
*/
public function currentStore($store = null)
{
Expand Down
8 changes: 5 additions & 3 deletions app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class Mage_Catalog_Model_Category extends Mage_Catalog_Model_Abstract
*
* @var array
*/
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
private $_designAttributes = [
'custom_design',
'custom_design_from',
Expand Down Expand Up @@ -313,7 +314,7 @@ public function move($parentId, $afterCategoryId)
/**
* Retrieve default attribute set id
*
* @return int
* @return string
*/
public function getDefaultAttributeSetId()
{
Expand Down Expand Up @@ -440,9 +441,9 @@ public function getLayoutUpdateHandle()
/**
* Return store id.
*
* If store id is underfined for category return current active store id
* If store id is undefined for category return current active store id
*
* @return int
* @return string
*/
public function getStoreId()
{
Expand Down Expand Up @@ -629,6 +630,7 @@ public function getDesignAttributes()
* @param string $attributeCode
* @return Mage_Eav_Model_Entity_Attribute_Abstract
*/
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
private function _getAttribute($attributeCode)
{
if (!$this->_useFlatResource) {
Expand Down
14 changes: 8 additions & 6 deletions app/code/core/Mage/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
* @method string getMetaDescription()
* @method string getMetaKeyword()
* @method string getMetaTitle()
* @method $this hasMsrpEnabled(bool $value)
* @method $this hasMsrpEnabled()
* @method bool getMsrpEnabled()
* @method string getMsrpDisplayActualPriceType()
*
Expand Down Expand Up @@ -217,7 +217,7 @@
* @method $this setStoreIds(array $storeIds)
* @method array getSwatchPrices()
*
* @method int getTaxClassId()
* @method string getTaxClassId()
* @method string getThumbnail()
* @method float getTaxPercent()
* @method $this setTaxPercent(float $value)
Expand Down Expand Up @@ -360,7 +360,7 @@ protected function _initOldFieldsMap()
/**
* Retrieve Store Id
*
* @return int
* @return string
*/
public function getStoreId()
{
Expand Down Expand Up @@ -417,7 +417,7 @@ public function validate()
/**
* Get product name
*
* @return string
* @return string|null
*/
public function getName()
{
Expand All @@ -442,16 +442,18 @@ public function getPrice()
* Set Price calculation flag
*
* @param bool $calculate
* @return $this
*/
public function setPriceCalculation($calculate = true)
{
$this->_calculatePrice = $calculate;
return $this;
}

/**
* Get product type identifier
*
* @return string
* @return string|null
*/
public function getTypeId()
{
Expand Down Expand Up @@ -875,7 +877,7 @@ public function cleanCache()
/**
* Get product price model
*
* @return Mage_Catalog_Model_Product_Type_Price|Mage_Bundle_Model_Product_Price
* @return Mage_Bundle_Model_Product_Price
*/
public function getPriceModel()
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function getUrl(Mage_Catalog_Model_Product $product, $params = [])
* Returns checked store_id value
*
* @param int|null $id
* @return int
* @return string
*/
protected function _getStoreId($id = null)
{
Expand Down
Loading
Loading