22declare (strict_types=1 );
33namespace PHPJava \Compiler \Lang \Assembler \Traits ;
44
5+ use phpDocumentor \Reflection \DocBlock \Tags \Param ;
6+ use phpDocumentor \Reflection \DocBlock \Tags \TagWithType ;
57use PHPJava \Compiler \Builder \Attributes \Architects \Operation ;
68use PHPJava \Compiler \Builder \Finder \ConstantPoolFinder ;
79use PHPJava \Compiler \Lang \Assembler \Enhancer \ConstantPoolEnhancer ;
@@ -49,37 +51,11 @@ public function parseParameterFromNode(Node $node): array
4951 $ documentBlock = \phpDocumentor \Reflection \DocBlockFactory::createInstance ()
5052 ->create ($ commentAttribute ->getText ());
5153
52- foreach ($ documentBlock ->getTagsByName ('param ' ) as $ documentParameter ) {
54+ foreach ($ documentBlock ->getTagsByName ('param ' ) as $ documentedParameter ) {
5355 /**
54- * @var \phpDocumentor\Reflection\DocBlock\Tags\Param $documentParameter
55- * @var null|\phpDocumentor\Reflection\Types\Object_ $typeObject
56+ * @var Param $documentedParameter
5657 */
57- $ typeObject = $ documentParameter
58- ->getType ();
59- $ stringifiedType = (string ) $ typeObject ;
60-
61- $ type = $ stringifiedType ;
62-
63- if ($ typeObject instanceof \phpDocumentor \Reflection \Types \Array_) {
64- $ typeObject = $ typeObject
65- ->getValueType ();
66- }
67-
68- if ($ typeObject instanceof \phpDocumentor \Reflection \Types \Object_) {
69- $ fullPath = (string ) $ typeObject ->getFqsen ();
70-
71- $ type = $ typeObject
72- ->getFqsen ()
73- ->getName ();
74-
75- // FIXED: phpDocumentor has an omitted path completion problem
76- // This statement fix it.
77- if ($ fullPath !== '\\' . ((string ) $ type )) {
78- $ type = $ fullPath ;
79- }
80- }
81-
82- $ variableName = $ documentParameter ->getVariableName ();
58+ [$ variableName , $ parameterInfo ] = $ this ->parseFromDocument ($ documentedParameter );
8359
8460 if (!isset ($ paramOrdersTable [$ variableName ])) {
8561 throw new AssembleStructureException (
@@ -88,25 +64,9 @@ public function parseParameterFromNode(Node $node): array
8864 }
8965
9066 // Update variable detail.
91- $ parameters [$ variableName ] = [
92- 'type ' => $ this ->convertWithImport (
93- Formatter::convertPHPPrimitiveTypeToJavaType (
94- str_replace (
95- '[] ' ,
96- '' ,
97- $ type
98- )
99- )
100- ),
101- 'dimensions_of_array ' => substr_count (
102- $ stringifiedType ,
103- '[] '
104- ),
67+ $ parameters [$ variableName ] = $ parameterInfo + [
10568 'order ' => $ paramOrdersTable [$ variableName ],
10669 ];
107-
108- $ definedType = $ parameters [$ variableName ]['type ' ];
109- $ definedTypeDimensionsOfArray = $ parameters [$ variableName ]['dimensions_of_array ' ];
11070 }
11171 }
11272
@@ -137,4 +97,59 @@ static function ($a, $b) {
13797
13898 return $ parameters ;
13999 }
100+
101+ public function parseFromDocument (TagWithType $ documentedParameter ): array
102+ {
103+ /**
104+ * @var null|\phpDocumentor\Reflection\Types\Object_ $typeObject
105+ */
106+ $ typeObject = $ documentedParameter
107+ ->getType ();
108+ $ stringifiedType = (string ) $ typeObject ;
109+
110+ $ type = $ stringifiedType ;
111+
112+ if ($ typeObject instanceof \phpDocumentor \Reflection \Types \Array_) {
113+ $ typeObject = $ typeObject
114+ ->getValueType ();
115+ }
116+
117+ if ($ typeObject instanceof \phpDocumentor \Reflection \Types \Object_) {
118+ $ fullPath = (string ) $ typeObject ->getFqsen ();
119+
120+ $ type = $ typeObject
121+ ->getFqsen ()
122+ ->getName ();
123+
124+ // FIXED: phpDocumentor has an omitted path completion problem
125+ // This statement fix it.
126+ if ($ fullPath !== '\\' . ((string ) $ type )) {
127+ $ type = $ fullPath ;
128+ }
129+ }
130+
131+ $ variableName = $ documentedParameter ->getVariableName ();
132+
133+ // Update variable detail.
134+ return [
135+ $ variableName === ''
136+ ? null
137+ : $ variableName ,
138+ [
139+ 'type ' => $ this ->convertWithImport (
140+ Formatter::convertPHPPrimitiveTypeToJavaType (
141+ str_replace (
142+ '[] ' ,
143+ '' ,
144+ $ type
145+ )
146+ )
147+ ),
148+ 'dimensions_of_array ' => substr_count (
149+ $ stringifiedType ,
150+ '[] '
151+ ),
152+ ],
153+ ];
154+ }
140155}
0 commit comments