Skip to content

Commit

Permalink
Re-added Drush command file
Browse files Browse the repository at this point in the history
  • Loading branch information
tuutti committed Feb 27, 2024
1 parent 00a77ce commit 0714d7c
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/Drush/Commands/VersionDrushCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace DrupalTools\Drush\Commands;

use ComposerLockParser\ComposerInfo;
use Drupal\Component\DependencyInjection\ContainerInterface;
use Drupal\helfi_api_base\Package\VersionChecker;
use Drush\Attributes\Argument;
use Drush\Attributes\Command;
use Drush\Commands\DrushCommands;

/**
* A drush command to check whether given Helfi packages are up-to-date.
*/
final class VersionDrushCommands extends DrushCommands {

/**
* Constructs a new instance.
*
* @param \Drupal\helfi_api_base\Package\VersionChecker $versionChecker
* The version checker service.
*/
public function __construct(
private readonly VersionChecker $versionChecker,

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Parameter $versionChecker of method DrupalTools\Drush\Commands\VersionDrushCommands::__construct() has invalid type Drupal\helfi_api_base\Package\VersionChecker.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Parameter $versionChecker of method DrupalTools\Drush\Commands\VersionDrushCommands::__construct() has invalid type Drupal\helfi_api_base\Package\VersionChecker.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Property DrupalTools\Drush\Commands\VersionDrushCommands::$versionChecker has unknown class Drupal\helfi_api_base\Package\VersionChecker as its type.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Property DrupalTools\Drush\Commands\VersionDrushCommands::$versionChecker has unknown class Drupal\helfi_api_base\Package\VersionChecker as its type.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Parameter $versionChecker of method DrupalTools\Drush\Commands\VersionDrushCommands::__construct() has invalid type Drupal\helfi_api_base\Package\VersionChecker.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Parameter $versionChecker of method DrupalTools\Drush\Commands\VersionDrushCommands::__construct() has invalid type Drupal\helfi_api_base\Package\VersionChecker.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Property DrupalTools\Drush\Commands\VersionDrushCommands::$versionChecker has unknown class Drupal\helfi_api_base\Package\VersionChecker as its type.

Check failure on line 26 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Property DrupalTools\Drush\Commands\VersionDrushCommands::$versionChecker has unknown class Drupal\helfi_api_base\Package\VersionChecker as its type.
) {
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): self {

Check failure on line 33 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Parameter $container of method DrupalTools\Drush\Commands\VersionDrushCommands::create() has invalid type Drupal\Component\DependencyInjection\ContainerInterface.

Check failure on line 33 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Parameter $container of method DrupalTools\Drush\Commands\VersionDrushCommands::create() has invalid type Drupal\Component\DependencyInjection\ContainerInterface.
return new static(
$container->get('helfi_api_base.package_version_checker'),

Check failure on line 35 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Call to method get() on an unknown class Drupal\Component\DependencyInjection\ContainerInterface.

Check failure on line 35 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Call to method get() on an unknown class Drupal\Component\DependencyInjection\ContainerInterface.
);
}

/**
* Checks whether Composer packages are up-to-date.
*
* @param string $file
* The path to composer.lock file.
*
* @return int
* The exit code.
*/
#[Command(name: 'helfi:tools:check-composer-versions')]
#[Argument(name: 'file', description: 'Path to composer.lock file')]
public function checkVersions(string $file) : int {
$info = new ComposerInfo($file);

Check failure on line 51 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Instantiated class ComposerLockParser\ComposerInfo not found.

Check failure on line 51 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Instantiated class ComposerLockParser\ComposerInfo not found.

$versions = [];
/** @var \Composer\Package\Package $package */
foreach (iterator_to_array($info->getPackages()) as $package) {

Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Call to method getPackages() on an unknown class ComposerLockParser\ComposerInfo.

Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

PHPDoc tag @var for variable $package contains unknown class Composer\Package\Package.

Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Call to method getPackages() on an unknown class ComposerLockParser\ComposerInfo.

Check failure on line 55 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

PHPDoc tag @var for variable $package contains unknown class Composer\Package\Package.
$version = $this->versionChecker->get($package->getName(), $package->getVersion());

Check failure on line 56 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.1)

Call to method get() on an unknown class Drupal\helfi_api_base\Package\VersionChecker.

Check failure on line 56 in src/Drush/Commands/VersionDrushCommands.php

View workflow job for this annotation

GitHub Actions / tests (8.2)

Call to method get() on an unknown class Drupal\helfi_api_base\Package\VersionChecker.

// Skip dev versions since we can't easily verify the latest
// version.
if (!$version || $version->isLatest || str_starts_with($package->getVersion(), 'dev-')) {
continue;
}
$versions[] = [
'name' => $package->getName(),
'currentVersion' => $package->getVersion(),
'latestVersion' => $version->latestVersion,
];
}
if (!$versions) {
return DrushCommands::EXIT_SUCCESS;
}

$this->io()->table(
['Name', 'Version', 'Latest version'],
$versions,
);
return DrushCommands::EXIT_FAILURE_WITH_CLARITY;
}

}

0 comments on commit 0714d7c

Please sign in to comment.