mcmatters/fqn-checker

v3.0.2 2024-08-17 16:17 UTC

This package is auto-updated.

Last update: 2024-10-17 16:53:28 UTC


README

Checks your php-code for the presence of un-imported functions and gives you information about where they are located.

Installation

composer require mcmatters/fqn-checker

Usage

<?php

declare(strict_types=1);

use McMatters\FqnChecker\FqnChecker;

require 'vendor/autoload.php';

$checker = new FqnChecker(file_get_contents(__DIR__.'/Wrong.php'));

print_r($checker->getNotImported());
print_r($checker->getImported());

Listing of Wrong.php

<?php

declare(strict_types=1);

namespace Acme;

use function ucfirst;

class Wrong
{
    public function testArray()
    {
        return array_filter([], null);
    }
    
    public function testString()
    {
        return ucfirst('hello');
    }
}

Result

[
    'constants' => [
        'Acme' => [
            'null' => [
                13,
            ],
        ],
    ],
    'functions' => [
        'Acme' => [
            'array_filter' => [
                13,
            ],
        ],
    ],
]

[
    'constants' => [],
    'functions' = [
        'Acme' => [
            'ucfirst' => true,
        ],
    ],
]