diff --git a/CHANGELOG.md b/CHANGELOG.md index facd571..b1b8ad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ Version 4.0.4-dev ----------------- -Nothing yet. +### Added + +* The following methods have been added to `BuilderFactory`: + * `useFunction()` + * `useConst()` Version 4.0.3 (2018-07-15) -------------------------- diff --git a/lib/PhpParser/BuilderFactory.php b/lib/PhpParser/BuilderFactory.php index 10028cd..b717dd5 100644 --- a/lib/PhpParser/BuilderFactory.php +++ b/lib/PhpParser/BuilderFactory.php @@ -106,7 +106,7 @@ class BuilderFactory * * @param Node\Name|string $name Name of the entity (namespace or class) to alias * - * @return Builder\Use_ The create use builder + * @return Builder\Use_ The created use builder */ public function use($name) : Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_NORMAL); @@ -117,7 +117,7 @@ class BuilderFactory * * @param Node\Name|string $name Name of the function to alias * - * @return Builder\Use_ The create use builder + * @return Builder\Use_ The created use function builder */ public function useFunction($name) : Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_FUNCTION); @@ -128,7 +128,7 @@ class BuilderFactory * * @param Node\Name|string $name Name of the const to alias * - * @return Builder\Use_ The create use builder + * @return Builder\Use_ The created use const builder */ public function useConst($name) : Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_CONSTANT); diff --git a/test/PhpParser/Builder/UseTest.php b/test/PhpParser/Builder/UseTest.php index 85c1d77..54ede58 100644 --- a/test/PhpParser/Builder/UseTest.php +++ b/test/PhpParser/Builder/UseTest.php @@ -26,5 +26,10 @@ class UseTest extends TestCase $this->assertEquals(new Stmt\Use_([ new Stmt\UseUse(new Name('foo\bar'), 'foo') ], Stmt\Use_::TYPE_FUNCTION), $node); + + $node = $this->createUseBuilder('foo\BAR', Stmt\Use_::TYPE_CONSTANT)->as('FOO')->getNode(); + $this->assertEquals(new Stmt\Use_([ + new Stmt\UseUse(new Name('foo\BAR'), 'FOO') + ], Stmt\Use_::TYPE_CONSTANT), $node); } } diff --git a/test/PhpParser/BuilderFactoryTest.php b/test/PhpParser/BuilderFactoryTest.php index 465f600..356880b 100644 --- a/test/PhpParser/BuilderFactoryTest.php +++ b/test/PhpParser/BuilderFactoryTest.php @@ -25,15 +25,17 @@ class BuilderFactoryTest extends TestCase public function provideTestFactory() { return [ - ['namespace', Builder\Namespace_::class], - ['class', Builder\Class_::class], - ['interface', Builder\Interface_::class], - ['trait', Builder\Trait_::class], - ['method', Builder\Method::class], - ['function', Builder\Function_::class], - ['property', Builder\Property::class], - ['param', Builder\Param::class], - ['use', Builder\Use_::class], + ['namespace', Builder\Namespace_::class], + ['class', Builder\Class_::class], + ['interface', Builder\Interface_::class], + ['trait', Builder\Trait_::class], + ['method', Builder\Method::class], + ['function', Builder\Function_::class], + ['property', Builder\Property::class], + ['param', Builder\Param::class], + ['use', Builder\Use_::class], + ['useFunction', Builder\Use_::class], + ['useConst', Builder\Use_::class], ]; } @@ -217,6 +219,8 @@ class BuilderFactoryTest extends TestCase $node = $factory->namespace('Name\Space') ->addStmt($factory->use('Foo\Bar\SomeOtherClass')) ->addStmt($factory->use('Foo\Bar')->as('A')) + ->addStmt($factory->useFunction('strlen')) + ->addStmt($factory->useConst('PHP_VERSION')) ->addStmt($factory ->class('SomeClass') ->extend('SomeOtherClass') @@ -254,6 +258,8 @@ namespace Name\Space; use Foo\Bar\SomeOtherClass; use Foo\Bar as A; +use function strlen; +use const PHP_VERSION; abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces { protected $someProperty;