@@ -24,17 +24,27 @@ final class ComposerPhpVersionFactory
2424
2525 private ?PhpVersion $ maxVersion = null ;
2626
27+ private bool $ initialized = false ;
28+
2729 /**
2830 * @param string[] $composerAutoloaderProjectPaths
2931 * @param int|array{min: int, max: int}|null $phpVersion
3032 */
3133 public function __construct (
3234 private array $ composerAutoloaderProjectPaths ,
33- int |array |null $ phpVersion ,
35+ private int |array |null $ phpVersion ,
3436 )
3537 {
38+ }
39+
40+ private function initVersions (): void
41+ {
42+ $ this ->initialized = true ;
43+
44+ $ phpVersion = $ this ->phpVersion ;
45+
3646 if (is_int ($ phpVersion )) {
37- return ;
47+ throw new ShouldNotHappenException () ;
3848 }
3949
4050 if (is_array ($ phpVersion )) {
@@ -73,11 +83,27 @@ public function __construct(
7383
7484 public function getMinVersion (): ?PhpVersion
7585 {
86+ if (is_int ($ this ->phpVersion )) {
87+ return null ;
88+ }
89+
90+ if ($ this ->initialized === false ) {
91+ $ this ->initVersions ();
92+ }
93+
7694 return $ this ->minVersion ;
7795 }
7896
7997 public function getMaxVersion (): ?PhpVersion
8098 {
99+ if (is_int ($ this ->phpVersion )) {
100+ return null ;
101+ }
102+
103+ if ($ this ->initialized === false ) {
104+ $ this ->initVersions ();
105+ }
106+
81107 return $ this ->maxVersion ;
82108 }
83109
0 commit comments