1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Rename setTypeHint() to setType()

To align with modern terminology -- we don't like calling these
type hints anymore. Old method name remains, marked as @deprecated.
This commit is contained in:
Nikita Popov 2018-07-22 21:41:21 +02:00
parent 4d6825c460
commit 41408081d7
4 changed files with 27 additions and 9 deletions

View File

@ -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)
--------------------------

View File

@ -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.
*

View File

@ -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() {

View File

@ -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.
*