Skip to content

Commit 20a094c

Browse files
committed
fixed inconsistencies between 'nullable string' and 'string' properties
1 parent 3182f5e commit 20a094c

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/PhpGenerator/Method.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class Method extends Nette\Object
1717
{
18-
/** @var string */
18+
/** @var string|NULL */
1919
private $name;
2020

2121
/** @var array of name => Parameter */
@@ -25,7 +25,7 @@ class Method extends Nette\Object
2525
private $uses = [];
2626

2727
/** @var string|FALSE */
28-
private $body;
28+
private $body = '';
2929

3030
/** @var bool */
3131
private $static = FALSE;
@@ -45,13 +45,13 @@ class Method extends Nette\Object
4545
/** @var bool */
4646
private $variadic = FALSE;
4747

48-
/** @var array of string */
48+
/** @var string[] */
4949
private $documents = [];
5050

5151
/** @var PhpNamespace|NULL */
5252
private $namespace;
5353

54-
/** @var string */
54+
/** @var string|NULL */
5555
private $returnType;
5656

5757

@@ -67,7 +67,7 @@ public static function from($from)
6767
$method->parameters[$param->getName()] = Parameter::from($param);
6868
}
6969
$method->static = $from->isStatic();
70-
$method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : '');
70+
$method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
7171
$method->final = $from->isFinal();
7272
$method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
7373
$method->body = $from->isAbstract() ? FALSE : '';
@@ -87,7 +87,7 @@ public static function from($from)
8787
*/
8888
public function __toString()
8989
{
90-
static $builtinTypes = ['array', 'self', 'parent', 'callable', 'string', 'bool', 'float', 'int', ''];
90+
static $builtinTypes = ['array', 'self', 'parent', 'callable', 'string', 'bool', 'float', 'int', NULL];
9191
$parameters = [];
9292
foreach ($this->parameters as $param) {
9393
$variadic = $this->variadic && $param === end($this->parameters);
@@ -105,7 +105,7 @@ public function __toString()
105105
foreach ($this->uses as $param) {
106106
$uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
107107
}
108-
$returnType = !$this->namespace || in_array($this->returnType, $builtinTypes)
108+
$returnType = !$this->namespace || in_array($this->returnType, $builtinTypes, TRUE)
109109
? $this->returnType
110110
: $this->namespace->unresolveName($this->returnType);
111111
return ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", $this->documents)) . "\n */\n" : '')
@@ -125,18 +125,18 @@ public function __toString()
125125

126126

127127
/**
128-
* @param string
128+
* @param string|NULL
129129
* @return self
130130
*/
131131
public function setName($name)
132132
{
133-
$this->name = (string) $name;
133+
$this->name = $name ? (string) $name : NULL;
134134
return $this;
135135
}
136136

137137

138138
/**
139-
* @return string
139+
* @return string|NULL
140140
*/
141141
public function getName()
142142
{
@@ -270,7 +270,7 @@ public function setVisibility($val)
270270
if (!in_array($val, ['public', 'protected', 'private', NULL], TRUE)) {
271271
throw new Nette\InvalidArgumentException('Argument must be public|protected|private|NULL.');
272272
}
273-
$this->visibility = (string) $val;
273+
$this->visibility = $val ? (string) $val : NULL;
274274
return $this;
275275
}
276276

@@ -405,18 +405,18 @@ public function setNamespace(PhpNamespace $val = NULL)
405405
}
406406

407407
/**
408-
* @param string
408+
* @param string|NULL
409409
* @return self
410410
*/
411411
public function setReturnType($val)
412412
{
413-
$this->returnType = (string) $val;
413+
$this->returnType = $val ? (string) $val : NULL;
414414
return $this;
415415
}
416416

417417

418418
/**
419-
* @return string
419+
* @return string|NULL
420420
*/
421421
public function getReturnType()
422422
{

src/PhpGenerator/Parameter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
class Parameter extends Nette\Object
1717
{
1818
/** @var string */
19-
private $name;
19+
private $name = '';
2020

2121
/** @var bool */
2222
private $reference = FALSE;
2323

24-
/** @var string */
24+
/** @var string|NULL */
2525
private $typeHint;
2626

2727
/** @var bool */
@@ -41,12 +41,12 @@ public static function from(\ReflectionParameter $from)
4141
$param->reference = $from->isPassedByReference();
4242
if (PHP_VERSION_ID >= 70000) {
4343
$type = $from->getType();
44-
$param->typeHint = !$type || $type->isBuiltin() ? (string) $type : '\\' . $type;
44+
$param->typeHint = $type ? ($type->isBuiltin() ? '' : '\\') . $type : NULL;
4545
} elseif ($from->isArray() || $from->isCallable()) {
4646
$param->typeHint = $from->isArray() ? 'array' : 'callable';
4747
} else {
4848
try {
49-
$param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : '';
49+
$param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : NULL;
5050
} catch (\ReflectionException $e) {
5151
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
5252
$param->typeHint = '\\' . $m[1];
@@ -108,18 +108,18 @@ public function isReference()
108108

109109

110110
/**
111-
* @param string
111+
* @param string|NULL
112112
* @return self
113113
*/
114114
public function setTypeHint($hint)
115115
{
116-
$this->typeHint = (string) $hint;
116+
$this->typeHint = $hint ? (string) $hint : NULL;
117117
return $this;
118118
}
119119

120120

121121
/**
122-
* @return string
122+
* @return string|NULL
123123
*/
124124
public function getTypeHint()
125125
{

src/PhpGenerator/Property.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Property extends Nette\Object
1717
{
1818
/** @var string */
19-
private $name;
19+
private $name = '';
2020

2121
/** @var mixed */
2222
public $value;
@@ -27,7 +27,7 @@ class Property extends Nette\Object
2727
/** @var string public|protected|private */
2828
private $visibility = 'public';
2929

30-
/** @var array of string */
30+
/** @var string[] */
3131
private $documents = [];
3232

3333

0 commit comments

Comments
 (0)