@@ -26,19 +26,25 @@ final class PhpNamespace
2626 use Nette \SmartObject;
2727
2828 public const
29- NAME_NORMAL = 'n ' ,
30- NAME_FUNCTION = 'f ' ,
31- NAME_CONSTANT = 'c ' ;
29+ NameNormal = 'n ' ,
30+ NameFunction = 'f ' ,
31+ NameConstant = 'c ' ;
32+
33+ /** @deprecated */
34+ public const
35+ NAME_NORMAL = self ::NameNormal,
36+ NAME_FUNCTION = self ::NameFunction,
37+ NAME_CONSTANT = self ::NameConstant;
3238
3339 private string $ name ;
3440
3541 private bool $ bracketedSyntax = false ;
3642
3743 /** @var string[][] */
3844 private array $ aliases = [
39- self ::NAME_NORMAL => [],
40- self ::NAME_FUNCTION => [],
41- self ::NAME_CONSTANT => [],
45+ self ::NameNormal => [],
46+ self ::NameFunction => [],
47+ self ::NameConstant => [],
4248 ];
4349
4450 /** @var ClassLike[] */
@@ -91,21 +97,21 @@ public function getBracketedSyntax(): bool
9197 /**
9298 * @throws InvalidStateException
9399 */
94- public function addUse (string $ name , ?string $ alias = null , string $ of = self ::NAME_NORMAL ): static
100+ public function addUse (string $ name , ?string $ alias = null , string $ of = self ::NameNormal ): static
95101 {
96102 if (
97103 !Helpers::isNamespaceIdentifier ($ name , true )
98- || (Helpers::isIdentifier ($ name ) && isset (Helpers::KEYWORDS [strtolower ($ name )]))
104+ || (Helpers::isIdentifier ($ name ) && isset (Helpers::Keywords [strtolower ($ name )]))
99105 ) {
100106 throw new Nette \InvalidArgumentException ("Value ' $ name' is not valid class/function/constant name. " );
101107
102- } elseif ($ alias && (!Helpers::isIdentifier ($ alias ) || isset (Helpers::KEYWORDS [strtolower ($ alias )]))) {
108+ } elseif ($ alias && (!Helpers::isIdentifier ($ alias ) || isset (Helpers::Keywords [strtolower ($ alias )]))) {
103109 throw new Nette \InvalidArgumentException ("Value ' $ alias' is not valid alias. " );
104110 }
105111
106112 $ name = ltrim ($ name , '\\' );
107113 $ aliases = array_change_key_case ($ this ->aliases [$ of ]);
108- $ used = [self ::NAME_NORMAL => $ this ->classes , self ::NAME_FUNCTION => $ this ->functions , self ::NAME_CONSTANT => []][$ of ];
114+ $ used = [self ::NameNormal => $ this ->classes , self ::NameFunction => $ this ->functions , self ::NameConstant => []][$ of ];
109115
110116 if ($ alias === null ) {
111117 $ base = Helpers::extractShortName ($ name );
@@ -133,18 +139,18 @@ public function addUse(string $name, ?string $alias = null, string $of = self::N
133139
134140 public function addUseFunction (string $ name , ?string $ alias = null ): static
135141 {
136- return $ this ->addUse ($ name , $ alias , self ::NAME_FUNCTION );
142+ return $ this ->addUse ($ name , $ alias , self ::NameFunction );
137143 }
138144
139145
140146 public function addUseConstant (string $ name , ?string $ alias = null ): static
141147 {
142- return $ this ->addUse ($ name , $ alias , self ::NAME_CONSTANT );
148+ return $ this ->addUse ($ name , $ alias , self ::NameConstant );
143149 }
144150
145151
146152 /** @return string[] */
147- public function getUses (string $ of = self ::NAME_NORMAL ): array
153+ public function getUses (string $ of = self ::NameNormal ): array
148154 {
149155 asort ($ this ->aliases [$ of ]);
150156 return array_filter (
@@ -163,16 +169,16 @@ public function unresolveName(string $name): string
163169 }
164170
165171
166- public function resolveName (string $ name , string $ of = self ::NAME_NORMAL ): string
172+ public function resolveName (string $ name , string $ of = self ::NameNormal ): string
167173 {
168- if (isset (Helpers::KEYWORDS [strtolower ($ name )]) || $ name === '' ) {
174+ if (isset (Helpers::Keywords [strtolower ($ name )]) || $ name === '' ) {
169175 return $ name ;
170176 } elseif ($ name [0 ] === '\\' ) {
171177 return substr ($ name , 1 );
172178 }
173179
174180 $ aliases = array_change_key_case ($ this ->aliases [$ of ]);
175- if ($ of !== self ::NAME_NORMAL ) {
181+ if ($ of !== self ::NameNormal ) {
176182 return $ aliases [strtolower ($ name )]
177183 ?? $ this ->resolveName (Helpers::extractNamespace ($ name ) . '\\' ) . Helpers::extractShortName ($ name );
178184 }
@@ -184,21 +190,21 @@ public function resolveName(string $name, string $of = self::NAME_NORMAL): strin
184190 }
185191
186192
187- public function simplifyType (string $ type , string $ of = self ::NAME_NORMAL ): string
193+ public function simplifyType (string $ type , string $ of = self ::NameNormal ): string
188194 {
189195 return preg_replace_callback ('~[\w\x7f-\xff \\\\]+~ ' , fn ($ m ) => $ this ->simplifyName ($ m [0 ], $ of ), $ type );
190196 }
191197
192198
193- public function simplifyName (string $ name , string $ of = self ::NAME_NORMAL ): string
199+ public function simplifyName (string $ name , string $ of = self ::NameNormal ): string
194200 {
195- if (isset (Helpers::KEYWORDS [strtolower ($ name )]) || $ name === '' ) {
201+ if (isset (Helpers::Keywords [strtolower ($ name )]) || $ name === '' ) {
196202 return $ name ;
197203 }
198204
199205 $ name = ltrim ($ name , '\\' );
200206
201- if ($ of !== self ::NAME_NORMAL ) {
207+ if ($ of !== self ::NameNormal ) {
202208 foreach ($ this ->aliases [$ of ] as $ alias => $ original ) {
203209 if (strcasecmp ($ original , $ name ) === 0 ) {
204210 return $ alias ;
@@ -244,7 +250,7 @@ public function add(ClassLike $class): static
244250 $ lower = strtolower ($ name );
245251 if (isset ($ this ->classes [$ lower ]) && $ this ->classes [$ lower ] !== $ class ) {
246252 throw new Nette \InvalidStateException ("Cannot add ' $ name', because it already exists. " );
247- } elseif ($ orig = array_change_key_case ($ this ->aliases [self ::NAME_NORMAL ])[$ lower ] ?? null ) {
253+ } elseif ($ orig = array_change_key_case ($ this ->aliases [self ::NameNormal ])[$ lower ] ?? null ) {
248254 throw new Nette \InvalidStateException ("Name ' $ name' used already as alias for $ orig. " );
249255 }
250256
@@ -293,7 +299,7 @@ public function addFunction(string $name): GlobalFunction
293299 $ lower = strtolower ($ name );
294300 if (isset ($ this ->functions [$ lower ])) {
295301 throw new Nette \InvalidStateException ("Cannot add ' $ name', because it already exists. " );
296- } elseif ($ orig = array_change_key_case ($ this ->aliases [self ::NAME_FUNCTION ])[$ lower ] ?? null ) {
302+ } elseif ($ orig = array_change_key_case ($ this ->aliases [self ::NameFunction ])[$ lower ] ?? null ) {
297303 throw new Nette \InvalidStateException ("Name ' $ name' used already as alias for $ orig. " );
298304 }
299305
0 commit comments