@@ -26,9 +26,14 @@ 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+ public const
34+ NAME_NORMAL = self ::NameNormal,
35+ NAME_FUNCTION = self ::NameFunction,
36+ NAME_CONSTANT = self ::NameConstant;
3237
3338 /** @var string */
3439 private $ name ;
@@ -38,9 +43,9 @@ final class PhpNamespace
3843
3944 /** @var string[][] */
4045 private $ aliases = [
41- self ::NAME_NORMAL => [],
42- self ::NAME_FUNCTION => [],
43- self ::NAME_CONSTANT => [],
46+ self ::NameNormal => [],
47+ self ::NameFunction => [],
48+ self ::NameConstant => [],
4449 ];
4550
4651 /** @var ClassType[] */
@@ -94,21 +99,21 @@ public function getBracketedSyntax(): bool
9499 * @throws InvalidStateException
95100 * @return static
96101 */
97- public function addUse (string $ name , ?string $ alias = null , string $ of = self ::NAME_NORMAL ): self
102+ public function addUse (string $ name , ?string $ alias = null , string $ of = self ::NameNormal ): self
98103 {
99104 if (
100105 !Helpers::isNamespaceIdentifier ($ name , true )
101- || (Helpers::isIdentifier ($ name ) && isset (Helpers::KEYWORDS [strtolower ($ name )]))
106+ || (Helpers::isIdentifier ($ name ) && isset (Helpers::Keywords [strtolower ($ name )]))
102107 ) {
103108 throw new Nette \InvalidArgumentException ("Value ' $ name' is not valid class/function/constant name. " );
104109
105- } elseif ($ alias && (!Helpers::isIdentifier ($ alias ) || isset (Helpers::KEYWORDS [strtolower ($ alias )]))) {
110+ } elseif ($ alias && (!Helpers::isIdentifier ($ alias ) || isset (Helpers::Keywords [strtolower ($ alias )]))) {
106111 throw new Nette \InvalidArgumentException ("Value ' $ alias' is not valid alias. " );
107112 }
108113
109114 $ name = ltrim ($ name , '\\' );
110115 $ aliases = array_change_key_case ($ this ->aliases [$ of ]);
111- $ used = [self ::NAME_NORMAL => $ this ->classes , self ::NAME_FUNCTION => $ this ->functions , self ::NAME_CONSTANT => []][$ of ];
116+ $ used = [self ::NameNormal => $ this ->classes , self ::NameFunction => $ this ->functions , self ::NameConstant => []][$ of ];
112117
113118 if ($ alias === null ) {
114119 $ base = Helpers::extractShortName ($ name );
@@ -137,19 +142,19 @@ public function addUse(string $name, ?string $alias = null, string $of = self::N
137142 /** @return static */
138143 public function addUseFunction (string $ name , ?string $ alias = null ): self
139144 {
140- return $ this ->addUse ($ name , $ alias , self ::NAME_FUNCTION );
145+ return $ this ->addUse ($ name , $ alias , self ::NameFunction );
141146 }
142147
143148
144149 /** @return static */
145150 public function addUseConstant (string $ name , ?string $ alias = null ): self
146151 {
147- return $ this ->addUse ($ name , $ alias , self ::NAME_CONSTANT );
152+ return $ this ->addUse ($ name , $ alias , self ::NameConstant );
148153 }
149154
150155
151156 /** @return string[] */
152- public function getUses (string $ of = self ::NAME_NORMAL ): array
157+ public function getUses (string $ of = self ::NameNormal ): array
153158 {
154159 asort ($ this ->aliases [$ of ]);
155160 return array_filter (
@@ -167,16 +172,16 @@ public function unresolveName(string $name): string
167172 }
168173
169174
170- public function resolveName (string $ name , string $ of = self ::NAME_NORMAL ): string
175+ public function resolveName (string $ name , string $ of = self ::NameNormal ): string
171176 {
172- if (isset (Helpers::KEYWORDS [strtolower ($ name )]) || $ name === '' ) {
177+ if (isset (Helpers::Keywords [strtolower ($ name )]) || $ name === '' ) {
173178 return $ name ;
174179 } elseif ($ name [0 ] === '\\' ) {
175180 return substr ($ name , 1 );
176181 }
177182
178183 $ aliases = array_change_key_case ($ this ->aliases [$ of ]);
179- if ($ of !== self ::NAME_NORMAL ) {
184+ if ($ of !== self ::NameNormal ) {
180185 return $ aliases [strtolower ($ name )]
181186 ?? $ this ->resolveName (Helpers::extractNamespace ($ name ) . '\\' ) . Helpers::extractShortName ($ name );
182187 }
@@ -188,21 +193,21 @@ public function resolveName(string $name, string $of = self::NAME_NORMAL): strin
188193 }
189194
190195
191- public function simplifyType (string $ type , string $ of = self ::NAME_NORMAL ): string
196+ public function simplifyType (string $ type , string $ of = self ::NameNormal ): string
192197 {
193198 return preg_replace_callback ('~[\w\x7f-\xff \\\\]+~ ' , function ($ m ) use ($ of ) { return $ this ->simplifyName ($ m [0 ], $ of ); }, $ type );
194199 }
195200
196201
197- public function simplifyName (string $ name , string $ of = self ::NAME_NORMAL ): string
202+ public function simplifyName (string $ name , string $ of = self ::NameNormal ): string
198203 {
199- if (isset (Helpers::KEYWORDS [strtolower ($ name )]) || $ name === '' ) {
204+ if (isset (Helpers::Keywords [strtolower ($ name )]) || $ name === '' ) {
200205 return $ name ;
201206 }
202207
203208 $ name = ltrim ($ name , '\\' );
204209
205- if ($ of !== self ::NAME_NORMAL ) {
210+ if ($ of !== self ::NameNormal ) {
206211 foreach ($ this ->aliases [$ of ] as $ alias => $ original ) {
207212 if (strcasecmp ($ original , $ name ) === 0 ) {
208213 return $ alias ;
@@ -247,7 +252,7 @@ public function add(ClassType $class): self
247252 }
248253
249254 $ lower = strtolower ($ name );
250- if ($ orig = array_change_key_case ($ this ->aliases [self ::NAME_NORMAL ])[$ lower ] ?? null ) {
255+ if ($ orig = array_change_key_case ($ this ->aliases [self ::NameNormal ])[$ lower ] ?? null ) {
251256 throw new Nette \InvalidStateException ("Name ' $ name' used already as alias for $ orig. " );
252257 }
253258
@@ -291,7 +296,7 @@ public function removeClass(string $name): self
291296 public function addFunction (string $ name ): GlobalFunction
292297 {
293298 $ lower = strtolower ($ name );
294- if ($ orig = array_change_key_case ($ this ->aliases [self ::NAME_FUNCTION ])[$ lower ] ?? null ) {
299+ if ($ orig = array_change_key_case ($ this ->aliases [self ::NameFunction ])[$ lower ] ?? null ) {
295300 throw new Nette \InvalidStateException ("Name ' $ name' used already as alias for $ orig. " );
296301 }
297302
0 commit comments