Directory Filter Class PHP
I would probably refactor these things:

Return Type Declaration

You're using argument type declaration, which is a good thing. You can even take it one step further and add a return type declaration as well:

: array


This will force the function to return an array. So the final definition will look like this:

public function filter(string $path, string $extension) : array {


Return Values

I would return an array in any case. If no matches where found this array would simply be empty:

return $results;


Check-ups

I would test a few things:


Is the directory available?
Is the directory readable?
Is the extension empty?


If any of these test fail, throw an Exception with a message describing the error. So, other parts have to worry about the validity of the arguments.

An example test for readability of an existing directory:

if (!is_readable($path)) {
    $message = 'The directory "' . $path . '" is not readble.';
    throw new \Exception($message);
}


Case Sensitivity

Currently your code will fail if you look for PDF but the file is called example.pdf. Use strtolower to get rid of this problem:

$extension = strtolower($extension);
$pathinfoExtension = strtolower(pathinfo($fileInfo, PATHINFO_EXTENSION));


FilesystemIterator

Currently you're using glob to iterate over the files. Alternatively use a FilesystemIterator. It has the advantages1:


increases readability
it skips dot files .|.. (as opposed to an DirectoryIterator)
it's extensible


Result

The final result would look like this:2

class DirectoryFilter {
    public function filter(string $path, string $extension) : ?array {
        $results = [];

        if (!is_dir($path)) {
            $message = 'The directory "' . $path . '" doesn\'t exist.';
            throw new \Exception($message);
        }

        if (!is_readable($path)) {
            $message = 'The directory "' . $path . '" is not readble.';
            throw new \Exception($message);
        }

        if (!$extension) {
            $message = 'An empty string is not a valid extension.';
            throw new \Exception($message);
        }

        $extension = strtolower($extension);

        $iterator = new FilesystemIterator($path);

        foreach ($iterator as $fileInfo) {
            $pathinfoExtension = strtolower(pathinfo($fileInfo, PATHINFO_EXTENSION));

            if ($extension == $pathinfoExtension) {
                $results[] = $fileInfo-&gt;getFilename();
            }
        }

        return $results;
    }
}

var_dump( (new DirectoryFilter())-&gt;filter(__DIR__, 'php') );


Further Thoughts

To reduce the amount of false-positives, like files that have a wrong extension, you should probably use some sort of MIME-type guesser. A good one, based on the PECL-extension, is the one included in the Symfony framework. The guesser uses two components: FileBinaryMimeTypeGuesser and FileinfoMimeTypeGuesser. The Symfony source code is a good starting point to go more into detail:

http-foundation / File / MimeType / MimeTypeGuesser.php



1 You can find more details in the answers of this question "What exactly are the benefits of using a PHP 5 DirectoryIterator over PHP 4 “opendir/readdir/closedir”?".

2 I removed all comments/PHPDoc to keep the answer compact.