@@ -37,7 +37,8 @@ final class Container
3737 private Filesystem $ filesystem ;
3838 private ConfigurationFactory $ configFactory ;
3939 private Parser $ parser ;
40- private ?PhpVersion $ phpVersion = null ;
40+ private ?PhpVersion $ parserPhpVersion = null ;
41+ private ?PhpVersion $ printerPhpVersion = null ;
4142 private Reflector $ reflector ;
4243 private ScoperFactory $ scoperFactory ;
4344 private EnrichedReflectorFactory $ enrichedReflectorFactory ;
@@ -82,20 +83,11 @@ public function getScoperFactory(?PhpVersion $phpVersion = null): ScoperFactory
8283 public function getParser (?PhpVersion $ phpVersion = null ): Parser
8384 {
8485 if (!isset ($ this ->parser )) {
85- $ this ->phpVersion = $ phpVersion ;
86+ $ this ->parserPhpVersion = $ phpVersion ;
8687 $ this ->parser = $ this ->createParser ($ phpVersion );
8788 }
8889
89- $ parserVersion = $ this ->phpVersion ;
90-
91- $ parserMessage = 'Cannot use the existing parser: its PHP version is different than the one requested. ' ;
92-
93- if (null === $ parserVersion ) {
94- Assert::null ($ phpVersion , $ parserMessage );
95- } else {
96- Assert::notNull ($ phpVersion , $ parserMessage );
97- Assert::true ($ parserVersion ->equals ($ phpVersion ), $ parserMessage );
98- }
90+ self ::checkSamePhpVersion ($ this ->parserPhpVersion , $ phpVersion );
9991
10092 return $ this ->parser ;
10193 }
@@ -130,14 +122,33 @@ public function getEnrichedReflectorFactory(): EnrichedReflectorFactory
130122 return $ this ->enrichedReflectorFactory ;
131123 }
132124
133- public function getPrinter (): Printer
125+ public function getPrinter (? PhpVersion $ phpVersion = null ): Printer
134126 {
135127 if (!isset ($ this ->printer )) {
128+ $ this ->printerPhpVersion = $ phpVersion ;
136129 $ this ->printer = new StandardPrinter (
137- new Standard (),
130+ new Standard ([
131+ 'phpVersion ' => $ phpVersion ,
132+ ]),
138133 );
139134 }
140135
136+ self ::checkSamePhpVersion ($ this ->printerPhpVersion , $ phpVersion );
137+
141138 return $ this ->printer ;
142139 }
140+
141+ private static function checkSamePhpVersion (
142+ ?PhpVersion $ versionUsed ,
143+ ?PhpVersion $ versionRequest ,
144+ ): void {
145+ $ parserMessage = 'Cannot use the existing parser: its PHP version is different than the one requested. ' ;
146+
147+ if (null === $ versionUsed ) {
148+ Assert::null ($ versionRequest , $ parserMessage );
149+ } else {
150+ Assert::notNull ($ versionRequest , $ parserMessage );
151+ Assert::true ($ versionUsed ->equals ($ versionRequest ), $ parserMessage );
152+ }
153+ }
143154}
0 commit comments