11
11
use phpDocumentor \Reflection \Location ;
12
12
use phpDocumentor \Reflection \Php \Class_ as ClassElement ;
13
13
use phpDocumentor \Reflection \Php \Factory \Reducer \Reducer ;
14
- use phpDocumentor \Reflection \Php \Expression ;
15
- use phpDocumentor \Reflection \Php \Expression \ExpressionPrinter ;
16
14
use phpDocumentor \Reflection \Php \ProjectFactoryStrategy ;
17
15
use phpDocumentor \Reflection \Php \StrategyContainer ;
18
16
use PhpParser \Modifiers ;
22
20
use PhpParser \PrettyPrinter \Standard as PrettyPrinter ;
23
21
use Webmozart \Assert \Assert ;
24
22
25
- use function is_string ;
26
-
27
23
final class ConstructorPromotion extends AbstractFactory
28
24
{
29
25
/** @param iterable<Reducer> $reducers */
@@ -80,11 +76,11 @@ private function promoteParameterToProperty(ContextStack $context, StrategyConta
80
76
->visibility ($ param )
81
77
->type ($ param ->type )
82
78
->docblock ($ param ->getDocComment ())
83
- ->default ($ this -> determineDefault ( $ param ) )
79
+ ->default ($ param -> default )
84
80
->readOnly ($ this ->readOnly ($ param ->flags ))
85
81
->static (false )
86
- ->startLocation (new Location ($ param ->getLine (), $ param -> getStartFilePos () ))
87
- ->endLocation (new Location ($ param ->getEndLine (), $ param -> getEndFilePos () ))
82
+ ->startLocation (new Location ($ param ->getLine ()))
83
+ ->endLocation (new Location ($ param ->getEndLine ()))
88
84
->hooks ($ param ->hooks ?? [])
89
85
->build ($ context );
90
86
@@ -99,24 +95,6 @@ private function promoteParameterToProperty(ContextStack $context, StrategyConta
99
95
$ methodContainer ->addProperty ($ property );
100
96
}
101
97
102
- private function determineDefault (Param $ value ): Expression |null
103
- {
104
- $ expression = $ value ->default !== null ? $ this ->valueConverter ->prettyPrintExpr ($ value ->default ) : null ;
105
- if ($ expression === null ) {
106
- return null ;
107
- }
108
-
109
- if ($ this ->valueConverter instanceof ExpressionPrinter) {
110
- $ expression = new Expression ($ expression , $ this ->valueConverter ->getParts ());
111
- }
112
-
113
- if (is_string ($ expression )) {
114
- $ expression = new Expression ($ expression , []);
115
- }
116
-
117
- return $ expression ;
118
- }
119
-
120
98
private function readOnly (int $ flags ): bool
121
99
{
122
100
return (bool ) ($ flags & Modifiers::READONLY ) === true ;
0 commit comments