explaingit

phpdocumentor/typeresolver

9,184PHPAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A PHP library that parses type expressions from documentation comments into structured objects, making it easy to build tools that inspect, analyze, or document PHP code.

Mindmap

mindmap
  root((typeresolver))
    What it does
      Parses DocBlock types
      Resolves class names
      Structured output
    Resolvers
      TypeResolver
      FqsenResolver
    Use cases
      Doc generators
      Static analysis
      Code reflection
    Audience
      PHP tool builders
      Framework devs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a PHP documentation generator that reads DocBlock type annotations and converts them into structured data objects.

USE CASE 2

Write a static analysis tool that expands partial class name aliases to their fully qualified names using each file's namespace and use statements.

USE CASE 3

Parse union types and array type expressions from PHP DocBlocks into typed objects for code inspection or IDE tooling.

USE CASE 4

Create a code reflection utility that understands PHP type hints including primitives, class references, and combined types.

Tech stack

PHPComposer

Getting it running

Difficulty · easy Time to first run · 30min

Installed via Composer, requires understanding of PHP DocBlock type syntax to use effectively.

Use freely for any purpose including commercial, as long as you keep the copyright notice.

In plain English

TypeResolver is a PHP library from the phpDocumentor project that reads type expressions found in code documentation comments and turns them into structured objects your code can work with. In PHP, developers write comments above functions and properties (called DocBlocks) to describe what types of values they accept or return, using notation like string|integer or MyClass[]. This library parses those expressions into objects that represent each type, making it easier to build tools that inspect or document PHP code. The library provides two resolvers. The TypeResolver handles PHP type expressions: primitives like string or void, arrays like string[], combined types like string|integer, and references to class names. The FqsenResolver handles references to specific named elements within code: classes, interfaces, traits, functions, constants, properties, and methods. FQSEN stands for Fully Qualified Structural Element Name, which is essentially the full path to a piece of code including its namespace. The most useful capability of both resolvers is expanding partial names into fully qualified ones. When PHP code has a use statement at the top importing a class under a short alias, a type expression might only mention the short name. This library can take the surrounding context (the namespace and the imports in effect at that point in the file) into account and expand the short name to the full class path. You provide this context either manually or by pointing the library at the source file. The package is part of the phpDocumentor ecosystem and is designed to be a low-level building block for documentation generators, static analysis tools, and code reflection utilities. It is installed via Composer and is licensed under the MIT license.

Copy-paste prompts

Prompt 1
Using phpdocumentor/typeresolver, show me how to parse the DocBlock type expression 'string|MyClass[]' into a structured PHP object I can inspect.
Prompt 2
I have a PHP file with 'use App\Models\User' at the top. Show me how TypeResolver expands the short name 'User' in a DocBlock to its fully qualified class name.
Prompt 3
Help me build a PHP script that reads all DocBlocks in a PHP class file and extracts the return type of each method using TypeResolver.
Prompt 4
What is the difference between TypeResolver and FqsenResolver in this library, and when should I use each one?
Open on GitHub → Explain another repo

← phpdocumentor on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.