55
66use Composer \Semver \Semver ;
77use MyOnlineStore \DevTools \Command \DevToolsCommand ;
8+ use Symfony \Component \Process \Process ;
89
910final class Configuration
1011{
@@ -20,6 +21,7 @@ final class Configuration
2021 private ?array $ phpVersions = null ;
2122
2223 private string $ rootDir ;
24+ private ?string $ threads = null ;
2325
2426 public function __construct ()
2527 {
@@ -40,6 +42,55 @@ public function __construct()
4042 throw new \RuntimeException ('Unable to determine project root ' );
4143 }
4244
45+ /**
46+ * @return array<string, class-string<DevToolsCommand>>
47+ */
48+ public function getEnabledTools (): array
49+ {
50+ if (null === $ this ->enabledTools ) {
51+ $ this ->enabledTools = $ this ->gatherEnabledTools ();
52+ }
53+
54+ return $ this ->enabledTools ;
55+ }
56+
57+ /**
58+ * @return list<string>
59+ */
60+ public function getPhpVersions (): array
61+ {
62+ if (null === $ this ->phpVersions ) {
63+ $ this ->phpVersions = $ this ->gatherPhpVersions ();
64+ }
65+
66+ return $ this ->phpVersions ;
67+ }
68+
69+ public function getRootDir (): string
70+ {
71+ return $ this ->rootDir ;
72+ }
73+
74+ public function getThreads (): string
75+ {
76+ if (null === $ this ->threads ) {
77+ $ this ->threads = $ this ->determineThreads ();
78+ }
79+
80+ return $ this ->threads ;
81+ }
82+
83+ private function determineThreads (): string
84+ {
85+ return \trim (
86+ match (\php_uname ('s ' )) {
87+ 'Linux ' => Process::fromShellCommandline ('nproc ' )->mustRun ()->getOutput (),
88+ 'Darwin ' => Process::fromShellCommandline ('sysctl -n hw.logicalcpu ' )->mustRun ()->getOutput (),
89+ default => '2 ' ,
90+ }
91+ );
92+ }
93+
4394 /**
4495 * @return list<string>
4596 */
@@ -111,33 +162,4 @@ private function gatherEnabledTools(): array
111162
112163 return $ enabledTools ;
113164 }
114-
115- /**
116- * @return array<string, class-string<DevToolsCommand>>
117- */
118- public function getEnabledTools (): array
119- {
120- if (null === $ this ->enabledTools ) {
121- $ this ->enabledTools = $ this ->gatherEnabledTools ();
122- }
123-
124- return $ this ->enabledTools ;
125- }
126-
127- /**
128- * @return list<string>
129- */
130- public function getPhpVersions (): array
131- {
132- if (null === $ this ->phpVersions ) {
133- $ this ->phpVersions = $ this ->gatherPhpVersions ();
134- }
135-
136- return $ this ->phpVersions ;
137- }
138-
139- public function getRootDir (): string
140- {
141- return $ this ->rootDir ;
142- }
143165}
0 commit comments