15
15
*
16
16
* @property string $body
17
17
*/
18
- class Method
18
+ class Method extends Member
19
19
{
20
- use Nette \SmartObject;
21
-
22
- /** @var string|NULL */
23
- private $ name ;
24
-
25
20
/** @var array of name => Parameter */
26
21
private $ parameters = [];
27
22
@@ -34,9 +29,6 @@ class Method
34
29
/** @var bool */
35
30
private $ static = FALSE ;
36
31
37
- /** @var string|NULL public|protected|private */
38
- private $ visibility ;
39
-
40
32
/** @var bool */
41
33
private $ final = FALSE ;
42
34
@@ -49,9 +41,6 @@ class Method
49
41
/** @var bool */
50
42
private $ variadic = FALSE ;
51
43
52
- /** @var string|NULL */
53
- private $ comment ;
54
-
55
44
/** @var PhpNamespace|NULL */
56
45
private $ namespace ;
57
46
@@ -82,14 +71,14 @@ public static function from($from)
82
71
if ($ from instanceof \ReflectionMethod) {
83
72
$ isInterface = $ from ->getDeclaringClass ()->isInterface ();
84
73
$ method ->static = $ from ->isStatic ();
85
- $ method ->visibility = $ from ->isPrivate () ? 'private ' : ($ from ->isProtected () ? 'protected ' : ($ isInterface ? NULL : 'public ' ));
74
+ $ method ->setVisibility ( $ from ->isPrivate () ? 'private ' : ($ from ->isProtected () ? 'protected ' : ($ isInterface ? NULL : 'public ' ) ));
86
75
$ method ->final = $ from ->isFinal ();
87
76
$ method ->abstract = $ from ->isAbstract () && !$ isInterface ;
88
77
$ method ->body = $ from ->isAbstract () ? FALSE : '' ;
89
78
}
90
79
$ method ->returnReference = $ from ->returnsReference ();
91
80
$ method ->variadic = $ from ->isVariadic ();
92
- $ method ->comment = Helpers::unformatDocComment ($ from ->getDocComment ());
81
+ $ method ->setComment ( Helpers::unformatDocComment ($ from ->getDocComment () ));
93
82
if (PHP_VERSION_ID >= 70000 && $ from ->hasReturnType ()) {
94
83
$ method ->returnType = (string ) $ from ->getReturnType ();
95
84
$ method ->returnNullable = $ from ->getReturnType ()->allowsNull ();
@@ -127,37 +116,20 @@ public function __toString()
127
116
$ uses [] = ($ param ->isReference () ? '& ' : '' ) . '$ ' . $ param ->getName ();
128
117
}
129
118
130
- return Helpers::formatDocComment ($ this ->comment . "\n" )
119
+ return Helpers::formatDocComment ($ this ->getComment () . "\n" )
131
120
. ($ this ->abstract ? 'abstract ' : '' )
132
121
. ($ this ->final ? 'final ' : '' )
133
- . ($ this ->visibility ? $ this ->visibility . ' ' : '' )
122
+ . ($ this ->getVisibility () ? $ this ->getVisibility () . ' ' : '' )
134
123
. ($ this ->static ? 'static ' : '' )
135
124
. 'function '
136
125
. ($ this ->returnReference ? '& ' : '' )
137
- . $ this ->name
126
+ . $ this ->getName ()
138
127
. '( ' . implode (', ' , $ parameters ) . ') '
139
128
. ($ this ->uses ? ' use ( ' . implode (', ' , $ uses ) . ') ' : '' )
140
129
. ($ this ->returnType ? ': ' . ($ this ->returnNullable ? '? ' : '' )
141
130
. ($ this ->namespace ? $ this ->namespace ->unresolveName ($ this ->returnType ) : $ this ->returnType ) : '' )
142
131
. ($ this ->abstract || $ this ->body === FALSE ? '; '
143
- : ($ this ->name ? "\n" : ' ' ) . "{ \n" . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 ) . '} ' );
144
- }
145
-
146
-
147
- /** @deprecated */
148
- public function setName ($ name )
149
- {
150
- $ this ->name = $ name ? (string ) $ name : NULL ;
151
- return $ this ;
152
- }
153
-
154
-
155
- /**
156
- * @return string|NULL
157
- */
158
- public function getName ()
159
- {
160
- return $ this ->name ;
132
+ : ($ this ->getName () ? "\n" : ' ' ) . "{ \n" . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 ) . '} ' );
161
133
}
162
134
163
135
@@ -278,29 +250,6 @@ public function isStatic()
278
250
}
279
251
280
252
281
- /**
282
- * @param string|NULL public|protected|private
283
- * @return static
284
- */
285
- public function setVisibility ($ val )
286
- {
287
- if (!in_array ($ val , ['public ' , 'protected ' , 'private ' , NULL ], TRUE )) {
288
- throw new Nette \InvalidArgumentException ('Argument must be public|protected|private|NULL. ' );
289
- }
290
- $ this ->visibility = $ val ? (string ) $ val : NULL ;
291
- return $ this ;
292
- }
293
-
294
-
295
- /**
296
- * @return string|NULL
297
- */
298
- public function getVisibility ()
299
- {
300
- return $ this ->visibility ;
301
- }
302
-
303
-
304
253
/**
305
254
* @param bool
306
255
* @return static
@@ -401,61 +350,6 @@ public function isVariadic()
401
350
}
402
351
403
352
404
- /**
405
- * @param string|NULL
406
- * @return static
407
- */
408
- public function setComment ($ val )
409
- {
410
- $ this ->comment = $ val ? (string ) $ val : NULL ;
411
- return $ this ;
412
- }
413
-
414
-
415
- /**
416
- * @return string|NULL
417
- */
418
- public function getComment ()
419
- {
420
- return $ this ->comment ;
421
- }
422
-
423
-
424
- /**
425
- * @param string
426
- * @return static
427
- */
428
- public function addComment ($ val )
429
- {
430
- $ this ->comment .= $ this ->comment ? "\n$ val " : $ val ;
431
- return $ this ;
432
- }
433
-
434
-
435
- /** @deprecated */
436
- public function setDocuments (array $ s )
437
- {
438
- trigger_error (__METHOD__ . '() is deprecated, use similar setComment() ' , E_USER_DEPRECATED );
439
- return $ this ->setComment (implode ("\n" , $ s ));
440
- }
441
-
442
-
443
- /** @deprecated */
444
- public function getDocuments ()
445
- {
446
- trigger_error (__METHOD__ . '() is deprecated, use similar getComment() ' , E_USER_DEPRECATED );
447
- return $ this ->comment ? [$ this ->comment ] : [];
448
- }
449
-
450
-
451
- /** @deprecated */
452
- public function addDocument ($ s )
453
- {
454
- trigger_error (__METHOD__ . '() is deprecated, use addComment() ' , E_USER_DEPRECATED );
455
- return $ this ->addComment ($ s );
456
- }
457
-
458
-
459
353
/**
460
354
* @return static
461
355
*/
0 commit comments