vm5/php-parser

There is no license information available for the latest version (dev-master) of this package.

This package can parse easily PHP Files. There is a visitor which removes all the PHP comments (NOT the DocBlocks) - including @author and @copyright tags from docblocks.

dev-master 2017-09-12 09:12 UTC

This package is auto-updated.

Last update: 2024-03-26 23:42:53 UTC


README

Sample usage:

<?php

use PhpParser\NodeTraverser;
use PhpParser\PrettyPrinter;
use VM5\PhpCommentsRemover\Saver\SameFileSaver;
use VM5\PhpCommentsRemover\Visitor;

require 'vendor/autoload.php';

$parserFactory = new \PhpParser\ParserFactory();

$docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
$serializer = new \phpDocumentor\Reflection\DocBlock\Serializer();

$docBlockVisitors = [
    new \VM5\PhpParser\DocBlockVisitor\CommentsRemoverDocBlockVisitor(),
];

$visitor = new \VM5\PhpParser\NodeVisitor\DocBlockVisitor($docBlockFactory, $serializer, $docBlockVisitors);
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor($visitor);

$removeComments = new \VM5\PhpCommentsRemover\CommentsRemover(
    $parserFactory->create(\PhpParser\ParserFactory::PREFER_PHP5),
    $traverser,
    new PrettyPrinter\Standard,
    new SameFileSaver()
);

$removeComments->parseDirectory(__DIR__);
$removeComments->parseFile('file.php');