Skip to content

Commit 4c11c7e

Browse files
committed
Method, Parameter, Property: added and used constructors
1 parent 36f8baf commit 4c11c7e

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ public function getProperty($name)
452452
*/
453453
public function addProperty($name, $value = NULL)
454454
{
455-
$property = new Property;
456-
return $this->properties[$name] = $property->setName($name)->setValue($value);
455+
$property = new Property($name);
456+
return $this->properties[$name] = $property->setValue($value);
457457
}
458458

459459

@@ -500,13 +500,13 @@ public function getMethod($name)
500500
*/
501501
public function addMethod($name)
502502
{
503-
$method = new Method;
503+
$method = new Method($name);
504504
if ($this->type === 'interface') {
505505
$method->setVisibility(NULL)->setBody(FALSE);
506506
} else {
507507
$method->setVisibility('public');
508508
}
509-
return $this->methods[$name] = $method->setName($name);
509+
return $this->methods[$name] = $method;
510510
}
511511

512512
}

src/PhpGenerator/Method.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public static function from($from)
6565
$from = new \ReflectionFunction($from);
6666
}
6767

68-
$method = new static;
69-
$method->name = $from->isClosure() ? NULL : $from->getName();
68+
$method = new static($from->isClosure() ? NULL : $from->getName());
7069
foreach ($from->getParameters() as $param) {
7170
$method->parameters[$param->getName()] = Parameter::from($param);
7271
}
@@ -84,6 +83,15 @@ public static function from($from)
8483
}
8584

8685

86+
/**
87+
* @param string|NULL
88+
*/
89+
public function __construct($name = NULL)
90+
{
91+
$this->setName($name);
92+
}
93+
94+
8795
/**
8896
* @return string PHP code
8997
*/
@@ -173,11 +181,11 @@ public function getParameters()
173181
*/
174182
public function addParameter($name, $defaultValue = NULL)
175183
{
176-
$param = new Parameter;
184+
$param = new Parameter($name);
177185
if (func_num_args() > 1) {
178186
$param->setOptional(TRUE)->setDefaultValue($defaultValue);
179187
}
180-
return $this->parameters[$name] = $param->setName($name);
188+
return $this->parameters[$name] = $param;
181189
}
182190

183191

@@ -205,8 +213,7 @@ public function getUses()
205213
*/
206214
public function addUse($name)
207215
{
208-
$param = new Parameter;
209-
return $this->uses[] = $param->setName($name);
216+
return $this->uses[] = new Parameter($name);
210217
}
211218

212219

src/PhpGenerator/Parameter.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class Parameter extends Nette\Object
3636
*/
3737
public static function from(\ReflectionParameter $from)
3838
{
39-
$param = new static;
40-
$param->name = $from->getName();
39+
$param = new static($from->getName());
4140
$param->reference = $from->isPassedByReference();
4241
if ($from->isArray()) {
4342
$param->typeHint = 'array';
@@ -66,6 +65,15 @@ public static function from(\ReflectionParameter $from)
6665
}
6766

6867

68+
/**
69+
* @param string without $
70+
*/
71+
public function __construct($name = '')
72+
{
73+
$this->setName($name);
74+
}
75+
76+
6977
/**
7078
* @param string without $
7179
* @return self

src/PhpGenerator/Property.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class Property extends Nette\Object
3636
*/
3737
public static function from(\ReflectionProperty $from)
3838
{
39-
$prop = new static;
40-
$prop->name = $from->getName();
39+
$prop = new static($from->getName());
4140
$defaults = $from->getDeclaringClass()->getDefaultProperties();
4241
$prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
4342
$prop->static = $from->isStatic();
@@ -47,6 +46,15 @@ public static function from(\ReflectionProperty $from)
4746
}
4847

4948

49+
/**
50+
* @param string without $
51+
*/
52+
public function __construct($name = '')
53+
{
54+
$this->setName($name);
55+
}
56+
57+
5058
/**
5159
* @param string without $
5260
* @return self

0 commit comments

Comments
 (0)