mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 20:14:46 +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:
parent
4d6825c460
commit
41408081d7
@ -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.
|
* 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.
|
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)
|
Version 4.0.3 (2018-07-15)
|
||||||
--------------------------
|
--------------------------
|
||||||
|
@ -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)
|
* @return $this The builder instance (for fluid interface)
|
||||||
*/
|
*/
|
||||||
public function setTypeHint($type) {
|
public function setType($type) {
|
||||||
$this->type = BuilderHelpers::normalizeType($type);
|
$this->type = BuilderHelpers::normalizeType($type);
|
||||||
if ($this->type == 'void') {
|
if ($this->type == 'void') {
|
||||||
throw new \LogicException('Parameter type cannot be void');
|
throw new \LogicException('Parameter type cannot be void');
|
||||||
@ -57,6 +57,19 @@ class Param implements PhpParser\Builder
|
|||||||
return $this;
|
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.
|
* Make the parameter accept the value by reference.
|
||||||
*
|
*
|
||||||
|
@ -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')
|
$node = $this->createParamBuilder('test')
|
||||||
->setTypeHint($typeHint)
|
->setTypeHint($typeHint)
|
||||||
->getNode()
|
->getNode()
|
||||||
@ -100,7 +100,7 @@ class ParamTest extends TestCase
|
|||||||
$this->assertEquals($expectedType, $type);
|
$this->assertEquals($expectedType, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideTestTypeHints() {
|
public function provideTestTypes() {
|
||||||
return [
|
return [
|
||||||
['array', new Node\Identifier('array')],
|
['array', new Node\Identifier('array')],
|
||||||
['callable', new Node\Identifier('callable')],
|
['callable', new Node\Identifier('callable')],
|
||||||
@ -134,7 +134,7 @@ class ParamTest extends TestCase
|
|||||||
* @expectedExceptionMessage Parameter type cannot be void
|
* @expectedExceptionMessage Parameter type cannot be void
|
||||||
*/
|
*/
|
||||||
public function testVoidTypeError() {
|
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
|
* @expectedExceptionMessage Type must be a string, or an instance of Name, Identifier or NullableType
|
||||||
*/
|
*/
|
||||||
public function testInvalidTypeError() {
|
public function testInvalidTypeError() {
|
||||||
$this->createParamBuilder('test')->setTypeHint(new \stdClass);
|
$this->createParamBuilder('test')->setType(new \stdClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testByRef() {
|
public function testByRef() {
|
||||||
|
@ -276,7 +276,7 @@ class BuilderFactoryTest extends TestCase
|
|||||||
->addStmt($factory->method('someMethod')
|
->addStmt($factory->method('someMethod')
|
||||||
->makePublic()
|
->makePublic()
|
||||||
->makeAbstract()
|
->makeAbstract()
|
||||||
->addParam($factory->param('someParam')->setTypeHint('SomeClass'))
|
->addParam($factory->param('someParam')->setType('SomeClass'))
|
||||||
->setDocComment('/**
|
->setDocComment('/**
|
||||||
* This method does something.
|
* This method does something.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user