Skip to content

Commit

Permalink
Remove stub that was previously used for PHP < 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jeherve committed Nov 16, 2023
1 parent b650352 commit c59548e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 120 deletions.
98 changes: 91 additions & 7 deletions projects/packages/changelogger/src/CommandLoader.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,98 @@
<?php
/**
* Compatibility stub for Symfony 6 changes.
*
* Symfony 6 (for PHP 8.0+) added return type hints to its interface. But we still support PHP 7.0, which doesn't recognize that syntax.
* Since specifying a return type when the interface doesn't is ok, use the version that always does that for PHP 7+ instead of figuring
* out how to check the actual symfony version.
* Command loader for the changelogger tool CLI.
*
* @package automattic/jetpack-changelogger
*/

namespace Automattic\Jetpack\Changelogger;
namespace Automattic\Jetpack\Changelogger\php7;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Exception\CommandNotFoundException;

/**
* Command loader for the changelogger tool CLI.
*/
class CommandLoader implements CommandLoaderInterface {
/**
* 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;
}

/**
* 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();
}
}
60 changes: 5 additions & 55 deletions projects/packages/changelogger/src/CommandLoaderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

This file was deleted.

6 changes: 0 additions & 6 deletions projects/packages/changelogger/src/php7/.phpcs.dir.xml

This file was deleted.

48 changes: 0 additions & 48 deletions projects/packages/changelogger/src/php7/CommandLoader.php

This file was deleted.

0 comments on commit c59548e

Please sign in to comment.