2017 © Pedro Peláez
 

library reflection

Reflection library to do Static Analysis for PHP Projects

image

phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

  • Wednesday, June 20, 2018
  • by mvriel
  • Repository
  • 15 Watchers
  • 56 Stars
  • 2,081,140 Installations
  • PHP
  • 70 Dependents
  • 11 Suggesters
  • 35 Forks
  • 7 Open issues
  • 27 Versions
  • 4 % Grown

The README.md

License: MIT Qa workflow Coveralls Coverage Scrutinizer Code Coverage Scrutinizer Code Quality Stable Version Unstable Version, (*1)

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., (*2)

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:, (*3)

  • 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:, (*4)

composer require phpdocumentor/reflection:~5.0

After the installation is complete no further configuration is necessary and you can immediately start using it., (*5)

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., (*6)

An easy way to do this is by including the composer autoloader as shown here:, (*7)

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., (*8)

$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., (*9)

$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., (*10)

See the example script for a detailed and commented example, (*11)

The Versions

20/06 2018

dev-develop

dev-develop http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

19/06 2018

4.0.0-alpha2

4.0.0.0-alpha2 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

15/06 2018

4.0.0-alpha1

4.0.0.0-alpha1 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

20/12 2017

dev-master

9999999-dev http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

23/05 2017

dev-feature/bump-phpparser

dev-feature/bump-phpparser http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

21/05 2016

3.0.1

3.0.1.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

19/02 2016

3.0.0

3.0.0.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

05/12 2015

2.0.0-alpha2

2.0.0.0-alpha2 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

09/08 2015

2.0.0-alpha1

2.0.0.0-alpha1 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

14/11 2014

1.0.7

1.0.7.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

06/06 2014

1.0.6

1.0.6.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

28/03 2014

1.0.5

1.0.5.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

08/03 2014

1.0.4

1.0.4.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

16/02 2014

1.0.3

1.0.3.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

29/11 2013

1.0.2

1.0.2.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

16/09 2013

1.0.1

1.0.1.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

01/08 2013

1.0.0

1.0.0.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

15/07 2013

0.1.9

0.1.9.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

15/07 2013

0.1.8

0.1.8.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

30/06 2013

0.1.7

0.1.7.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

23/06 2013

0.1.6

0.1.6.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

06/05 2013

0.1.5

0.1.5.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

25/04 2013

0.1.4

0.1.4.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

22/12 2012

0.1.3

0.1.3.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

22/12 2012

0.1.2

0.1.2.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

02/12 2012

0.1.1

0.1.1.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis

29/11 2012

0.1.0

0.1.0.0 http://www.phpdoc.org

Reflection library to do Static Analysis for PHP Projects

  Sources   Download

MIT

The Requires

 

The Development Requires

phpdoc phpdocumentor reflection static analysis