PHP code example of symplify / better-phpdoc-parser

1. Go to this page and download the library: Download symplify/better-phpdoc-parser 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/ */

    

symplify / better-phpdoc-parser example snippets


/**
 * @param   string   $name
 * @param   string   $surname
 * @return  bool
  */

/**
 * @param string $name
 * @param string $surname
 * @return bool
 */

/**
 * @param   string   $name
 * @param   string   $surname
 * @return  bool
 */



use Symplify\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Symplify\BetterPhpDocParser\Printer\PhpDocInfoPrinter;

class SomeClass
{
    public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpDocInfoPrinter $phpDocInfoPrinter)
    {
        $this->phpDocInfoFactory = $phpDocInfoFactory;
        $this->phpDocInfoPrinter = $phpDocInfoPrinter;
    }

    public function changeDocBlockAndPrintItBack(): string
    {
        $docComment = '/**    @var Type $variable    */';

        $phpDocInfo = $this->phpDocInfoFactory->createFrom($docComment);

        // modify `$phpDocInfo` using its methods

        return $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo);
    }
}