Skip to content

Commit 7329ec2

Browse files
committed
refactoring
1 parent 0ba04ff commit 7329ec2

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ final class Helpers
2121

2222
public const PHP_IDENT = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
2323

24+
public const KEYWORDS = [
25+
// built-in types
26+
'string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'array' => 1, 'object' => 1,
27+
'callable' => 1, 'iterable' => 1, 'void' => 1, 'null' => 1, 'mixed' => 1, 'false' => 1,
28+
'never' => 1,
29+
30+
// class keywords
31+
'self' => 1, 'parent' => 1, 'static' => 1,
32+
];
33+
2434

2535
/** @deprecated use (new Nette\PhpGenerator\Dumper)->dump() */
2636
public static function dump($var): string

src/PhpGenerator/PhpNamespace.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ final class PhpNamespace
2626
{
2727
use Nette\SmartObject;
2828

29-
private const KEYWORDS = [
30-
'string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'array' => 1, 'object' => 1,
31-
'callable' => 1, 'iterable' => 1, 'void' => 1, 'self' => 1, 'parent' => 1, 'static' => 1,
32-
'mixed' => 1, 'null' => 1, 'false' => 1, 'never' => 1,
33-
];
34-
3529
/** @var string */
3630
private $name;
3731

@@ -137,7 +131,7 @@ public function unresolveType(string $type): string
137131

138132
public function unresolveName(string $name): string
139133
{
140-
if (isset(self::KEYWORDS[strtolower($name)]) || $name === '') {
134+
if (isset(Helpers::KEYWORDS[strtolower($name)]) || $name === '') {
141135
return $name;
142136
}
143137
$name = ltrim($name, '\\');

0 commit comments

Comments
 (0)