PHPackages                             seretos/php-file-parser - 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. seretos/php-file-parser

ActiveLibrary

seretos/php-file-parser
=======================

parse a php file and get the used namespaces

v0.3.1(9y ago)029MITPHPPHP &gt;=5.3.0

Since Oct 30Pushed 9y ago2 watchersCompare

[ Source](https://github.com/Seretos/PHPFileParser)[ Packagist](https://packagist.org/packages/seretos/php-file-parser)[ RSS](/packages/seretos-php-file-parser/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (2)Versions (15)Used By (0)

PHPFileParser
=============

[](#phpfileparser)

This library can be used to parse an PHP file and response all used namespaces in this file.

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

[](#installation)

Add this repository to your composer.json as below:

```
{
    "require-dev": {
        ...
        "seretos/php-file-parser": "0.3.x-dev"
    }
}
```

Usage
-----

[](#usage)

PHPPackageParser:

```
use PHPFileParser\PHPPackageParser;

$parser = new PHPPackageParser();

$classMap = ['my\\FullNamespace\\class' => __DIR__.'/path/to/file.php'];

$calls = $parser->parse($classMap);     //returns all used classes which not part of the classMap

foreach($calls as $class => $source){
    print_r('class ' .$class . ' is used in ' . $source);
}
```

PHPFileParser:

```
use Symfony\Component\Finder\Finder;
use PHPFileParser\PHPFileParser;
use PHPFileParser\Parser\NewParser;
use PHPFileParser\Parser\StaticParser;
use PHPFileParser\Parser\ExtendsParser;
use PHPFileParser\Parser\ImplementsParser;
use PHPFileParser\Parser\CatchParser;
use PHPFileParser\Parser\ArgumentParser;
use PHPFileParser\Parser\AnnotationParser;

$finder = new Finder();
$finder->files()->in(__DIR__);

foreach($finder as $file){
    $parser = new PHPFileParser($file);

    $parser->addParser(new NewParser());        // parse new operations like $var = new MyClass();
    $parser->addParser(new StaticParser());     // parse static operations like MyClass::class;
    $parser->addParser(new ExtendsParser());    // parse extended base classes
    $parser->addParser(new ImplementsParser()); // parse implemented class interfaces
    $parser->addParser(new CatchParser());      // parse the catched exception classes
    $parser->addParser(new ArgumentParser());   // parse the type hints in function arguments
    $parser->addParser(new AnnotationParser()); // parse the annotation type declarations
    $parser->addParser(new InstanceOfParser()); // parse instanceof operations

    $parser->parse();               // parse the php file
    $parser->getCalls();            // get an array of used classes (with fully qualified namespace)
    $parser->getNamespaces();       // returns an array with namespaces. every item has an 'use' and an 'alias' key
    $parser->getAllUsedNamespaces() // get all used classes (getCalls and getAnnotationCalls) and remove all doubles
    $parser->getNamespace();        // returns null or the current namespace
}
```

###  Health Score

25

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

13

Last Release

3429d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1956f0019585e067a8c17676304b6f9442aa9c495c81d4294f5805940ed3fd12?d=identicon)[Seretos](/maintainers/Seretos)

---

Top Contributors

[![Seretos](https://avatars.githubusercontent.com/u/18718900?v=4)](https://github.com/Seretos "Seretos (21 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/seretos-php-file-parser/health.svg)

```
[![Health](https://phpackages.com/badges/seretos-php-file-parser/health.svg)](https://phpackages.com/packages/seretos-php-file-parser)
```

###  Alternatives

[php-mcp/server

PHP SDK for building Model Context Protocol (MCP) servers - Create MCP tools, resources, and prompts

822230.3k20](/packages/php-mcp-server)[darkghosthunter/preloader

Preloader helper to create a PHP-ready preload script from Opcache.

433657.4k1](/packages/darkghosthunter-preloader)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[wpstarter/framework

The WpStarter Framework - Laravel Framework for WordPress

1610.0k4](/packages/wpstarter-framework)

PHPackages © 2026

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