Skip to content

phpstan: variable.implicitArray#5551

Open
sreichel wants to merge 15 commits into
OpenMage:mainfrom
sreichel:phpstan/mixid-1
Open

phpstan: variable.implicitArray#5551
sreichel wants to merge 15 commits into
OpenMage:mainfrom
sreichel:phpstan/mixid-1

Conversation

@sreichel
Copy link
Copy Markdown
Contributor

Description (*)

Minor phpstan fixes.

Copilot AI review requested due to automatic review settings April 29, 2026 00:13
@sreichel sreichel added the chore label Apr 29, 2026
@github-actions github-actions Bot added Component: PayPal Relates to Mage_Paypal Component: Core Relates to Mage_Core Component: Catalog Relates to Mage_Catalog Component: Cms Relates to Mage_Cms Component: Checkout Relates to Mage_Checkout Component: lib/Varien Relates to lib/Varien Component: Sales Relates to Mage_Sales Template : base Relates to base template Component: Adminhtml Relates to Mage_Adminhtml Component: Page Relates to Mage_Page Component: CurrencySymbol Relates to Mage_CurrencySymbol Component: Newsletter Relates to Mage_Newsletter Component: Downloadable Relates to Mage_Downloadable Component: Bundle Relates to Mage_Bundle Component: CatalogIndex Relates to Mage_CatalogIndex Component: Paygate Relates to Mage_Paygate Component: lib/* Relates to lib/* labels Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies minor PHPStan-driven fixes by eliminating implicit array creation and a few related baseline suppressions across core, lib, and template code.

Changes:

  • Initialize variables as arrays before assigning offsets to satisfy variable.implicitArray.
  • Harden Varien_Object::_addFullNames() against non-array _data to avoid invalid array operations.
  • Remove PHPStan baseline entries/files that are no longer needed after the fixes (including class name case ignore).

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/Varien/Object.php Adds array-type guards before sync-field mapping to avoid invalid array operations.
lib/Varien/Io/File.php Initializes $owner/$group/$world arrays before offset assignment in permission parsing.
app/design/frontend/base/default/template/paypal/payment/redirect.phtml Updates docblock class references to correct case used in codebase and removes related baseline need.
app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php Initializes $lines before nested offset usage in header rendering.
app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php Initializes $lines before nested offset usage in header rendering.
app/code/core/Mage/Sales/Model/Order/Pdf/Creditmemo.php Initializes $lines before nested offset usage in header rendering.
app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php Initializes $result before setting result keys in cancel action.
app/code/core/Mage/Paygate/controllers/Adminhtml/Paygate/Authorizenet/PaymentController.php Initializes $result before setting result keys in cancel action.
app/code/core/Mage/Page/Block/Html/Toplinks.php Initializes $toplinkInfo before populating it.
app/code/core/Mage/Newsletter/Model/Resource/Subscriber.php Initializes $data before populating update payload.
app/code/core/Mage/Downloadable/Model/Resource/Link.php Initializes $dataToInsert before population.
app/code/core/Mage/CurrencySymbol/Model/System/Currencysymbol.php Initializes $value before writing nested option structure.
app/code/core/Mage/Core/Model/File/Validator/AvailablePath.php Initializes $options before setting file_mask.
app/code/core/Mage/Cms/Model/Resource/Page/Collection.php Initializes $data before setting value/label.
app/code/core/Mage/Checkout/controllers/OnepageController.php Initializes $result early for consistent array usage.
app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Minimalprice.php Initializes $conditions before appending SQL conditions.
app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Abstract.php Initializes $conditions before appending SQL conditions.
app/code/core/Mage/CatalogIndex/Model/Indexer/Minimalprice.php Initializes $data and $search arrays before offset assignment.
app/code/core/Mage/Catalog/Model/Resource/Product.php Initializes $updateCond before appending conditions.
app/code/core/Mage/Catalog/Model/Product/Image.php Initializes $path prior to usage to satisfy PHPStan (see review nit).
app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php Initializes $params before setting URL generation flags.
app/code/core/Mage/Catalog/Block/Layer/State.php Initializes $params before setting URL generation flags.
app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php Ensures $defaultValues is always defined and reorders a couple initializations.
app/code/core/Mage/Adminhtml/controllers/TagController.php Initializes $data before offset assignment; tightens return docblock.
app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php Initializes $params before use.
app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Form.php Initializes $data before building URL params.
app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php Initializes $data before building URL params; removes stray whitespace line.
app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Action.php Initializes $actions before conditional pushes.
app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php Initializes $config before nested offset assignment.
.phpstan.dist.baselines/variable.undefined.php Removes baseline entry now fixed in bundle JSON config logic.
.phpstan.dist.baselines/variable.implicitArray.php Removes many no-longer-needed ignores after explicit array initialization.
.phpstan.dist.baselines/offsetAccess.notFound.php Removes baseline entry now handled by guards in Varien_Object.
.phpstan.dist.baselines/empty.notAllowed.php Updates ignore count after reducing one empty() usage.
.phpstan.dist.baselines/class.nameCase.php Removes obsolete baseline file (now fixed in template docblock).
.phpstan.dist.baselines/argument.type.php Removes obsolete baseline entry after guarding array usage in Varien_Object.
.phpstan.dist.baselines/_loader.php Stops loading the removed class.nameCase baseline file.

Comment thread app/code/core/Mage/Catalog/Model/Product/Image.php
@sreichel sreichel requested a review from Hanmac April 29, 2026 00:24
Comment on lines +56 to +61
$params = [];
$params['_current'] = true;
$params['_use_rewrite'] = true;
$params['_query'] = $filterState;
$params['_escape'] = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have $params = [ ... ]?

with [ ... ] being a Multiline Array?

Or better return Mage::getUrl('*/*/*', [ ... ]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be to much work.

Lets keep it simple.

Copy link
Copy Markdown
Contributor

@Hanmac Hanmac Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sreichel i meant to write the params array like this:

$params = [
    '_current'     => true,
    '_use_rewrite' => true,
    '_query'       => $filterState,
    '_escape'      => true,
];

or like this:

return Mage::getUrl('*/*/*', [
    '_current'     => true,
    '_use_rewrite' => true,
    '_query'       => $filterState,
    '_escape'      => true,
]);

i found a rector for similar stuff, but not quite the right thing:
https://getrector.com/rule-detail/inline-array-return-assign-rector

Edit: i asked if there is an extra rule: rectorphp/rector#9747
there isn't one right now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, to automate it, but atm i dont wont to spent much time for writing rules.

(there should be some project/OM-related rules first e.g. change to getDataById())

btw ... we also have CodeSniffer/Beatifier, cs-fixer with additional ECS rules, but no one covers this

@sreichel sreichel changed the title phpstan: variable.implicitArray (1) phpstan: variable.implicitArray May 1, 2026
@sreichel sreichel added this to the 20.19.0 milestone May 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 49 out of 49 changed files in this pull request and generated 3 comments.

Comment on lines 207 to 213
if ($this->getHelper()->isPriceGlobal()) {
$websiteId = 0;
} else {
$websiteId = (int) Mage::app()->getStore($this->getStoreId())->getWebsiteId();
$pricing = [];
$pricing[$websiteId] = [];
}
Comment thread app/code/core/Mage/Catalog/Model/Product/Image.php
sreichel and others added 4 commits May 7, 2026 00:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added Component: Reports Relates to Mage_Reports Component: Customer Relates to Mage_Customer Component: Wishlist Relates to Mage_Wishlist Component: Review Relates to Mage_Review Component: Index Relates to Mage_Index labels May 7, 2026
@sreichel sreichel marked this pull request as draft May 7, 2026 03:37
@github-actions github-actions Bot added Component: CatalogRule Relates to Mage_CatalogRule Component: Payment Relates to Mage_Payment labels May 7, 2026
@sreichel sreichel changed the title phpstan: variable.implicitArray phpstan: docblock-update May 7, 2026
@sreichel sreichel changed the title phpstan: docblock-update phpstan: variable.implicitArray May 7, 2026
@sreichel sreichel marked this pull request as ready for review May 7, 2026 21:25
@sreichel sreichel requested a review from Copilot May 7, 2026 21:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 107 out of 107 changed files in this pull request and generated 83 comments.

Comment on lines +441 to 448
$path = [];

$path = [
self::$_baseMediaPath,
'cache',
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir(),
];
Comment thread app/code/core/Mage/Wishlist/controllers/IndexController.php Outdated
Comment thread app/code/core/Mage/Review/controllers/ProductController.php Outdated
Comment thread app/code/core/Mage/Customer/controllers/AccountController.php Outdated
Comment thread app/code/core/Mage/Checkout/controllers/CartController.php Outdated
Comment thread app/code/core/Mage/PaypalUk/Model/Api/Nvp.php Outdated
Comment thread app/code/core/Mage/PaypalUk/Model/Api/Nvp.php Outdated
Comment thread app/code/core/Mage/Adminhtml/Block/Customer/Edit/Renderer/Region.php Outdated
Comment thread app/code/core/Mage/Payment/Model/Method/Abstract.php
Comment thread app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php
@sreichel sreichel marked this pull request as draft May 7, 2026 21:44
@sreichel sreichel marked this pull request as ready for review May 8, 2026 17:32
sreichel added 2 commits May 22, 2026 17:41
# Conflicts:
#	.phpstan.dist.baselines/notEqual.notAllowed.php
#	app/design/frontend/base/default/template/paypal/payment/redirect.phtml
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Component: Adminhtml Relates to Mage_Adminhtml Component: Bundle Relates to Mage_Bundle Component: Catalog Relates to Mage_Catalog Component: CatalogIndex Relates to Mage_CatalogIndex Component: CatalogRule Relates to Mage_CatalogRule Component: CatalogSearch Relates to Mage_CatalogSearch Component: Checkout Relates to Mage_Checkout Component: Cms Relates to Mage_Cms Component: Core Relates to Mage_Core Component: CurrencySymbol Relates to Mage_CurrencySymbol Component: Customer Relates to Mage_Customer Component: Dataflow Relates to Mage_Dataflow Component: Downloadable Relates to Mage_Downloadable Component: Index Relates to Mage_Index Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* Component: Newsletter Relates to Mage_Newsletter Component: Page Relates to Mage_Page Component: Paygate Relates to Mage_Paygate Component: Payment Relates to Mage_Payment Component: PayPal Relates to Mage_Paypal Component: Reports Relates to Mage_Reports Component: Review Relates to Mage_Review Component: Sales Relates to Mage_Sales Component: Shipping Relates to Mage_Shipping Component: Tag Relates to Mage_Tag Component: Tax Relates to Mage_Tax Component: Usa Relates to Mage_Usa Component: Wishlist Relates to Mage_Wishlist phpstan Template : base Relates to base template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants