setDescription('Sets the version number'); $this->setHelp('This command generates the PhpMyAdmin\Version class based on the version number provided.'); $this->addArgument('version', InputArgument::REQUIRED, 'The version number'); } protected function execute(InputInterface $input, OutputInterface $output): int { /** @var string $version */ $version = $input->getArgument('version'); $generatedClass = $this->getGeneratedClass($version); if (! $this->writeGeneratedClassFile($generatedClass)) { return Command::FAILURE; } $output->writeln('PhpMyAdmin\Version class successfully generated!'); return Command::SUCCESS; } private function getGeneratedClass(string $version): string { // Do not allow any major below 5 $return = preg_match('/^([5-9]+)\.(\d{1,2})\.(\d{1,2})(-([a-z0-9]+))?$/', $version, $matches); if ($return === false || $return === 0) { throw new RangeException('The version number is in the wrong format: ' . $version); } return sprintf( self::$generatedClassTemplate, $matches[1], $matches[2], $matches[3], $matches[4] ?? '', $matches[5] ?? '', ($matches[5] ?? '') === 'dev' ? 'true' : 'false' ); } private function writeGeneratedClassFile(string $generatedClass): bool { $result = file_put_contents(ROOT_PATH . 'libraries/classes/Version.php', $generatedClass); return $result !== false; } }