55use Krlove \Generator \Collection \LineCollection ;
66use Krlove \Generator \Collection \RenderableCollection ;
77use Krlove \Generator \Line \Line ;
8+ use Krlove \Generator \Model \Traits \DocBlockTrait ;
89use Krlove \Generator \Model \Traits \ModifierTrait ;
910use Krlove \Generator \RenderableInterface ;
1011
1617class MethodModel implements RenderableInterface
1718{
1819 use ModifierTrait;
20+ use DocBlockTrait;
1921
2022 /**
2123 * @var string
@@ -33,12 +35,14 @@ class MethodModel implements RenderableInterface
3335 protected $ body ;
3436
3537 /**
36- * PHPClassMethod constructor.
38+ * MethodModel constructor.
3739 * @param string $name
40+ * @param string $modifier
3841 */
39- public function __construct ($ name )
42+ public function __construct ($ name, $ modifier = ' public ' )
4043 {
41- $ this ->setName ($ name );
44+ $ this ->setName ($ name )
45+ ->setModifier ($ modifier );
4246
4347 $ this ->arguments = new RenderableCollection ();
4448 }
@@ -49,18 +53,21 @@ public function __construct($name)
4953 public function render ()
5054 {
5155 $ lines = new LineCollection ();
52- $ output = sprintf ('%s function %s( ' , $ this ->modifier , $ this ->name );
56+ if ($ this ->docBlock !== null ) {
57+ $ lines [] = $ this ->docBlock ->render ();
58+ }
59+ $ function = sprintf ('%s function %s( ' , $ this ->modifier , $ this ->name );
5360 if ($ this ->arguments ) {
5461 $ arguments = [];
5562 foreach ($ this ->arguments as $ argument ) {
5663 $ arguments [] = $ argument ->render ();
5764 }
5865
59- $ output .= implode (', ' , $ arguments );
66+ $ function .= implode (', ' , $ arguments );
6067 }
61- $ output .= ') ' ;
68+ $ function .= ') ' ;
6269
63- $ lines [] = new Line ($ output );
70+ $ lines [] = new Line ($ function );
6471 $ lines [] = new Line ('{ ' );
6572 if ($ this ->body ) {
6673 $ lines [] = new Line ($ this ->body ); // todo make body renderable
0 commit comments