getOption('args'); $language = $input->getOption('language'); $workingDir = $input->getOption('working-dir'); if ($language === null) { $language = (new DetermineProjectLanguage( filesystem: $this->filesystem, workingDir: $workingDir, ))->getLanguage(); } assert( assertion: ProjectLanguage::isValid($language), description: sprintf('%s is not a supported language.', $language), ); // TODO: Composer in Docker Compose? $process = Process::create( args: explode(separator: ' ', string: strval($args)), command: $this->getCommand(language: $language, workingDir: $workingDir), workingDir: $workingDir, ); $process->setTimeout(null); $process->run(); return Command::SUCCESS; } /** * @param non-empty-string $language * @param non-empty-string $workingDir * @return non-empty-array * @throws RuntimeException If the lanuage cannot be determined. */ private function getCommand(string $language, string $workingDir): array { if ($language === ProjectLanguage::PHP->value) { return ['composer', 'install']; } elseif ($language === ProjectLanguage::JavaScript->value) { $packageManager = new DeterminePackageManager( filesystem: $this->filesystem, projectLanguage: $language, workingDir: $workingDir, ); switch ($packageManager->getPackageManager()) { case PackageManager::pnpm->value: return ['pnpm', 'install']; case PackageManager::yarn->value: return ['yarn']; default: return ['npm', 'install']; } } // TODO: add a test to ensure the exception is thrown? throw new RuntimeException('Project language cannot be determined.'); } }