1111
1212
1313/**
14- * Method or function description .
14+ * Class method .
1515 *
1616 * @property string|FALSE $body
1717 */
@@ -23,12 +23,6 @@ class Method
2323 use Traits \VisibilityAware;
2424 use Traits \CommentAware;
2525
26- /** @var Parameter[] */
27- private $ uses = [];
28-
29- /** @var string|FALSE */
30- private $ body = '' ;
31-
3226 /** @var bool */
3327 private $ static = FALSE ;
3428
@@ -51,15 +45,23 @@ public static function from($method)
5145 }
5246
5347
48+ /**
49+ * @param string
50+ */
51+ public function __construct ($ name = NULL )
52+ {
53+ if ($ name === NULL ) {
54+ throw new Nette \DeprecatedException ('For closures use Nette\PhpGenerator\GlobalFunction instead of Nette\PhpGenerator\Method. ' );
55+ }
56+ $ this ->setName ($ name );
57+ }
58+
59+
5460 /**
5561 * @return string PHP code
5662 */
5763 public function __toString ()
5864 {
59- $ uses = [];
60- foreach ($ this ->uses as $ param ) {
61- $ uses [] = ($ param ->isReference () ? '& ' : '' ) . '$ ' . $ param ->getName ();
62- }
6365 return Helpers::formatDocComment ($ this ->comment . "\n" )
6466 . ($ this ->abstract ? 'abstract ' : '' )
6567 . ($ this ->final ? 'final ' : '' )
@@ -69,38 +71,10 @@ public function __toString()
6971 . ($ this ->returnReference ? '& ' : '' )
7072 . $ this ->name
7173 . $ this ->parametersToString ()
72- . ($ this ->uses ? ' use ( ' . implode (', ' , $ uses ) . ') ' : '' )
7374 . $ this ->returnTypeToString ()
74- . ($ this ->abstract || $ this ->body === FALSE ? '; '
75- : ($ this ->name ? "\n" : ' ' ) . "{ \n" . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 ) . '} ' );
76- }
77-
78-
79- /**
80- * @return static
81- */
82- public function setUses (array $ val )
83- {
84- $ this ->uses = $ val ;
85- return $ this ;
86- }
87-
88-
89- /**
90- * @return array
91- */
92- public function getUses ()
93- {
94- return $ this ->uses ;
95- }
96-
97-
98- /**
99- * @return Parameter
100- */
101- public function addUse ($ name )
102- {
103- return $ this ->uses [] = new Parameter ($ name );
75+ . ($ this ->abstract || $ this ->body === FALSE
76+ ? '; '
77+ : "\n{ \n" . Nette \Utils \Strings::indent (ltrim (rtrim ($ this ->body ) . "\n" ), 1 ) . '} ' );
10478 }
10579
10680
@@ -124,17 +98,6 @@ public function getBody()
12498 }
12599
126100
127- /**
128- * @param string
129- * @return static
130- */
131- public function addBody ($ code , array $ args = NULL )
132- {
133- $ this ->body .= ($ args === NULL ? $ code : Helpers::formatArgs ($ code , $ args )) . "\n" ;
134- return $ this ;
135- }
136-
137-
138101 /**
139102 * @param bool
140103 * @return static
0 commit comments