Unused use statement rule

Author: alexwhitmanCreated Dec 3, 2015Updated Mar 9, 2026
LabelsType: enhancement

Is there a rule to detect unused use statements? For example:

php
<?php

use Foo\Bar;
use Foo\Baz; // This should be detected as unused

class MyClass
{
    public function doSomething(Bar $bar)
    {
        // .....
    }
}

PHP-CS-Fixer has an unused_use fixer but I'd prefer to use the one tool if possible.

Source: squizlabs/PHP_CodeSniffer