• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reflection library to do Static Analysis for PHP Projects

License: MIT Qa workflow Coveralls Coverage Scrutinizer Code Coverage Scrutinizer Code Quality Stable Version Unstable Version

Reflection

Using this library it is possible to statically reflect one or more files and create an object graph representing your application's structure, including accompanying in-source documentation using DocBlocks.

The information that this library provides is similar to what the (built-in) Reflection extension of PHP provides; there are however several advantages to using this library:

  • Due to its Static nature it does not execute procedural code in your reflected files where Dynamic Reflection does.
  • Because the none of the code is interpreted by PHP (and executed) Static Reflection uses less memory.
  • Can reflect complete files
  • Can reflect a whole project by reflecting multiple files.
  • Reflects the contents of a DocBlock instead of just mentioning there is one.
  • Is capable of analyzing code written for any PHP version (starting at 5.2) up to and including your installed PHP version.

Features

  • [Creates an object graph] containing the structure of your application much like a site map shows the structure of a website.
  • Can read and interpret code of any PHP version starting with 5.2 up to and including your currently installed version of PHP.
  • Due it's clean interface it can be in any application without a complex setup.

Installation

In order to inspect a codebase you need to tell composer to include the phpdocumentor/reflection package. This can easily be done using the following command in your command line terminal:

composer require phpdocumentor/reflection:~5.0

After the installation is complete no further configuration is necessary and you can immediately start using it.

Basic Usage

This Reflection library uses PSR-4 and it is recommended to use a PSR-4 compatible autoloader to load all the files containing the classes for this library.

An easy way to do this is by including the composer autoloader as shown here:

include 'vendor/autoload.php';

Once that is done you can use the createInstance() method of the \phpDocumentor\Reflection\Php\ProjectFactory class to instantiate a new project factory and pre-configure it with sensible defaults. Optional you can specify the parser version that shall be used as an argument of createInstance(). By default the php7 parser is prefered. And php5 is used as a fallback. See the documentation of phpparser for more info.

$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();

At this point we are ready to analyze your complete project or just one file at the time. Just pass an array of file paths to the create method of the project factory.

$projectFiles = [new \phpDocumentor\Reflection\File\LocalFile('tests/example.file.php')];
$project = $projectFactory->create('My Project', $projectFiles);

When the process is ready a new object of type phpDocumentor\Reflection\Php\Project will be returned that contains a complete hierarchy of all files with their classes, traits and interfaces (and everything in there), but also all namespaces and packages as a hierarchical tree.

See the example script for a detailed and commented example

More Repositories

1

ReflectionDocBlock

PHP
9,279
star
2

TypeResolver

A PSR-5 based resolver of Class names, Types and Structural Element Names
PHP
9,090
star
3

ReflectionCommon

PHP
8,983
star
4

phpDocumentor

Documentation Generator for PHP
PHP
4,035
star
5

GraphViz

PHP
91
star
6

FlyFinder

PHP
29
star
7

Parallel

A separate module to introduce parallelization into a project. Can be used in any project.
17
star
8

template.responsive

ABANDONED: This template is merged into phpDocumentor2 itself
JavaScript
17
star
9

Scrybe

[ABANDONED] This package will be included in phpDocumentor 3
PHP
16
star
10

guides

Experimental guides library to parse documentation
PHP
15
star
11

Fileset

A fileset component that manages the collection of files using directories and filenames
PHP
11
star
12

template.new_black

ABANDONED: This template is merged into phpDocumentor2 itself
CSS
6
star
13

phpdoc.org

The source of the phpDocumentor website
Twig
6
star
14

shim

phpDocumentor phar as composer package
PHP
6
star
15

plugin-twig

[DEPRECATED] A plugin that adds Twig capabilities to phpDocumentor2
PHP
6
star
16

template.abstract

ABANDONED: This template is merged into phpDocumentor2 itself
XSLT
5
star
17

UnifiedAssetInstaller

ABANDONED
PHP
4
star
18

template.zend

ABANDONED: This template is merged into phpDocumentor2 itself
CSS
3
star
19

template.old_ocean

ABANDONED: This template is merged into phpDocumentor2 itself
JavaScript
3
star
20

phar-ga

Phar building github action
Shell
2
star
21

template.checkstyle

ABANDONED: This template is merged into phpDocumentor2 itself
2
star
22

template.clean

ABANDONED: This template is merged into phpDocumentor2 itself
JavaScript
2
star
23

phpstan-ga

phpstan github action for phpdocumentor
Dockerfile
1
star
24

pdf.old_ocean

Experimental PDF generation template
1
star
25

guides-restructured-text

Guides library to parse ReStructured text into an AST
PHP
1
star
26

guides-markdown

Guides library to parse Markdown into Guides AST
PHP
1
star
27

template.responsive-twig

ABANDONED: This template is merged into phpDocumentor2 itself
1
star