PHPCS: conform to SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3567950. -->
Reported by: [wim leers](https://www.drupal.org/user/99777)
Related to !477
>>>
<h3 id="overview">Overview</h3>
<p>Inspired by <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3567931" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3567931</a></span>, I stumbled upon <a href="https://github.com/mglaman/phpstan-drupal/pull/718">https://github.com/mglaman/phpstan-drupal/pull/718</a>, which is not quite the same, but nicely complementary.</p>
<p>Why?</p>
<blockquote><p>Modern php has several optimizations it can apply to global functions at compile-time, but only when they are fully-qualified.</p></blockquote>
<p>— <a href="https://github.com/mglaman/phpstan-drupal/pull/718#:~:text=Modern%20php%20has%20several%20optimizations%20it%20can%20apply%20to%20global%20functions%20at%20compile%2Dtime%2C%20but%20only%20when%20they%20are%20fully%2Dqualified">https://github.com/mglaman/phpstan-drupal/pull/718#:~:text=Modern%20php%20has%20several%20optimizations%20it%20can%20apply%20to%20global%20functions%20at%20compile%2Dtime%2C%20but%20only%20when%20they%20are%20fully%2Dqualified</a>.</p>
<p>That's literally what @larowlan has been doing in every of his MRs for the past year. Which means that some parts of Canvas do this, others don't. Some reviews point it out, others don't, yet others are wondering "why". <strong>@catch is also proposing this for Drupal core: <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-13"><a href="https://www.drupal.org/project/drupal/issues/3346987" title="Status: Needs work">#3346987: Call PHP native functions fully qualified (like \array_key_exists())</a></span> — the list of benefiting PHP functions can be found at <a href="https://github.com/php/php-src/blob/PHP-8.4.18/Zend/zend_compile.c#L4962">https://github.com/php/php-src/blob/PHP-8.4.18/Zend/zend_compile.c#L4962</a>.</strong></p>
<p>This is avoidable noise in the review process: automated feedback increases velocity.</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<ol>
<li>Conform to <code>SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions</code>.</li>
<li>Do not disrupt all existing MRs massively. Start with just 2 commonly used functions: <code>\assert()</code> and <code>\sprintf()</code>.</li>
<li>Create Novice follow-up issues to gradually apply this to ALL global functions. See <a href="https://www.drupal.org/project/canvas/issues/3567950#comment-16415093">#5</a> for a two-step guide for novices of how to do this 😊</li>
</ol>
<p>(FYI <code>SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants</code> might be worth doing too. Also follow-up material.)</p>
<h3 id="ui-changes">User interface changes</h3>
<p>None.</p>
issue