magento-coding-standard icon indicating copy to clipboard operation
magento-coding-standard copied to clipboard

Enforce import of global functions or using FQN calls

Open ilnytskyi opened this issue 1 year ago • 1 comments

Rule

Reason

I used code example from here https://tideways.com/profiler/blog/compiler-optimized-php-functions https://veewee.github.io/blog/optimizing-php-performance-by-fq-function-calls/

If we import or use FQN call for the global function php produces more optimized code. Also visible via profilers: SPX: Selection_578

Same effect with blackfire:

  1. Without import Selection_575

  2. with import Selection_576

Although the optimization might not be that significant for whole codebase it also helps to specify dependency via use statement. It also might improve performance of some loops when checks like is_array, ltrim, preg_match etc. are used as PHP would no more execute extra opcode INIT_NS_FCALL_BY_NAME

Also by import or FQN core function for setup:di:compile code we might reduce magento compilation time by a few seconds.

Selection_577

Implementation

Can be taken from here: https://github.com/slevomat/coding-standard/blob/master/doc/namespaces.md#slevomatcodingstandardnamespacesreferenceusednamesonly-

    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
        <properties>
            <property name="allowFallbackGlobalFunctions" value="0" />
            <property name="allowFallbackGlobalConstants" value="0" />
        </properties>
    </rule>

ilnytskyi avatar Aug 08 '23 11:08 ilnytskyi

Hi @ilnytskyi. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information. Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.

m2-assistant[bot] avatar Aug 08 '23 11:08 m2-assistant[bot]