PHP code example of quintenmbusiness / php-ast-toolkit

1. Go to this page and download the library: Download quintenmbusiness/php-ast-toolkit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

quintenmbusiness / php-ast-toolkit example snippets


use quintenmbusiness\PhpAstCodeGenerationHelper\Core\DirectoryScanner;
use quintenmbusiness\PhpAstCodeGenerationHelper\Core\ClassFilter;

$scanner = new DirectoryScanner();
$classes = $scanner->scan('/path/to/php/files', true);
$filter = new ClassFilter($classes);

// Search for a specific class
$class = $filter->searchByClassName('MyClass')[0];

$class->updateName('NewClassName');
$class->methods[0]->updateName('newMethodName');
$class->save();

$newInterfacePath = '/path/to/NewInterface.php';
$class->createInterfaceVersion(
    newName: 'NewInterface',
    newPath: $newInterfacePath,
    newExtends: null,
    newImplements: [],
    updateOriginal: true
);

$newFilePath = '/path/to/NewClass.php';
$newClass = $class->copy($newFilePath);