@@ -66,7 +66,7 @@ class ClassType
66
66
* @param string|object
67
67
* @return static
68
68
*/
69
- public static function from ($ class )
69
+ public static function from ($ class ): self
70
70
{
71
71
if ($ class instanceof \ReflectionClass) {
72
72
trigger_error (__METHOD__ . '() accepts only class name or object. ' , E_USER_DEPRECATED );
@@ -77,20 +77,14 @@ public static function from($class)
77
77
}
78
78
79
79
80
- /**
81
- * @param string|NULL
82
- */
83
- public function __construct ($ name = NULL , PhpNamespace $ namespace = NULL )
80
+ public function __construct (string $ name = NULL , PhpNamespace $ namespace = NULL )
84
81
{
85
82
$ this ->setName ($ name );
86
83
$ this ->namespace = $ namespace ;
87
84
}
88
85
89
86
90
- /**
91
- * @return string PHP code
92
- */
93
- public function __toString ()
87
+ public function __toString (): string
94
88
{
95
89
$ traits = [];
96
90
foreach ($ this ->traits as $ trait => $ resolutions ) {
@@ -148,7 +142,7 @@ public function getNamespace()
148
142
* @param string|NULL
149
143
* @return static
150
144
*/
151
- public function setName ($ name )
145
+ public function setName ($ name ): self
152
146
{
153
147
if ($ name !== NULL && !Helpers::isIdentifier ($ name )) {
154
148
throw new Nette \InvalidArgumentException ("Value ' $ name' is not valid class name. " );
@@ -168,10 +162,9 @@ public function getName()
168
162
169
163
170
164
/**
171
- * @param string
172
165
* @return static
173
166
*/
174
- public function setType ($ type )
167
+ public function setType (string $ type ): self
175
168
{
176
169
if (!in_array ($ type , ['class ' , 'interface ' , 'trait ' ], TRUE )) {
177
170
throw new Nette \InvalidArgumentException ('Argument must be class|interface|trait. ' );
@@ -181,50 +174,39 @@ public function setType($type)
181
174
}
182
175
183
176
184
- /**
185
- * @return string
186
- */
187
- public function getType ()
177
+ public function getType (): string
188
178
{
189
179
return $ this ->type ;
190
180
}
191
181
192
182
193
183
/**
194
- * @param bool
195
184
* @return static
196
185
*/
197
- public function setFinal ($ state = TRUE )
186
+ public function setFinal (bool $ state = TRUE ): self
198
187
{
199
188
$ this ->final = (bool ) $ state ;
200
189
return $ this ;
201
190
}
202
191
203
192
204
- /**
205
- * @return bool
206
- */
207
- public function isFinal ()
193
+ public function isFinal (): bool
208
194
{
209
195
return $ this ->final ;
210
196
}
211
197
212
198
213
199
/**
214
- * @param bool
215
200
* @return static
216
201
*/
217
- public function setAbstract ($ state = TRUE )
202
+ public function setAbstract (bool $ state = TRUE ): self
218
203
{
219
204
$ this ->abstract = (bool ) $ state ;
220
205
return $ this ;
221
206
}
222
207
223
208
224
- /**
225
- * @return bool
226
- */
227
- public function isAbstract ()
209
+ public function isAbstract (): bool
228
210
{
229
211
return $ this ->abstract ;
230
212
}
@@ -234,7 +216,7 @@ public function isAbstract()
234
216
* @param string|string[]
235
217
* @return static
236
218
*/
237
- public function setExtends ($ types )
219
+ public function setExtends ($ types ): self
238
220
{
239
221
if (!is_string ($ types ) && !(is_array ($ types ) && Nette \Utils \Arrays::every ($ types , 'is_string ' ))) {
240
222
throw new Nette \InvalidArgumentException ('Argument must be string or string[]. ' );
@@ -254,10 +236,9 @@ public function getExtends()
254
236
255
237
256
238
/**
257
- * @param string
258
239
* @return static
259
240
*/
260
- public function addExtend ($ type )
241
+ public function addExtend (string $ type ): self
261
242
{
262
243
$ this ->extends = (array ) $ this ->extends ;
263
244
$ this ->extends [] = (string ) $ type ;
@@ -269,7 +250,7 @@ public function addExtend($type)
269
250
* @param string[]
270
251
* @return static
271
252
*/
272
- public function setImplements (array $ types )
253
+ public function setImplements (array $ types ): self
273
254
{
274
255
$ this ->implements = $ types ;
275
256
return $ this ;
@@ -279,17 +260,16 @@ public function setImplements(array $types)
279
260
/**
280
261
* @return string[]
281
262
*/
282
- public function getImplements ()
263
+ public function getImplements (): array
283
264
{
284
265
return $ this ->implements ;
285
266
}
286
267
287
268
288
269
/**
289
- * @param string
290
270
* @return static
291
271
*/
292
- public function addImplement ($ type )
272
+ public function addImplement (string $ type ): self
293
273
{
294
274
$ this ->implements [] = (string ) $ type ;
295
275
return $ this ;
@@ -300,7 +280,7 @@ public function addImplement($type)
300
280
* @param string[]
301
281
* @return static
302
282
*/
303
- public function setTraits (array $ traits )
283
+ public function setTraits (array $ traits ): self
304
284
{
305
285
$ this ->traits = array_fill_keys ($ traits , []);
306
286
return $ this ;
@@ -310,17 +290,16 @@ public function setTraits(array $traits)
310
290
/**
311
291
* @return string[]
312
292
*/
313
- public function getTraits ()
293
+ public function getTraits (): array
314
294
{
315
295
return array_keys ($ this ->traits );
316
296
}
317
297
318
298
319
299
/**
320
- * @param string
321
300
* @return static
322
301
*/
323
- public function addTrait ($ trait , array $ resolutions = [])
302
+ public function addTrait (string $ trait , array $ resolutions = []): self
324
303
{
325
304
$ this ->traits [$ trait ] = $ resolutions ;
326
305
return $ this ;
@@ -331,7 +310,7 @@ public function addTrait($trait, array $resolutions = [])
331
310
* @deprecated use setConstants()
332
311
* @return static
333
312
*/
334
- public function setConsts (array $ consts )
313
+ public function setConsts (array $ consts ): self
335
314
{
336
315
trigger_error (__METHOD__ . '() is deprecated, use setConstants() ' , E_USER_DEPRECATED );
337
316
return $ this ->setConstants ($ consts );
@@ -340,9 +319,8 @@ public function setConsts(array $consts)
340
319
341
320
/**
342
321
* @deprecated use getConstants()
343
- * @return array
344
322
*/
345
- public function getConsts ()
323
+ public function getConsts (): array
346
324
{
347
325
trigger_error (__METHOD__ . '() is deprecated, use similar getConstants() ' , E_USER_DEPRECATED );
348
326
return array_map (function ($ const ) { return $ const ->getValue (); }, $ this ->consts );
@@ -351,11 +329,9 @@ public function getConsts()
351
329
352
330
/**
353
331
* @deprecated use addConstant()
354
- * @param string
355
- * @param mixed
356
332
* @return static
357
333
*/
358
- public function addConst ($ name , $ value )
334
+ public function addConst (string $ name , $ value ): self
359
335
{
360
336
trigger_error (__METHOD__ . '() is deprecated, use similar addConstant() ' , E_USER_DEPRECATED );
361
337
$ this ->addConstant ($ name , $ value );
@@ -367,7 +343,7 @@ public function addConst($name, $value)
367
343
* @param Constant[]|mixed[]
368
344
* @return static
369
345
*/
370
- public function setConstants (array $ consts )
346
+ public function setConstants (array $ consts ): self
371
347
{
372
348
$ this ->consts = [];
373
349
foreach ($ consts as $ k => $ v ) {
@@ -381,18 +357,13 @@ public function setConstants(array $consts)
381
357
/**
382
358
* @return Constant[]
383
359
*/
384
- public function getConstants ()
360
+ public function getConstants (): array
385
361
{
386
362
return $ this ->consts ;
387
363
}
388
364
389
365
390
- /**
391
- * @param string
392
- * @param mixed
393
- * @return Constant
394
- */
395
- public function addConstant ($ name , $ value )
366
+ public function addConstant (string $ name , $ value ): Constant
396
367
{
397
368
return $ this ->consts [$ name ] = (new Constant ($ name ))->setValue ($ value );
398
369
}
@@ -402,7 +373,7 @@ public function addConstant($name, $value)
402
373
* @param Property[]
403
374
* @return static
404
375
*/
405
- public function setProperties (array $ props )
376
+ public function setProperties (array $ props ): self
406
377
{
407
378
$ this ->properties = [];
408
379
foreach ($ props as $ v ) {
@@ -418,16 +389,13 @@ public function setProperties(array $props)
418
389
/**
419
390
* @return Property[]
420
391
*/
421
- public function getProperties ()
392
+ public function getProperties (): array
422
393
{
423
394
return $ this ->properties ;
424
395
}
425
396
426
397
427
- /**
428
- * @return Property
429
- */
430
- public function getProperty ($ name )
398
+ public function getProperty ($ name ): Property
431
399
{
432
400
if (!isset ($ this ->properties [$ name ])) {
433
401
throw new Nette \InvalidArgumentException ("Property ' $ name' not found. " );
@@ -438,10 +406,8 @@ public function getProperty($name)
438
406
439
407
/**
440
408
* @param string without $
441
- * @param mixed
442
- * @return Property
443
409
*/
444
- public function addProperty ($ name , $ value = NULL )
410
+ public function addProperty (string $ name , $ value = NULL ): Property
445
411
{
446
412
return $ this ->properties [$ name ] = (new Property ($ name ))->setValue ($ value );
447
413
}
@@ -451,7 +417,7 @@ public function addProperty($name, $value = NULL)
451
417
* @param Method[]
452
418
* @return static
453
419
*/
454
- public function setMethods (array $ methods )
420
+ public function setMethods (array $ methods ): self
455
421
{
456
422
$ this ->methods = [];
457
423
foreach ($ methods as $ v ) {
@@ -467,16 +433,13 @@ public function setMethods(array $methods)
467
433
/**
468
434
* @return Method[]
469
435
*/
470
- public function getMethods ()
436
+ public function getMethods (): array
471
437
{
472
438
return $ this ->methods ;
473
439
}
474
440
475
441
476
- /**
477
- * @return Method
478
- */
479
- public function getMethod ($ name )
442
+ public function getMethod ($ name ): Method
480
443
{
481
444
if (!isset ($ this ->methods [$ name ])) {
482
445
throw new Nette \InvalidArgumentException ("Method ' $ name' not found. " );
@@ -485,11 +448,7 @@ public function getMethod($name)
485
448
}
486
449
487
450
488
- /**
489
- * @param string
490
- * @return Method
491
- */
492
- public function addMethod ($ name )
451
+ public function addMethod (string $ name ): Method
493
452
{
494
453
$ method = (new Method ($ name ))->setNamespace ($ this ->namespace );
495
454
if ($ this ->type === 'interface ' ) {
0 commit comments