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  
Name: Lars Moelleken <contact>
Classes: 23 packages by
Country: Germany Germany
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

  Files folder image Files  /  .github  
File Role Description
  Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data
  Accessible without login Plain text file ISSUE_TEMPLATE.md Data Auxiliary data
  Accessible without login Plain text file PULL_REQUEST_TEMPLATE.md Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imagevoku (1 directory)

  Files folder image Files  /  src  /  voku  
File Role Description
Files folder imageSimplePhpParser (2 directories)

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  
File Role Description
Files folder imageModel (11 files, 1 directory)
Files folder imageParsers (1 file, 2 directories)

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  /  Model  
File Role Description
Files folder imagetypes (6 files)
  Plain text file BasePHPClass.php Class Class source
  Plain text file BasePHPElement.php Class Class source
  Plain text file PHPClass.php Class Class source
  Plain text file PHPConst.php Class Class source
  Plain text file PHPDefineConstant.php Class Class source
  Plain text file PHPDocElement.php Class Class source
  Plain text file PHPFunction.php Class Class source
  Plain text file PHPInterface.php Class Class source
  Plain text file PHPMethod.php Class Class source
  Plain text file PHPParameter.php Class Class source
  Plain text file PHPProperty.php Class Class source

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  /  Model  /  types  
File Role Description
  Plain text file ArrayArray.php Class Class source
  Plain text file ArrayFloat.php Class Class source
  Plain text file ArrayInt.php Class Class source
  Plain text file ArrayString.php Class Class source
  Plain text file BooleanFalse.php Class Class source
  Plain text file BooleanTrue.php Class Class source

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  /  Parsers  
File Role Description
Files folder imageHelper (4 files, 1 directory)
Files folder imageVisitors (2 files)
  Plain text file PhpCodeParser.php Class Class source

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  /  Parsers  /  Helper  
File Role Description
Files folder imagePsalm (2 files)
  Plain text file DocFactoryProvider.php Class Class source
  Plain text file ParserContainer.php Class Class source
  Plain text file ParserErrorHandler.php Class Class source
  Plain text file Utils.php Class Class source

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  /  Parsers  /  Helper  /  Psalm  
File Role Description
  Plain text file FakeConfig.php Class Class source
  Plain text file FakeFileProvider.php Class Class source

  Files folder image Files  /  src  /  voku  /  SimplePhpParser  /  Parsers  /  Visitors  
File Role Description
  Plain text file ASTVisitor.php Class Class source
  Plain text file ParentConnector.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file Dummy.php Class Class source
  Plain text file Dummy2.php Class Class source
  Plain text file DummyInterface.php Class Class source
  Plain text file ParserTest.php Class Class source

 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.