mcmatters/fqn-checker

v3.0.1 2024-02-29 07:24 UTC

This package is auto-updated.

Last update: 2024-03-29 07:25:57 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,
        ],
    ],
]