diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf3d3c..1011f17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ Version 4.0.4-dev * Passing a string with a leading backslash to the `Name` constructor will now throw an exception. Most likely a use of `Name\FullyQualified` was intended. + +### Deprecated + +* `Builder\Param::setTypeHint()` has been deprecated in favor of the newly introduced + `Builder\Param::setType()`. Version 4.0.3 (2018-07-15) -------------------------- diff --git a/lib/PhpParser/Builder/Param.php b/lib/PhpParser/Builder/Param.php index eff76cb..184813a 100644 --- a/lib/PhpParser/Builder/Param.php +++ b/lib/PhpParser/Builder/Param.php @@ -42,13 +42,13 @@ class Param implements PhpParser\Builder } /** - * Sets type hint for the parameter. + * Sets type for the parameter. * - * @param string|Node\Name|Node\NullableType $type Type hint to use + * @param string|Node\Name|Node\NullableType $type Parameter type * * @return $this The builder instance (for fluid interface) */ - public function setTypeHint($type) { + public function setType($type) { $this->type = BuilderHelpers::normalizeType($type); if ($this->type == 'void') { throw new \LogicException('Parameter type cannot be void'); @@ -57,6 +57,19 @@ class Param implements PhpParser\Builder return $this; } + /** + * Sets type for the parameter. + * + * @param string|Node\Name|Node\NullableType $type Parameter type + * + * @return $this The builder instance (for fluid interface) + * + * @deprecated Use setType() instead + */ + public function setTypeHint($type) { + return $this->setType($type); + } + /** * Make the parameter accept the value by reference. * diff --git a/test/PhpParser/Builder/ParamTest.php b/test/PhpParser/Builder/ParamTest.php index d331892..e060625 100644 --- a/test/PhpParser/Builder/ParamTest.php +++ b/test/PhpParser/Builder/ParamTest.php @@ -80,9 +80,9 @@ class ParamTest extends TestCase } /** - * @dataProvider provideTestTypeHints + * @dataProvider provideTestTypes */ - public function testTypeHints($typeHint, $expectedType) { + public function testTypes($typeHint, $expectedType) { $node = $this->createParamBuilder('test') ->setTypeHint($typeHint) ->getNode() @@ -100,7 +100,7 @@ class ParamTest extends TestCase $this->assertEquals($expectedType, $type); } - public function provideTestTypeHints() { + public function provideTestTypes() { return [ ['array', new Node\Identifier('array')], ['callable', new Node\Identifier('callable')], @@ -134,7 +134,7 @@ class ParamTest extends TestCase * @expectedExceptionMessage Parameter type cannot be void */ public function testVoidTypeError() { - $this->createParamBuilder('test')->setTypeHint('void'); + $this->createParamBuilder('test')->setType('void'); } /** @@ -142,7 +142,7 @@ class ParamTest extends TestCase * @expectedExceptionMessage Type must be a string, or an instance of Name, Identifier or NullableType */ public function testInvalidTypeError() { - $this->createParamBuilder('test')->setTypeHint(new \stdClass); + $this->createParamBuilder('test')->setType(new \stdClass); } public function testByRef() { diff --git a/test/PhpParser/BuilderFactoryTest.php b/test/PhpParser/BuilderFactoryTest.php index efab03d..08b0736 100644 --- a/test/PhpParser/BuilderFactoryTest.php +++ b/test/PhpParser/BuilderFactoryTest.php @@ -276,7 +276,7 @@ class BuilderFactoryTest extends TestCase ->addStmt($factory->method('someMethod') ->makePublic() ->makeAbstract() - ->addParam($factory->param('someParam')->setTypeHint('SomeClass')) + ->addParam($factory->param('someParam')->setType('SomeClass')) ->setDocComment('/** * This method does something. *