0 follower

Final Class Yiisoft\YiiDevTool\App\Command\Release\WhatCommand

InheritanceYiisoft\YiiDevTool\App\Command\Release\WhatCommand » Symfony\Component\Console\Command\Command

Method Details

Hide inherited methods

configure() protected method

protected mixed configure ( )

                protected function configure()
{
    $this
        ->setName('release/what')
        ->setDescription('Find out what to release next');
    parent::configure();
}

            
execute() protected method

protected mixed execute ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output )
$input \Symfony\Component\Console\Input\InputInterface
$output \Symfony\Component\Console\Output\OutputInterface

                protected function execute(InputInterface $input, OutputInterface $output)
{
    $this->initPackageList();
    $io = $this->getIO();
    $packagesWithoutRelease = [];
    $installedPackages = $this
        ->getPackageList()
        ->getInstalledAndEnabledPackages();
    // Get packages without release.
    foreach ($installedPackages as $installedPackage) {
        if ($this->hasRelease($installedPackage)) {
            $io->info("Skip {$installedPackage->getName()}. Already released.");
            // Skip released packages.
            continue;
        }
        if (!$installedPackage->composerConfigFileExists()) {
            $io->info("Skip {$installedPackage->getName()}. No composer.json.");
            // Skip packages without composer.json.
            continue;
        }
        $packagesWithoutRelease[$installedPackage->getName()] = [
            'dependencies' => 0,
            'dependents' => 0,
            'deps' => [],
        ];
    }
    // Get dependency stats for packages without release.
    foreach ($installedPackages as $installedPackage) {
        if (!array_key_exists($installedPackage->getName(), $packagesWithoutRelease)) {
            // Skip released packages and packages without composer.json.
            continue;
        }
        foreach ($this->getDependencyNames($installedPackage) as $dependencyName) {
            if (!array_key_exists($dependencyName, $packagesWithoutRelease)) {
                // Skip released and third party packages.
                continue;
            }
            $packagesWithoutRelease[$dependencyName]['dependents']++;
            $packagesWithoutRelease[$dependencyName]['deps'][] = $this->removeVendorName($installedPackage->getName());
            $packagesWithoutRelease[$installedPackage->getName()]['dependencies']++;
            $packagesWithoutRelease[$installedPackage->getName()]['deps'][] = $this->removeVendorName($dependencyName);
        }
    }
    uasort(
        $packagesWithoutRelease,
        static fn ($a, $b) => [$a['dependencies'], -$a['dependents']] <=> [$b['dependencies'], -$b['dependents']]
    );
    $successStyle = new TableCellStyle(['fg' => 'green']);
    $errorStyle = new TableCellStyle(['fg' => 'red']);
    $packagesToRelease = [];
    $packagesToDevelop = [];
    foreach ($packagesWithoutRelease as $packageName => $stats) {
        if ($stats['dependencies'] > 0) {
            $packagesToDevelop[] = [
                new TableCell($packageName, ['style' => $errorStyle]),
                $stats['dependencies'],
                $stats['dependents'],
                $this->concatDependencies($stats['deps']),
            ];
        } else {
            $packagesToRelease[] = [
                new TableCell($packageName, ['style' => $successStyle]),
                $stats['dependencies'],
                $stats['dependents'],
                $this->concatDependencies($stats['deps']),
            ];
        }
    }
    $tableIO = new Table($output);
    $tableIO->setHeaders(['Package', 'Out deps', 'In deps', 'Packages']);
    $tableIO->setColumnMaxWidth(3, 120);
    if (count($packagesToRelease) > 0) {
        $tableIO->addRow([
            new TableCell('Packages to release', [
                'colspan' => 4,
                'style' => new TableCellStyle(['align' => 'center', 'bg' => 'green']),
            ]),
        ]);
        $tableIO->addRows($packagesToRelease);
    }
    if (count($packagesToDevelop) > 0) {
        $tableIO->addRow([
            new TableCell('Packages to develop', [
                'colspan' => 4,
                'style' => new TableCellStyle(['align' => 'center', 'bg' => 'red']),
            ]),
        ]);
        $tableIO->addRows($packagesToDevelop);
    }
    $tableIO->render();
    $io
        ->important()
        ->info(
            <<<TEXT
    <success>Out deps</success> – count unreleased packages from which the package depends
    <success>In deps</success> – count unreleased packages which depends on the package
    TEXT
        );
    return Command::SUCCESS;
}

            
getAppRootDir() protected method

Use this method to get a root directory of the tool.

Commands and components can be moved as a result of refactoring, so you should not rely on their location in the file system.

protected string getAppRootDir ( )
return string

Path to the root directory of the tool WITH a TRAILING SLASH.

                protected function getAppRootDir(): string
{
    return rtrim($this
            ->getApplication()
            ->getRootDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}

            
getIO() protected method

protected Yiisoft\YiiDevTool\App\Component\Console\OutputManager getIO ( )

                protected function getIO(): OutputManager
{
    if ($this->io === null) {
        throw new RuntimeException('IO is not initialized.');
    }
    return $this->io;
}

            
initialize() protected method

protected mixed initialize ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output )
$input \Symfony\Component\Console\Input\InputInterface
$output \Symfony\Component\Console\Output\OutputInterface

                protected function initialize(InputInterface $input, OutputInterface $output)
{
    $this->io = new OutputManager(new YiiDevToolStyle($input, $output));
}