99use PhpParser \Node \Param ;
1010use PhpParser \Node \Stmt \ClassMethod ;
1111use RonasIT \Larabuilder \Contracts \InsertNodeContract ;
12+ use RonasIT \Larabuilder \DTO \MethodParamDTO ;
13+ use RonasIT \Larabuilder \DTO \MethodParamsList ;
1214use RonasIT \Larabuilder \Enums \AccessModifierEnum ;
1315use RonasIT \Larabuilder \Enums \DefaultValue ;
1416use RonasIT \Larabuilder \Exceptions \NodeAlreadyExistsException ;
1517use RonasIT \Larabuilder \Nodes \PreformattedCode ;
16- use RonasIT \Larabuilder \ValueOptions \MethodParam ;
17- use RonasIT \Larabuilder \ValueOptions \MethodParams ;
1818
19- class AddMethod extends AbstractMethodVisitor implements InsertNodeContract
19+ class AddMethod extends BaseMethodVisitor implements InsertNodeContract
2020{
2121 protected PreformattedCode $ code ;
2222
2323 public function __construct (
2424 protected string $ name ,
2525 string $ code ,
26- protected MethodParams $ params ,
26+ protected MethodParamsList $ paramsList ,
2727 protected ?string $ returnType = null ,
28- protected ? AccessModifierEnum $ accessModifier = null ,
29- protected bool $ static = false ,
30- protected bool $ returnsByRef = false ,
28+ protected AccessModifierEnum $ accessModifier = AccessModifierEnum::Public ,
29+ protected bool $ isStatic = false ,
30+ protected bool $ isReturnsByRef = false ,
3131 ) {
3232 $ this ->code = new PreformattedCode ($ code );
3333 }
@@ -45,29 +45,29 @@ protected function modify(Node $node): Node
4545
4646 public function getInsertableNode (): Node
4747 {
48- $ flags = ( $ this ->accessModifier ?? AccessModifierEnum::Public) ->value ;
48+ $ flags = $ this ->accessModifier ->value ;
4949
50- if ($ this ->static ) {
50+ if ($ this ->isStatic ) {
5151 $ flags |= Modifiers::STATIC ;
5252 }
5353
5454 return new ClassMethod ($ this ->name , [
5555 'flags ' => $ flags ,
56- 'byRef ' => $ this ->returnsByRef ,
56+ 'byRef ' => $ this ->isReturnsByRef ,
5757 'params ' => $ this ->buildParams (),
58- 'returnType ' => $ this ->returnType !== null ? BuilderHelpers::normalizeType ($ this ->returnType ) : null ,
58+ 'returnType ' => (! is_null ( $ this ->returnType )) ? BuilderHelpers::normalizeType ($ this ->returnType ) : null ,
5959 'stmts ' => [$ this ->code ],
6060 ]);
6161 }
6262
6363 protected function buildParams (): array
6464 {
65- return array_map (fn (MethodParam $ param ) => new Param (
65+ return array_map (fn (MethodParamDTO $ param ) => new Param (
6666 var: new Variable ($ param ->name ),
67- default: $ param ->default !== DefaultValue::None ? BuilderHelpers::normalizeValue ($ param ->default ) : null ,
68- type: $ param ->type !== null ? BuilderHelpers::normalizeType ($ param ->type ) : null ,
69- byRef: $ param ->byRef ,
70- variadic: $ param ->variadic ,
71- ), $ this ->params -> params );
67+ default: ( $ param ->default !== DefaultValue::None) ? BuilderHelpers::normalizeValue ($ param ->default ) : null ,
68+ type: (! is_null ( $ param ->type )) ? BuilderHelpers::normalizeType ($ param ->type ) : null ,
69+ byRef: $ param ->isReference ,
70+ variadic: $ param ->isVariadic ,
71+ ), $ this ->paramsList -> toArray () );
7272 }
7373}
0 commit comments