You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this fixer, an import such as use PDO; would be removed and all references to PDO in that file would be replaced with \PDO. Root imports are those which do not contain a backslash (\) character, excluding the first. The following are root imports:
PDO
\PDO
The following are not root imports:
Foo\Bar.
The rationale behind this fixer is to make it clear, when reading the code, whether the built-in implementation is used or a custom implementation. That is, when code follows the no root imports style, we can be confident that code occurences of \PDO refer to the standard implementation, and PDO refers to a custom implementation, because PHP built-in classes are not namespaced.
The text was updated successfully, but these errors were encountered:
This PR was squashed before being merged into the 2.16-dev branch (closes#4355).
Discussion
----------
GlobalNamespaceImportFixer - Introduction
* closes#1309
* refs #2166 (this pr does not differientiate between native/non-native elements, only between global/non-global)
* closes#2739
* closes#4347
---
The fixer can import global classes/functions/constants:
Input:
```php
<?php
namespace Foo;
if (\count($x)) {
/** @var \DateTimeImmutable $d */
$d = new \DateTimeImmutable();
$p = \M_PI;
}
```
Output:
```php
<?php
namespace Foo;
use DateTimeImmutable;
use function count;
use const M_PI;
if (count($x)) {
/** @var DateTimeImmutable $d */
$d = new DateTimeImmutable();
$p = M_PI;
}
```
Global functions/constants without leading `\` are not imported. The slash can be added by `Native(Constant|Function)InvocationFixer` before.
The fixer can also do the reverse fix, adding the backslash to imported global classes/functions/constants. But the fixer does not remove the imports, this can be done by `NoUnusedImportsFixer`.
Commits
-------
41fe1f4 GlobalNamespaceImportFixer - Introduction
With this fixer, an import such as
use PDO;
would be removed and all references toPDO
in that file would be replaced with\PDO
. Root imports are those which do not contain a backslash (\
) character, excluding the first. The following are root imports:PDO
\PDO
The following are not root imports:
Foo\Bar
.The rationale behind this fixer is to make it clear, when reading the code, whether the built-in implementation is used or a custom implementation. That is, when code follows the no root imports style, we can be confident that code occurences of
\PDO
refer to the standard implementation, andPDO
refers to a custom implementation, because PHP built-in classes are not namespaced.The text was updated successfully, but these errors were encountered: