-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
874baec
commit a4b4b47
Showing
21 changed files
with
282 additions
and
186 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "rector/simple-php-doc-parser", | ||
"description": "Simple service integration of phpstan/phpdoc-parser", | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.2.4|^8.0", | ||
"symfony/dependency-injection": "^4.4.8|^5.1", | ||
"symfony/config": "^4.4.8|^5.1", | ||
"symfony/http-kernel": "^4.4.8|^5.1", | ||
"symplify/package-builder": "^8.3.33" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^8.5|^9.2", | ||
"symplify/easy-testing": "^8.3.33" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Rector\\SymfonyPhpDocParser\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Rector\\SymfonyPhpDocParser\\Tests\\": "tests" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PHPStan\PhpDocParser\Lexer\Lexer; | ||
use PHPStan\PhpDocParser\Parser\PhpDocParser; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
|
||
$services->defaults() | ||
->public() | ||
->autowire() | ||
->autoconfigure(); | ||
|
||
$services->load('Rector\SimplePhpDocParser\\', __DIR__ . '/../src'); | ||
|
||
$services->set(PhpDocParser::class); | ||
$services->set(Lexer::class); | ||
}; |
19 changes: 19 additions & 0 deletions
19
...e-php-doc-parser/src/Bundle/DependencyInjection/Extension/SimplePhpDocParserExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SimplePhpDocParser\Bundle\DependencyInjection\Extension; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | ||
|
||
final class SimplePhpDocParserExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $containerBuilder): void | ||
{ | ||
$phpFileLoader = new PhpFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../../../../config')); | ||
$phpFileLoader->load('config.php'); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/simple-php-doc-parser/src/Bundle/SimplePhpDocParserBundle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SimplePhpDocParser\Bundle; | ||
|
||
use Rector\SimplePhpDocParser\Bundle\DependencyInjection\Extension\SimplePhpDocParserExtension; | ||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; | ||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
final class SimplePhpDocParserBundle extends Bundle | ||
{ | ||
public function getContainerExtension(): ?ExtensionInterface | ||
{ | ||
return new SimplePhpDocParserExtension(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SimplePhpDocParser; | ||
|
||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; | ||
use PHPStan\PhpDocParser\Lexer\Lexer; | ||
use PHPStan\PhpDocParser\Parser\PhpDocParser; | ||
use PHPStan\PhpDocParser\Parser\TokenIterator; | ||
|
||
/** | ||
* @see \Rector\SimplePhpDocParser\Tests\SimplePhpDocParser\SimplePhpDocParserTest | ||
*/ | ||
final class SimplePhpDocParser | ||
{ | ||
/** | ||
* @var PhpDocParser | ||
*/ | ||
private $phpDocParser; | ||
|
||
/** | ||
* @var Lexer | ||
*/ | ||
private $lexer; | ||
|
||
public function __construct(PhpDocParser $phpDocParser, Lexer $lexer) | ||
{ | ||
$this->phpDocParser = $phpDocParser; | ||
$this->lexer = $lexer; | ||
} | ||
|
||
public function parseDocBlock(string $docBlock): PhpDocNode | ||
{ | ||
$tokens = $this->lexer->tokenize($docBlock); | ||
$tokenIterator = new TokenIterator($tokens); | ||
|
||
return $this->phpDocParser->parse($tokenIterator); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/simple-php-doc-parser/tests/SimplePhpDocParser/Fixture/basic_doc.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** | ||
* @var int | ||
*/ |
34 changes: 34 additions & 0 deletions
34
packages/simple-php-doc-parser/tests/SimplePhpDocParser/SimplePhpDocParserTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SimplePhpDocParser\Tests\SimplePhpDocParser; | ||
|
||
use Rector\Core\HttpKernel\RectorKernel; | ||
use Rector\SimplePhpDocParser\SimplePhpDocParser; | ||
use Symplify\PackageBuilder\Tests\AbstractKernelTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class SimplePhpDocParserTest extends AbstractKernelTestCase | ||
{ | ||
/** | ||
* @var SimplePhpDocParser | ||
*/ | ||
private $simplePhpDocParser; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->bootKernel(RectorKernel::class); | ||
$this->simplePhpDocParser = self::$container->get(SimplePhpDocParser::class); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$fileInfo = new SmartFileInfo(__DIR__ . '/Fixture/basic_doc.txt'); | ||
|
||
$phpDocNode = $this->simplePhpDocParser->parseDocBlock($fileInfo->getContents()); | ||
|
||
$varTagValues = $phpDocNode->getVarTagValues(); | ||
$this->assertCount(1, $varTagValues); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.