1515 *
1616 * @property string $body
1717 */
18- class Method
18+ class Method extends Member
1919{
20- use Nette \SmartObject;
21-
22- /** @var string|NULL */
23- private $ name ;
24-
2520 /** @var array of name => Parameter */
2621 private $ parameters = [];
2722
@@ -34,9 +29,6 @@ class Method
3429 /** @var bool */
3530 private $ static = FALSE ;
3631
37- /** @var string|NULL public|protected|private */
38- private $ visibility ;
39-
4032 /** @var bool */
4133 private $ final = FALSE ;
4234
@@ -49,9 +41,6 @@ class Method
4941 /** @var bool */
5042 private $ variadic = FALSE ;
5143
52- /** @var string|NULL */
53- private $ comment ;
54-
5544 /** @var PhpNamespace|NULL */
5645 private $ namespace ;
5746
@@ -82,14 +71,14 @@ public static function from($from)
8271 if ($ from instanceof \ReflectionMethod) {
8372 $ isInterface = $ from ->getDeclaringClass ()->isInterface ();
8473 $ 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 ' ) ));
8675 $ method ->final = $ from ->isFinal ();
8776 $ method ->abstract = $ from ->isAbstract () && !$ isInterface ;
8877 $ method ->body = $ from ->isAbstract () ? FALSE : '' ;
8978 }
9079 $ method ->returnReference = $ from ->returnsReference ();
9180 $ method ->variadic = $ from ->isVariadic ();
92- $ method ->comment = Helpers::unformatDocComment ($ from ->getDocComment ());
81+ $ method ->setComment ( Helpers::unformatDocComment ($ from ->getDocComment () ));
9382 if (PHP_VERSION_ID >= 70000 && $ from ->hasReturnType ()) {
9483 $ method ->returnType = (string ) $ from ->getReturnType ();
9584 $ method ->returnNullable = $ from ->getReturnType ()->allowsNull ();
@@ -127,37 +116,20 @@ public function __toString()
127116 $ uses [] = ($ param ->isReference () ? '& ' : '' ) . '$ ' . $ param ->getName ();
128117 }
129118
130- return Helpers::formatDocComment ($ this ->comment . "\n" )
119+ return Helpers::formatDocComment ($ this ->getComment () . "\n" )
131120 . ($ this ->abstract ? 'abstract ' : '' )
132121 . ($ this ->final ? 'final ' : '' )
133- . ($ this ->visibility ? $ this ->visibility . ' ' : '' )
122+ . ($ this ->getVisibility () ? $ this ->getVisibility () . ' ' : '' )
134123 . ($ this ->static ? 'static ' : '' )
135124 . 'function '
136125 . ($ this ->returnReference ? '& ' : '' )
137- . $ this ->name
126+ . $ this ->getName ()
138127 . '( ' . implode (', ' , $ parameters ) . ') '
139128 . ($ this ->uses ? ' use ( ' . implode (', ' , $ uses ) . ') ' : '' )
140129 . ($ this ->returnType ? ': ' . ($ this ->returnNullable ? '? ' : '' )
141130 . ($ this ->namespace ? $ this ->namespace ->unresolveName ($ this ->returnType ) : $ this ->returnType ) : '' )
142131 . ($ 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 ) . '} ' );
161133 }
162134
163135
@@ -278,29 +250,6 @@ public function isStatic()
278250 }
279251
280252
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-
304253 /**
305254 * @param bool
306255 * @return static
@@ -401,61 +350,6 @@ public function isVariadic()
401350 }
402351
403352
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-
459353 /**
460354 * @return static
461355 */
0 commit comments