Skip to content

Commit 58e904b

Browse files
committed
PhpGenerator: uses magic @methods
1 parent 42626d5 commit 58e904b

File tree

4 files changed

+97
-84
lines changed

4 files changed

+97
-84
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,67 @@
2121
*
2222
* @author David Grudl
2323
*
24-
* @method ClassType setName(string $name)
25-
* @method ClassType setType(string $type)
26-
* @method ClassType setFinal(bool $on)
27-
* @method ClassType setAbstract(bool $on)
28-
* @method ClassType addExtend(string $class)
29-
* @method ClassType addImplement(string $interface)
30-
* @method ClassType addTrait(string $trait)
31-
* @method ClassType addDocument(string $doc)
24+
* @method ClassType setName(string)
25+
* @method string getName()
26+
* @method ClassType setType(string)
27+
* @method string getType()
28+
* @method ClassType setFinal(bool)
29+
* @method bool isFinal()
30+
* @method ClassType setAbstract(bool)
31+
* @method bool isAbstract()
32+
* @method ClassType setExtends(string[]|string)
33+
* @method string[]|string getExtends()
34+
* @method ClassType addExtend(string)
35+
* @method ClassType setImplements(string[])
36+
* @method string[] getImplements()
37+
* @method ClassType addImplement(string)
38+
* @method ClassType setTraits(string[])
39+
* @method string[] getTraits()
40+
* @method ClassType addTrait(string)
41+
* @method ClassType setDocuments(string[])
42+
* @method string[] getDocuments()
43+
* @method ClassType addDocument(string)
44+
* @method ClassType setConsts(scalar[])
45+
* @method scalar[] getConsts()
46+
* @method ClassType setProperties(Property[])
47+
* @method Property[] getProperties()
48+
* @method ClassType setMethods(Method[])
49+
* @method Method[] getMethods()
3250
*/
3351
class ClassType extends Nette\Object
3452
{
3553
/** @var string */
36-
public $name;
54+
private $name;
3755

3856
/** @var string class|interface|trait */
39-
public $type = 'class';
57+
private $type = 'class';
4058

4159
/** @var bool */
42-
public $final;
60+
private $final;
4361

4462
/** @var bool */
45-
public $abstract;
63+
private $abstract;
4664

47-
/** @var string[] */
48-
public $extends = array();
65+
/** @var string[]|string */
66+
private $extends = array();
4967

5068
/** @var string[] */
51-
public $implements = array();
69+
private $implements = array();
5270

5371
/** @var string[] */
54-
public $traits = array();
72+
private $traits = array();
5573

5674
/** @var string[] */
57-
public $documents = array();
75+
private $documents = array();
5876

5977
/** @var mixed[] name => value */
60-
public $consts = array();
78+
private $consts = array();
6179

6280
/** @var Property[] name => Property */
63-
public $properties = array();
81+
private $properties = array();
6482

6583
/** @var Method[] name => Method */
66-
public $methods = array();
84+
private $methods = array();
6785

6886

6987
/** @return ClassType */
@@ -141,13 +159,6 @@ public function addMethod($name)
141159

142160

143161

144-
public function __call($name, $args)
145-
{
146-
return Nette\ObjectMixin::callProperty($this, $name, $args);
147-
}
148-
149-
150-
151162
/** @return string PHP code */
152163
public function __toString()
153164
{

src/PhpGenerator/Method.php

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,58 @@
2020
*
2121
* @author David Grudl
2222
*
23-
* @method Method setName(string $name)
24-
* @method Method setBody(string $body)
25-
* @method Method setStatic(bool $on)
26-
* @method Method setVisibility(string $access)
27-
* @method Method setFinal(bool $on)
28-
* @method Method setAbstract(bool $on)
29-
* @method Method setReturnReference(bool $on)
30-
* @method Method addDocument(string $doc)
23+
* @method Method setName(string)
24+
* @method string getName()
25+
* @method Method setParameters(Parameter[])
26+
* @method Parameter[] getParameters()
27+
* @method Method setUses(array)
28+
* @method array getUses()
29+
* @method string getBody()
30+
* @method Method setStatic(bool)
31+
* @method bool isStatic()
32+
* @method Method setVisibility(string)
33+
* @method string getVisibility()
34+
* @method Method setFinal(bool)
35+
* @method bool isFinal()
36+
* @method Method setAbstract(bool)
37+
* @method bool isAbstract()
38+
* @method Method setReturnReference(bool)
39+
* @method bool getReturnReference()
40+
* @method Method setDocuments(string[])
41+
* @method string[] getDocuments()
42+
* @method Method addDocument(string)
3143
*/
3244
class Method extends Nette\Object
3345
{
3446
/** @var string */
35-
public $name;
47+
private $name;
3648

3749
/** @var array of name => Parameter */
38-
public $parameters = array();
50+
private $parameters = array();
3951

4052
/** @var array of name => bool */
41-
public $uses = array();
53+
private $uses = array();
4254

4355
/** @var string|FALSE */
44-
public $body;
56+
private $body;
4557

4658
/** @var bool */
47-
public $static;
59+
private $static;
4860

4961
/** @var string public|protected|private or none */
50-
public $visibility;
62+
private $visibility;
5163

5264
/** @var bool */
53-
public $final;
65+
private $final;
5466

5567
/** @var bool */
56-
public $abstract;
68+
private $abstract;
5769

5870
/** @var bool */
59-
public $returnReference;
71+
private $returnReference;
6072

6173
/** @var array of string */
62-
public $documents = array();
74+
private $documents = array();
6375

6476

6577
/** @return Method */
@@ -122,13 +134,6 @@ public function addBody($statement, array $args = NULL)
122134

123135

124136

125-
public function __call($name, $args)
126-
{
127-
return Nette\ObjectMixin::callProperty($this, $name, $args);
128-
}
129-
130-
131-
132137
/** @return string PHP code */
133138
public function __toString()
134139
{

src/PhpGenerator/Parameter.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,30 @@
2020
*
2121
* @author David Grudl
2222
*
23-
* @method Parameter setName(string $name)
24-
* @method Parameter setReference(bool $on)
25-
* @method Parameter setTypeHint(string $class)
26-
* @method Parameter setOptional(bool $on)
27-
* @method Parameter setDefaultValue(mixed $value)
23+
* @method Parameter setName(string)
24+
* @method string getName()
25+
* @method Parameter setReference(bool)
26+
* @method bool isReference()
27+
* @method Parameter setTypeHint(string)
28+
* @method string getTypeHint()
29+
* @method Parameter setOptional(bool)
30+
* @method bool isOptional()
31+
* @method Parameter setDefaultValue(mixed)
32+
* @method mixed getDefaultValue()
2833
*/
2934
class Parameter extends Nette\Object
3035
{
3136
/** @var string */
32-
public $name;
37+
private $name;
3338

3439
/** @var bool */
35-
public $reference;
40+
private $reference;
3641

3742
/** @var string */
38-
public $typeHint;
43+
private $typeHint;
3944

4045
/** @var bool */
41-
public $optional;
46+
private $optional;
4247

4348
/** @var mixed */
4449
public $defaultValue;
@@ -70,11 +75,4 @@ public static function from(\ReflectionParameter $from)
7075
return $param;
7176
}
7277

73-
74-
75-
public function __call($name, $args)
76-
{
77-
return Nette\ObjectMixin::callProperty($this, $name, $args);
78-
}
79-
8078
}

src/PhpGenerator/Property.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,34 @@
2020
*
2121
* @author David Grudl
2222
*
23-
* @method Property setName(string $name)
24-
* @method Property setValue(mixed $value)
25-
* @method Property setStatic(bool $on)
26-
* @method Property setVisibility(string $access)
27-
* @method Property addDocument(string $doc)
23+
* @method Property setName(string)
24+
* @method string getName()
25+
* @method Property setValue(mixed)
26+
* @method mixed getValue()
27+
* @method Property setStatic(bool)
28+
* @method bool isStatic()
29+
* @method Property setVisibility(string)
30+
* @method string getVisibility()
31+
* @method Property setDocuments(string[])
32+
* @method string[] getDocuments()
33+
* @method Property addDocument(string)
2834
*/
2935
class Property extends Nette\Object
3036
{
3137
/** @var string */
32-
public $name;
38+
private $name;
3339

3440
/** @var mixed */
3541
public $value;
3642

3743
/** @var bool */
38-
public $static;
44+
private $static;
3945

4046
/** @var string public|protected|private */
41-
public $visibility = 'public';
47+
private $visibility = 'public';
4248

4349
/** @var array of string */
44-
public $documents = array();
50+
private $documents = array();
4551

4652

4753
/** @return Property */
@@ -57,11 +63,4 @@ public static function from(\ReflectionProperty $from)
5763
return $prop;
5864
}
5965

60-
61-
62-
public function __call($name, $args)
63-
{
64-
return Nette\ObjectMixin::callProperty($this, $name, $args);
65-
}
66-
6766
}

0 commit comments

Comments
 (0)