PHP Classes

Simple PHP Code Parser: Parse PHP code to extract its structure

Recommend this page to a friend!
  Info   View files View files (50)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-05-14 (6 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 63 This week: 63All time: 9,672 This week: 7Up
Version License PHP version Categories
simple-php-code-pars 0.0.0MIT/X Consortium ...7PHP 5, Parsers
Collaborate with this project Author
Description

This package can parse PHP code to extract its structure.

It can take a string or a file with PHP code and parses it to obtain is structure elements. Currently it can extract the code:

- Classes
- Class functions
- Class variables
- Class constants
- Global functions
- Function parameters

  Performance   Level  
Innovation award
Innovation award
Nominee: 9x

Winner: 1x

 

Details

Build Status Coverage Status Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon

? Simple PHP Code Parser

You can simply scan a string, a file or a full directory and you can see a simple data structure from your php code. - Classes (PHPClass) - Class Properties (PHPProperties) - Class Constants (PHPConst) - Class Methods (PHPMethod) - Functions (PHPFunction) - Function / Method Parameter (PHPParameter)

This code is forked from JetBrains/phpstorm-stubs but you can't use the classes from "phpstorm-stubs" directly, because the are in a test namespace and the autoloader is "autoload-dev", so here is a extended version.

We will use: - "PHP Reflection" AND / OR "nikic/PHP-Parser" - phpDocumentor (+ psalm)

Install via "composer require"

composer require voku/simple-php-code-parser

Quick Start

Parse a string:

$code = '
<?php
namespace voku\tests;
class SimpleClass {}
$obja = new class() {};
$objb = new class {};
class AnotherClass {}
';
$phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getFromString($code);
$phpClasses = $phpCode->getClasses();

var_dump($phpClasses['voku\tests\SimpleClass']); // "PHPClass"-object

Parse one file:

$phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getPhpFiles(__DIR__ . '/Dummy.php');
$phpClasses = $phpCode->getClasses();

var_dump($phpClasses[Dummy::class]); // "PHPClass"-object

var_dump($phpClasses[Dummy::class]->methods); // "PHPMethod[]"-objects

var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']); // "PHPMethod"-object

var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters); // "PHPParameter[]"-objects

var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters['useRandInt']); // "PHPParameter"-object

var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters['useRandInt']->type); // "bool"

Parse many files:

$phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getPhpFiles(__DIR__ . '/src');
$phpClasses = $phpCode->getClasses();

var_dump($phpClasses[Dummy::class]); // "PHPClass"-object

Support

For support and donations please visit Github | Issues | PayPal | Patreon.

For status updates and release announcements please visit Releases | Twitter | Patreon.

For professional support please contact me.

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerfull code style check.
  • Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code! w
  Files folder image Files  
File Role Description
Files folder image.github (4 files)
Files folder imagesrc (1 directory)
Files folder imagetests (5 files)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .gitattributes Data Auxiliary data
Accessible without login Plain text file .gitignore Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file circle.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.php_cs Example Example script
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:63
This week:63
All time:9,672
This week:7Up

For more information send a message to info at phpclasses dot org.