Skip to content

Commit 4f4af9a

Browse files
committed
getType(), getReturnType(): added option $asObject that returns Nette\Utils\Type
(requires nette/utils 3.2.5)
1 parent a1f31b4 commit 4f4af9a

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/PhpGenerator/Parameter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Nette\PhpGenerator;
1111

1212
use Nette;
13+
use Nette\Utils\Type;
1314

1415

1516
/**
@@ -61,9 +62,14 @@ public function setType(?string $type): self
6162
}
6263

6364

64-
public function getType(): ?string
65+
/**
66+
* @return Type|string|null
67+
*/
68+
public function getType(bool $asObject = false)
6569
{
66-
return $this->type;
70+
return $asObject && $this->type
71+
? Type::fromString($this->type)
72+
: $this->type;
6773
}
6874

6975

src/PhpGenerator/Property.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Nette\PhpGenerator;
1111

1212
use Nette;
13+
use Nette\Utils\Type;
1314

1415

1516
/**
@@ -81,9 +82,14 @@ public function setType(?string $type): self
8182
}
8283

8384

84-
public function getType(): ?string
85+
/**
86+
* @return Type|string|null
87+
*/
88+
public function getType(bool $asObject = false)
8589
{
86-
return $this->type;
90+
return $asObject && $this->type
91+
? Type::fromString($this->type)
92+
: $this->type;
8793
}
8894

8995

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Nette;
1313
use Nette\PhpGenerator\Dumper;
1414
use Nette\PhpGenerator\Parameter;
15+
use Nette\Utils\Type;
1516

1617

1718
/**
@@ -130,9 +131,14 @@ public function setReturnType(?string $type): self
130131
}
131132

132133

133-
public function getReturnType(): ?string
134+
/**
135+
* @return Type|string|null
136+
*/
137+
public function getReturnType(bool $asObject = false)
134138
{
135-
return $this->returnType;
139+
return $asObject && $this->returnType
140+
? Type::fromString($this->returnType)
141+
: $this->returnType;
136142
}
137143

138144

0 commit comments

Comments
 (0)