PHPackages                             jerowork/file-class-reflector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jerowork/file-class-reflector

Abandoned → [roave/better-reflection](/?search=roave%2Fbetter-reflection)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

jerowork/file-class-reflector
=============================

Get fully-qualified class names based on directory and file paths.

0.3.0(3y ago)32.1k[5 PRs](https://github.com/jerowork/file-class-reflector/pulls)1MITPHPPHP ^8.1CI passing

Since Aug 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jerowork/file-class-reflector)[ Packagist](https://packagist.org/packages/jerowork/file-class-reflector)[ RSS](/packages/jerowork-file-class-reflector/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (4)Dependencies (8)Versions (10)Used By (1)

file-class-reflector
====================

[](#file-class-reflector)

[![Build Status](https://camo.githubusercontent.com/8295a86e55d192e5acd6a1b4f00dd6142aff5e1194e9bd2257615ffdef7b0abb/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246616374696f6e732d62616467652e6174726f782e6465762532466a65726f776f726b25324666696c652d636c6173732d7265666c6563746f7225324662616467652533467265662533446d61696e267374796c653d666c61742d737175617265)](https://github.com/jerowork/file-class-reflector/actions)[![Coverage Status](https://camo.githubusercontent.com/18cbe09d52370f4075835f3b4327f70e3e3b55044d574866949b78a257f7424c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6a65726f776f726b2f66696c652d636c6173732d7265666c6563746f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/jerowork/file-class-reflector/code-structure)[![Quality Score](https://camo.githubusercontent.com/e7ee3b6bb99ae2605554d0d3d77587ec3193ad785a62959b293d57bfcb31c857/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6a65726f776f726b2f66696c652d636c6173732d7265666c6563746f722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/jerowork/file-class-reflector)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/e3392c4349c6b38c3600ada4ab05aa0311f294a1955c25a72daab8733b222cb9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a65726f776f726b2f66696c652d636c6173732d7265666c6563746f722e7376673f7374796c653d666c61742d73717561726526696e636c7564655f70726572656c6561736573)](https://packagist.org/packages/jerowork/file-class-reflector)[![PHP Version](https://camo.githubusercontent.com/6f61c16385e121f1009c477296e9a88d9352813581b8b66a97fed5237b222457/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://www.php.net)

Get fully-qualified classnames based on directory and file paths.

Installation
------------

[](#installation)

Install via [Composer](https://getcomposer.org):

```
composer require jerowork/file-class-reflector
```

Usage
-----

[](#usage)

The `ClassReflector` makes use of the [nikic/php-parser](https://github.com/nikic/php-parser)package to retrieve the fully-qualified class name from a file.

Basic usage:

```
use Jerowork\FileClassReflector\NikicParser\NikicParserClassReflectorFactory;

// Create a new ClassReflector instance directly via a static factory method
$reflector = NikicParserClassReflectorFactory::createInstance();

// Add necessary directories and/or files and reflect
$reflector
    ->addDirectory(__DIR__ . '/some/directory')
    ->reflect();

// Get all \ReflectionClass found in files
$classes = $reflector->getClasses();
```

The `ClassReflectorFactory` can also be instantiated via the constructor. In this way the factory can be added to a DI container.

```
use Jerowork\FileClassReflector\FileFinder\RegexIterator\RegexIteratorFileFinder;
use Jerowork\FileClassReflector\NikicParser\NikicParserClassReflectorFactory;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;

// Create the factory
$factory = new NikicParserClassReflectorFactory(
    new RegexIteratorFileFinder(),
    (new ParserFactory())->create(ParserFactory::PREFER_PHP7),
    new NodeTraverser(),
);

// Create a new ClassReflector instance
$reflector = $factory->create();

// ...
```

### DI service definition

[](#di-service-definition)

As a good practice we should always 'program to interfaces, not implementations', you should add this to your DI container.

PSR-11 Container example:

```
use Jerowork\FileClassReflector\ClassReflectorFactory;
use Jerowork\FileClassReflector\FileFinder\FileFinder;
use Jerowork\FileClassReflector\FileFinder\RegexIterator\RegexIteratorFileFinder;
use Jerowork\FileClassReflector\NikicParser\NikicParserClassReflectorFactory;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use Psr\Container\ContainerInterface;

return [
    ClassReflectorFactory::class => static function (ContainerInterface $container): ClassReflectorFactory {
        return new NikicParserClassReflectorFactory(
            new RegexIteratorFileFinder(),
            (new ParserFactory())->create(ParserFactory::PREFER_PHP7),
            new NodeTraverser(),
        );
    },

    FileFinder::class => static fn (): FileFinder => new RegexIteratorFileFinder(),
];
```

Symfony YAML-file example:

```
services:
  _defaults:
    autowire: true
    autoconfigure: true

  Jerowork\FileClassReflector\ClassReflectorFactory:
    class: Jerowork\FileClassReflector\NikicParser\NikicParserClassReflectorFactory

  Jerowork\FileClassReflector\FileFinder\FileFinder:
    class: Jerowork\FileClassReflector\FileFinder\RegexIterator\RegexIteratorFileFinder

  PhpParser\ParserFactory: ~

  PhpParser\Parser:
    factory: ['@PhpParser\ParserFactory', 'create']
    arguments: [1] # 1 = ParserFactory::PREFER_PHP7

  PhpParser\NodeTraverser: ~
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~181 days

Total

4

Last Release

1170d ago

PHP version history (2 changes)0.1.0PHP ^8.0

0.2.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/f5fda898ea5700962c462ce21749b844fa13a9b239bfb52c95926a90d07c0ef5?d=identicon)[jerowork](/maintainers/jerowork)

---

Top Contributors

[![jerowork](https://avatars.githubusercontent.com/u/4119451?v=4)](https://github.com/jerowork "jerowork (42 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (23 commits)")

---

Tags

class-namefqcnreflectionreflectionphp8fqcnclass-name

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jerowork-file-class-reflector/health.svg)

```
[![Health](https://phpackages.com/badges/jerowork-file-class-reflector/health.svg)](https://phpackages.com/packages/jerowork-file-class-reflector)
```

###  Alternatives

[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

9.1k706.8M26](/packages/phpdocumentor-reflection-common)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12521.4M108](/packages/phpdocumentor-reflection)[php-di/phpdoc-reader

PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)

7431.6M54](/packages/php-di-phpdoc-reader)[minime/annotations

The KISS PHP annotations library

229378.6k36](/packages/minime-annotations)[butschster/cron-expression-generator

Cron expression generator

511.4M2](/packages/butschster-cron-expression-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
