diff --git a/projects/packages/changelogger/src/CommandLoader.php b/projects/packages/changelogger/src/CommandLoader.php index 2b82457a48979..ce84c8f45fa56 100644 --- a/projects/packages/changelogger/src/CommandLoader.php +++ b/projects/packages/changelogger/src/CommandLoader.php @@ -1,14 +1,98 @@ get_class_name( $name ) ); + } + + /** + * Loads a command. + * + * @param string $name Command name. + * @return Command + * @throws CommandNotFoundException If the command is not found. + */ + protected function doGet( $name ) { + $class = $this->get_class_name( $name ); + if ( ! class_exists( $class ) ) { + throw new CommandNotFoundException( "Command \"$name\" does not exist." ); + } + return new $class(); + } + + /** + * Return all command names. + * + * @return string[] All registered command names + */ + protected function doGetNames() { + $names = array(); + foreach ( new \DirectoryIterator( __DIR__ ) as $file ) { + if ( substr( $file->getBasename(), -11 ) === 'Command.php' ) { + $names[] = lcfirst( substr( $file->getBasename(), 0, -11 ) ); + } + } + sort( $names ); + return $names; + } + + /** + * Checks if a command exists. + * + * @param string $name Command name. + * @return bool + */ + public function has( $name ): bool { + return $this->doHas( $name ); + } + + /** + * Loads a command. + * + * @param string $name Command name. + * @return Command + * @throws CommandNotFoundException If the command is not found. + */ + public function get( $name ): Command { + return $this->doGet( $name ); + } -class_alias( php7\CommandLoader::class, CommandLoader::class ); + /** + * Return all command names. + * + * @return string[] All registered command names + */ + public function getNames(): array { + return $this->doGetNames(); + } +} diff --git a/projects/packages/changelogger/src/CommandLoaderBase.php b/projects/packages/changelogger/src/CommandLoaderBase.php index afb7ad15af065..4f81887809884 100644 --- a/projects/packages/changelogger/src/CommandLoaderBase.php +++ b/projects/packages/changelogger/src/CommandLoaderBase.php @@ -5,66 +5,16 @@ * For compatibility with both PHP 5.6 and Symfony 6, this class doesn't implement CommandLoaderInterface. * Instead, CommandLoader.php aliases one of php5/CommandLoader or php7/CommandLoader depending on the PHP version. * + * @deprecated Use CommandLoader class instead. + * * @package automattic/jetpack-changelogger */ namespace Automattic\Jetpack\Changelogger; -use Symfony\Component\Console\Exception\CommandNotFoundException; - /** * Command loader for the changelogger tool CLI. + * + * @deprecated Use CommandLoader class instead. */ -class CommandLoaderBase { - - /** - * Get the class name for a command. - * - * @param string $name Command name. - * @return string Class name. - */ - private function get_class_name( $name ) { - return __NAMESPACE__ . '\\' . ucfirst( $name ) . 'Command'; - } - - /** - * Checks if a command exists. - * - * @param string $name Command name. - * @return bool - */ - protected function doHas( $name ) { - return class_exists( $this->get_class_name( $name ) ); - } - - /** - * Loads a command. - * - * @param string $name Command name. - * @return Command - * @throws CommandNotFoundException If the command is not found. - */ - protected function doGet( $name ) { - $class = $this->get_class_name( $name ); - if ( ! class_exists( $class ) ) { - throw new CommandNotFoundException( "Command \"$name\" does not exist." ); - } - return new $class(); - } - - /** - * Return all command names. - * - * @return string[] All registered command names - */ - protected function doGetNames() { - $names = array(); - foreach ( new \DirectoryIterator( __DIR__ ) as $file ) { - if ( substr( $file->getBasename(), -11 ) === 'Command.php' ) { - $names[] = lcfirst( substr( $file->getBasename(), 0, -11 ) ); - } - } - sort( $names ); - return $names; - } -} +class CommandLoaderBase {} diff --git a/projects/packages/changelogger/src/php7/.phpcs.dir.phpcompatibility.xml b/projects/packages/changelogger/src/php7/.phpcs.dir.phpcompatibility.xml deleted file mode 100644 index a341a2ae9fd81..0000000000000 --- a/projects/packages/changelogger/src/php7/.phpcs.dir.phpcompatibility.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/projects/packages/changelogger/src/php7/.phpcs.dir.xml b/projects/packages/changelogger/src/php7/.phpcs.dir.xml deleted file mode 100644 index 699de1295ae65..0000000000000 --- a/projects/packages/changelogger/src/php7/.phpcs.dir.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/projects/packages/changelogger/src/php7/CommandLoader.php b/projects/packages/changelogger/src/php7/CommandLoader.php deleted file mode 100644 index 50f96fec7101b..0000000000000 --- a/projects/packages/changelogger/src/php7/CommandLoader.php +++ /dev/null @@ -1,48 +0,0 @@ -doHas( $name ); - } - - /** - * Loads a command. - * - * @param string $name Command name. - * @return Command - * @throws CommandNotFoundException If the command is not found. - */ - public function get( $name ): Command { - return $this->doGet( $name ); - } - - /** - * Return all command names. - * - * @return string[] All registered command names - */ - public function getNames(): array { - return $this->doGetNames(); - } -}