Duplicate Imports
ID |
php.duplicate_imports |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Php |
Tags |
code_smell, unused-code |
Description
Reports a use statement that imports a symbol already imported by an earlier statement in
the same file. The first occurrence is kept; every later statement importing the same symbol
is flagged.
Rationale
Duplicate imports are harmless to the runtime but clutter the import block and usually result
from a careless merge or copy-paste. Imports are compared by kind, so a class import, a
use function and a use const of the same name do not collide. An aliased import is keyed
on its alias: importing the same target under two different aliases is legitimate, whereas
repeating the same alias is the duplicate.
<?php
use App\Model\User; // OK - first import
use App\Service\Mailer as M; // OK - first aliased import
use App\Model\User; // FLAW - duplicate of App\Model\User
use App\Service\Mailer as N; // OK - same target, different alias