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

bugfix + add module names to helper #2617

Merged
merged 2 commits into from
Oct 1, 2022
Merged

bugfix + add module names to helper #2617

merged 2 commits into from
Oct 1, 2022

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Sep 24, 2022

Description (*)

Read: https://magento.stackexchange.com/questions/46255/ecomdev-phpunit-translation-not-working-with-mocked-helper/46256#46256

  • 1st commit: added module name to all helpers
  • 2nd: fix for Imagine what bugs a module name starting with "Helper" would cause...
<?php
$class = 'Vendor_Helper_Helper_Helper_Test';

$old = substr($class, 0, strpos($class, '_Helper'));
$new = implode('_', array_slice(explode ('_', $class), 0, 2));

var_dump($old);
var_dump($new);

To test you can set a debug breakpoint at Mage_Core_Helper_Abstract::_getModuleName()

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added Component: AdminNotification Relates to Mage_AdminNotification Component: Adminhtml Relates to Mage_Adminhtml Component: Admin Relates to Mage_Admin Component: Api PageRelates to Mage_Api Component: Api2 Relates to Mage_Api2 Component: Authorizenet Relates to Mage_Authorizenet Component: Backup Relates to Mage_Backup Component: Bundle Relates to Mage_Bundle Component: Captcha Relates to Mage_Captcha Component: Catalog Relates to Mage_Catalog Component: CatalogInventory Relates to Mage_CatalogInventory Component: CatalogRule Relates to Mage_CatalogRule Component: CatalogSearch Relates to Mage_CatalogSearch Component: Centinel Relates to Mage_Centinel Component: Checkout Relates to Mage_Checkout Component: Cms Relates to Mage_Cms Component: ConfigurableSwatches Relates to Mage_ConfigurableSwatches Component: Contacts Relates to Mage_Contacts Component: Core Relates to Mage_Core Component: Cron Relates to Mage_Cron Component: CurrencySymbol Relates to Mage_CurrencySymbol Component: Customer Relates to Mage_Customer Component: Dataflow Relates to Mage_Dataflow Component: Directory Relates to Mage_Directory Component: Downloadable Relates to Mage_Downloadable Component: Eav Relates to Mage_Eav labels Sep 24, 2022
@github-actions github-actions bot added Component: Rating Relates to Mage_Rating Component: Reports Relates to Mage_Reports Component: Review Relates to Mage_Review Component: Rss Relates to Mage_Rss Component: Rule Relates to Mage_Rule Component: Sales Relates to Mage_Sales Component: SalesRule Relates to Mage_SalesRule Component: Sendfriend Relates to Mage_Sendfriend Component: Shipping Relates to Mage_Shipping Component: Sitemap Relates to Mage_Sitemap Component: Tag Relates to Mage_Tag Component: Tax Relates to Mage_Tax Component: Uploader Relates to Mage_Uploader Component: Usa Relates to Mage_Usa Component: Weee Relates to Mage_Weee Component: Widget Relates to Mage_Widget Component: Wishlist Relates to Mage_Wishlist labels Sep 24, 2022
@elidrissidev
Copy link
Member

I understand the bug fix, but is it really necessary to set the module name explicitly in every helper?

@fballiano
Copy link
Contributor

I understand the bug fix, but is it really necessary to set the module name explicitly in every helper?

exactly what I was thinking :-(

@sreichel
Copy link
Contributor Author

sreichel commented Sep 26, 2022

I think it is bit faster to get module name from property, instead of retrieve it from classname.

@sreichel
Copy link
Contributor Author

sreichel commented Oct 1, 2022

This method is called on nearly every page for at least ten times (or more often) ...

protected function _getModuleName()
{
    if (!$this->_moduleName) {
        $class = get_class($this);
        $this->_moduleName = substr($class, 0, strpos($class, '_Helper'));
    }
    return $this->_moduleName;
}

Why to not set $_moduleName to skip that useless calls?

@kiatng
Copy link
Contributor

kiatng commented Oct 1, 2022

Why I agree with @sreichel:

3 reasons:

  1. It's available for the child helpers
  2. It's harmless for the children to make use of it
  3. It saves many computing cycle times

@Flyingmana
Copy link
Contributor

Why to not set $_moduleName to skip that useless calls?

because most helper classes should not need to know their module name.
It could be seen as a violation of separation of concerns.
Especially as there was a best practice to only use the translate method from the data helper I think?

It also goes further away on how the Block classes do it, which do it fully dynamically.

anyway, this optimization saves around 0.02ms per request according to my abstracted benchmark, if all of these classes are loaded and used.

@fballiano fballiano merged commit 9608e10 into OpenMage:1.9.4.x Oct 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2022

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  ±0  5 ✔️ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit 9608e10. ± Comparison against base commit 47c8177.

@sreichel sreichel deleted the module-names branch October 1, 2022 22:56
sreichel added a commit that referenced this pull request Oct 17, 2022
* Fixed "should return string but returns false"

* Fixed "should return XYZ but returns false"

* Fixed "should return array but returns null"

* Fixed "should return string but returns null"

* Fixed "should return int but returns null"

* Fixed "should return bool but returns"

* Fixed docs (see comments)

* Fixed "should return array"

* Update app/code/core/Mage/Adminhtml/Block/Widget/Grid/Massaction/Abstract.php

Co-authored-by: Ng Kiat Siong <[email protected]>

* Update app/code/core/Mage/Catalog/Model/Product/Attribute/Tierprice/Api.php

Co-authored-by: Ng Kiat Siong <[email protected]>

* Update app/code/core/Mage/Tag/Model/Resource/Tag.php

Co-authored-by: Ng Kiat Siong <[email protected]>

* Update app/code/core/Mage/Customer/Block/Form/Register.php

Co-authored-by: Ng Kiat Siong <[email protected]>

* Added module names to helper(#2617)

* Get catalog search result collection from engine (#2634)

* Add PHP dependencies security check workflow (#2639)

* [security-workflow] Fixed cron syntax (#2640)

* Added OpenMage Contributors Copyright (#2295)

* Added ddev snippets to docs (#2575)

* Improve dev/openmage/install.sh script for newer versions of Docker - no longer requires separate compose.

* Only run workflows when relevant files change (#2641)

* Add back notification popup severity icons URL (#2633)

* Reduce reprocessed jpeg file size by defaulting quality to 85% (#2629)

* Fixed issue #475.

* Removed <frontend_type>text</frontend_type> as it is the default.

* Fixed bug on users not able to modify image quality in backend if deprecated config exists.

* Fixed bug on incorrect check if image quality was not set in backend.

* Improved note in system.xml.

* Prevented editing of a non-editable order (#2632)

* Fix dev/openmage/install.sh script setting permissions on var directory.

* Allowed automatic full invoice from API (#2393)

* Add check if array key isset before using it (#2649)

* Fixed phpstan-baseline.neon

* Fixed phpstan-baseline.neon (updated dev tools)

* Revert "Fixed phpstan-baseline.neon"

This reverts commit 3c82e76.

* Fixed getRegion()

Co-authored-by: Ng Kiat Siong <[email protected]>
Co-authored-by: Mohamed ELIDRISSI <[email protected]>
Co-authored-by: Justin Beaty <[email protected]>
Co-authored-by: Colin Mollenhour <[email protected]>
Co-authored-by: luigifab <[email protected]>
Co-authored-by: Przemysław Piotrowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component: Admin Relates to Mage_Admin Component: Adminhtml Relates to Mage_Adminhtml Component: AdminNotification Relates to Mage_AdminNotification Component: Api PageRelates to Mage_Api Component: Api2 Relates to Mage_Api2 Component: Authorizenet Relates to Mage_Authorizenet Component: Backup Relates to Mage_Backup Component: Bundle Relates to Mage_Bundle Component: Captcha Relates to Mage_Captcha Component: Catalog Relates to Mage_Catalog Component: CatalogInventory Relates to Mage_CatalogInventory Component: CatalogRule Relates to Mage_CatalogRule Component: CatalogSearch Relates to Mage_CatalogSearch Component: Centinel Relates to Mage_Centinel Component: Checkout Relates to Mage_Checkout Component: Cms Relates to Mage_Cms Component: ConfigurableSwatches Relates to Mage_ConfigurableSwatches Component: Contacts Relates to Mage_Contacts Component: Core Relates to Mage_Core Component: Cron Relates to Mage_Cron Component: CurrencySymbol Relates to Mage_CurrencySymbol Component: Customer Relates to Mage_Customer Component: Dataflow Relates to Mage_Dataflow Component: Directory Relates to Mage_Directory Component: Downloadable Relates to Mage_Downloadable Component: Eav Relates to Mage_Eav Component: GoogleAnalytics Relates to Mage_GoogleAnalytics Component: ImportExport Relates to Mage_ImportExport Component: Index Relates to Mage_Index Component: Install Relates to Mage_Install Component: Log Relates to Mage_Log Component: Media Relates to Mage_Media Component: Oauth Relates to Mage_Oauth Component: Page Relates to Mage_Page Component: PageCache Relates to Mage_PageCache Component: Paygate Relates to Mage_Paygate Component: Payment Relates to Mage_Payment Component: PayPal Relates to Mage_Paypal Component: PaypalUk Relates to Mage_PaypalUk Component: Poll Relates to Mage_Poll Component: ProductAlert Relates to Mage_ProductAlert Component: Rating Relates to Mage_Rating Component: Reports Relates to Mage_Reports Component: Review Relates to Mage_Review Component: Rss Relates to Mage_Rss Component: Rule Relates to Mage_Rule Component: Sales Relates to Mage_Sales Component: SalesRule Relates to Mage_SalesRule Component: Sendfriend Relates to Mage_Sendfriend Component: Shipping Relates to Mage_Shipping Component: Sitemap Relates to Mage_Sitemap Component: Tag Relates to Mage_Tag Component: Tax Relates to Mage_Tax Component: Uploader Relates to Mage_Uploader Component: Usa Relates to Mage_Usa Component: Weee Relates to Mage_Weee Component: Widget Relates to Mage_Widget Component: Wishlist Relates to Mage_Wishlist enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants