Skip to content

Commit 2c08cae

Browse files
committed
setName() is deprecated in favor of constructors
1 parent 6e1b293 commit 2c08cae

File tree

8 files changed

+15
-37
lines changed

8 files changed

+15
-37
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public static function from($from)
9999
}
100100

101101

102-
public function __construct($name = NULL, PhpNamespace $namespace = NULL)
102+
public function __construct($name = '', PhpNamespace $namespace = NULL)
103103
{
104-
$this->setName((string) $name);
104+
$this->setName($name);
105105
$this->namespace = $namespace;
106106
}
107107

@@ -158,18 +158,15 @@ public function __toString()
158158

159159

160160
/**
161-
* @return PhpNamespace
161+
* @return PhpNamespace|NULL
162162
*/
163163
public function getNamespace()
164164
{
165165
return $this->namespace;
166166
}
167167

168168

169-
/**
170-
* @param string
171-
* @return self
172-
*/
169+
/** @deprecated */
173170
public function setName($name)
174171
{
175172
$this->name = (string) $name;

src/PhpGenerator/Method.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ public function __toString()
141141
}
142142

143143

144-
/**
145-
* @param string|NULL
146-
* @return self
147-
*/
144+
/** @deprecated */
148145
public function setName($name)
149146
{
150147
$this->name = $name ? (string) $name : NULL;

src/PhpGenerator/Parameter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ public function __construct($name = '')
7575
}
7676

7777

78-
/**
79-
* @param string without $
80-
* @return self
81-
*/
78+
/** @deprecated */
8279
public function setName($name)
8380
{
8481
$this->name = (string) $name;

src/PhpGenerator/PhpNamespace.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public function __construct($name = NULL)
4141
}
4242

4343

44-
/**
45-
* @param string|NULL
46-
* @return self
47-
*/
44+
/** @deprecated */
4845
public function setName($name)
4946
{
5047
$this->name = (string) $name;

src/PhpGenerator/Property.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ public function __construct($name = '')
5555
}
5656

5757

58-
/**
59-
* @param string without $
60-
* @return self
61-
*/
58+
/** @deprecated */
6259
public function setName($name)
6360
{
6461
$this->name = (string) $name;

tests/PhpGenerator/Method.returnTypes.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ namespace
3434

3535
// generating methods with return type declarations
3636

37-
$method = (new Method)
38-
->setName('create')
37+
$method = (new Method('create'))
3938
->setReturnType('Foo')
4039
->setBody('return new Foo();');
4140

tests/PhpGenerator/Method.scalarParameters.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ Assert::same('float', $method->getParameters()['d']->getTypeHint());
3535

3636
// generating methods with scalar type hints
3737

38-
$method = (new Method)
39-
->setName('create')
38+
$method = (new Method('create'))
4039
->setBody('return null;');
4140
$method->addParameter('a')->setTypeHint('string');
4241
$method->addParameter('b')->setTypeHint('bool');

tests/PhpGenerator/Method.variadics.phpt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ Assert::same('array', $method->getParameters()['bar']->getTypeHint());
3434
// test generating
3535

3636
// parameterless variadic method
37-
$method = (new Method)
38-
->setName('variadic')
37+
$method = (new Method('variadic'))
3938
->setVariadic(TRUE)
4039
->setBody('return 42;');
4140

@@ -48,8 +47,7 @@ Assert::match(
4847

4948

5049
// variadic method with one parameter
51-
$method = (new Method)
52-
->setName('variadic')
50+
$method = (new Method('variadic'))
5351
->setVariadic(TRUE)
5452
->setBody('return 42;');
5553
$method->addParameter('foo');
@@ -63,8 +61,7 @@ Assert::match(
6361

6462

6563
// variadic method with multiple parameters
66-
$method = (new Method)
67-
->setName('variadic')
64+
$method = (new Method('variadic'))
6865
->setVariadic(TRUE)
6966
->setBody('return 42;');
7067
$method->addParameter('foo');
@@ -80,8 +77,7 @@ Assert::match(
8077

8178

8279
// method with typehinted variadic param
83-
$method = (new Method)
84-
->setName('variadic')
80+
$method = (new Method('variadic'))
8581
->setVariadic(TRUE)
8682
->setBody('return 42;');
8783
$method->addParameter('foo')->setTypeHint('array');
@@ -95,8 +91,7 @@ Assert::match(
9591

9692

9793
// method with typrhinted by-value variadic param
98-
$method = (new Method)
99-
->setName('variadic')
94+
$method = (new Method('variadic'))
10095
->setVariadic(TRUE)
10196
->setBody('return 42;');
10297
$method->addParameter('foo')->setTypeHint('array')->setReference(TRUE);

0 commit comments

Comments
 (0)