PHP code example of dbublik / unused-class-hunter

1. Go to this page and download the library: Download dbublik/unused-class-hunter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dbublik / unused-class-hunter example snippets




declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;
use Symfony\Component\Finder\Finder;

$finder = Finder::create()
    ->in(__DIR__);

return (new Config())
    ->setFinder($finder);



declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;

return (new Config())
    ->withIgnoredClasses(
        \ExampleNamespace\FirstExampleClass::class,
        \ExampleNamespace\SecondExampleClass::class,
    )
    ->withIgnoredAttributes(
        \ExampleNamespace\Attribute\ExampleAttribute::class,
    );



declare(strict_types=1);

namespace ExampleNamespace\Filter;

use DBublik\UnusedClassHunter\Filter\FilterInterface;
use DBublik\UnusedClassHunter\ValueObject\ClassNode;
use DBublik\UnusedClassHunter\ValueObject\ReaderResult;

final readonly class ExampleFilter implements FilterInterface
{
    #[\Override]
    public function isIgnored(ClassNode $class, ReaderResult $reader): bool
    {
        return str_starts_with($class->getName(), 'BadName');
    }
}



declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;

return (new Config())
    ->withFilters(
        new \ExampleNamespace\Filter\ExampleFilter(),
    );



declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;

return (new Config())
    ->withSets(
        symfony: true,
        doctrine: true,
        twig: true,
        phpunit: true,
        codeception: true,
    );



declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;

return (new Config())
    ->setCacheDir(__DIR__ . '/var/cache');



declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;

return (new Config())
    ->withBootstrapFiles(
        __DIR__ . '/example/bootstrap.php',
    );



declare(strict_types=1);

use DBublik\UnusedClassHunter\Config;
use Symfony\Component\Finder\Finder;

return (new Config())
    ->allowStrictMode();
bash
./vendor/bin/unused-class-hunter hunt --config=example/directory/.unused-class-hunter.php