Skip to content

Commit 2f15be4

Browse files
committed
Method, Parameter, Property: added and used constructors
1 parent cd49f30 commit 2f15be4

File tree

5 files changed

+36
-16
lines changed

5 files changed

+36
-16
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,7 @@ public function getProperty($name)
473473
*/
474474
public function addProperty($name, $value = NULL)
475475
{
476-
$property = new Property;
477-
return $this->properties[$name] = $property->setName($name)->setValue($value);
476+
return $this->properties[$name] = (new Property($name))->setValue($value);
478477
}
479478

480479

@@ -521,13 +520,13 @@ public function getMethod($name)
521520
*/
522521
public function addMethod($name)
523522
{
524-
$method = new Method;
523+
$method = new Method($name);
525524
if ($this->type === 'interface') {
526525
$method->setVisibility(NULL)->setBody(FALSE);
527526
} else {
528527
$method->setVisibility('public');
529528
}
530-
return $this->methods[$name] = $method->setName($name);
529+
return $this->methods[$name] = $method;
531530
}
532531

533532
}

src/PhpGenerator/Method.php

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

71-
$method = new static;
72-
$method->name = $from->isClosure() ? NULL : $from->getName();
71+
$method = new static($from->isClosure() ? NULL : $from->getName());
7372
foreach ($from->getParameters() as $param) {
7473
$method->parameters[$param->getName()] = Parameter::from($param);
7574
}
@@ -91,6 +90,15 @@ public static function from($from)
9190
}
9291

9392

93+
/**
94+
* @param string|NULL
95+
*/
96+
public function __construct($name = NULL)
97+
{
98+
$this->setName($name);
99+
}
100+
101+
94102
/**
95103
* @return string PHP code
96104
*/
@@ -184,11 +192,11 @@ public function getParameters()
184192
*/
185193
public function addParameter($name, $defaultValue = NULL)
186194
{
187-
$param = new Parameter;
195+
$param = new Parameter($name);
188196
if (func_num_args() > 1) {
189197
$param->setOptional(TRUE)->setDefaultValue($defaultValue);
190198
}
191-
return $this->parameters[$name] = $param->setName($name);
199+
return $this->parameters[$name] = $param;
192200
}
193201

194202

@@ -216,8 +224,7 @@ public function getUses()
216224
*/
217225
public function addUse($name)
218226
{
219-
$param = new Parameter;
220-
return $this->uses[] = $param->setName($name);
227+
return $this->uses[] = new Parameter($name);
221228
}
222229

223230

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 (PHP_VERSION_ID >= 70000) {
4342
$type = $from->getType();
@@ -67,6 +66,15 @@ public static function from(\ReflectionParameter $from)
6766
}
6867

6968

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

src/PhpGenerator/PhpFile.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class PhpFile extends Object
2828
private $namespaces = [];
2929

3030

31-
32-
3331
/**
3432
* @param string|NULL
3533
* @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)