0 follower

Final Class Yiisoft\YiiDevTool\App\Command\LintCommand

InheritanceYiisoft\YiiDevTool\App\Command\LintCommand » Yiisoft\YiiDevTool\App\Component\Console\PackageCommand » Symfony\Component\Console\Command\Command

Protected Methods

Hide inherited methods

Method Description Defined By
afterProcessingPackages() Override this method in a subclass if you want to do something after processing the packages. Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
areTargetPackagesSpecifiedExplicitly() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
beforeProcessingPackages() Override this method in a subclass if you want to do something before processing the packages. Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
checkSSHConnection() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
configure() Yiisoft\YiiDevTool\App\Command\LintCommand
doesPackageContainErrors() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
execute() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
getAppRootDir() Use this method to get a root directory of the tool. Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
getErrorsList() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
getExampleCommandPrefix() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
getIO() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
getMessageWhenNothingHasBeenOutput() Yiisoft\YiiDevTool\App\Command\LintCommand
getPackageList() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
getTargetPackages() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
initPackageList() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
initTargetPackages() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
initialize() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand
processPackage() Yiisoft\YiiDevTool\App\Command\LintCommand
registerPackageError() Yiisoft\YiiDevTool\App\Component\Console\PackageCommand

Method Details

Hide inherited methods

afterProcessingPackages() protected method

Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::afterProcessingPackages()

Override this method in a subclass if you want to do something after processing the packages.

For example, link the packages with each other.

protected void afterProcessingPackages ( \Symfony\Component\Console\Input\InputInterface $input )
$input \Symfony\Component\Console\Input\InputInterface

                protected function afterProcessingPackages(InputInterface $input): void
{
}

            
areTargetPackagesSpecifiedExplicitly() protected method
protected boolean areTargetPackagesSpecifiedExplicitly ( )

                protected function areTargetPackagesSpecifiedExplicitly(): bool
{
    if ($this->targetPackagesSpecifiedExplicitly === null) {
        throw new RuntimeException('Target packages are not initialized.');
    }
    return $this->targetPackagesSpecifiedExplicitly;
}

            
beforeProcessingPackages() protected method

Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::beforeProcessingPackages()

Override this method in a subclass if you want to do something before processing the packages.

For example, check the input arguments.

protected void beforeProcessingPackages ( \Symfony\Component\Console\Input\InputInterface $input )
$input \Symfony\Component\Console\Input\InputInterface

                protected function beforeProcessingPackages(InputInterface $input): void
{
}

            
checkSSHConnection() protected method
protected boolean checkSSHConnection ( )

                protected function checkSSHConnection(): bool
{
    $process = new Process(['ssh', '-T', 'git@github.com']);
    $process
        ->setTimeout(null)
        ->run();
    if ($process->getExitCode() !== 1) {
        $this
            ->getIO()
            ->error([
                'Checking access to github.com ... DENIED',
                'Error: ' . $process->getErrorOutput(),
                'Seems like you have not installed SSH key to you Github account.',
                'Key is required to work with repository via SSH.',
                'See here for instructions: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account',
            ]);
        return false;
    }
    return true;
}

            
configure() protected method

protected mixed configure ( )

                protected function configure()
{
    $this
        ->setName('lint')
        ->setDescription('Check packages according to PSR-12 standard');
    parent::configure();
}

            
doesPackageContainErrors() protected method
protected boolean doesPackageContainErrors ( Yiisoft\YiiDevTool\App\Component\Package\Package $package )
$package Yiisoft\YiiDevTool\App\Component\Package\Package

                protected function doesPackageContainErrors(Package $package): bool
{
    return $this->errorList->has($package);
}

            
execute() protected method
protected integer 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): int
{
    $this->initPackageList();
    $this->initTargetPackages($input);
    $io = $this->getIO();
    $this->beforeProcessingPackages($input);
    $packages = $this->getTargetPackages();
    sort($packages);
    foreach ($packages as $package) {
        if ($this->isCurrentInstallationValid($package)) {
            $this->processPackage($package);
        }
    }
    $io->clearPreparedPackageHeader();
    $this->afterProcessingPackages($input);
    $this->showPackageErrors();
    if ($io->nothingHasBeenOutput()) {
        $message = $this->getMessageWhenNothingHasBeenOutput();
        if ($message !== null) {
            $io
                ->important()
                ->info($message);
        }
    }
    return Command::SUCCESS;
}

            
getAppRootDir() protected method

Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::getAppRootDir()

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;
}

            
getErrorsList() protected method
protected Yiisoft\YiiDevTool\App\Component\Package\PackageErrorList getErrorsList ( )

                protected function getErrorsList(): PackageErrorList
{
    return $this->errorList;
}

            
getExampleCommandPrefix() protected method
protected string getExampleCommandPrefix ( )
return string

Console command prefix that works in current environment.

                protected function getExampleCommandPrefix(): string
{
    $shell = getenv('SHELL');
    $isBash = ($shell && stripos($shell, 'bash')) !== false;
    return $isBash ? './' : '';
}

            
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;
}

            
getMessageWhenNothingHasBeenOutput() protected method

protected string|null getMessageWhenNothingHasBeenOutput ( )

                protected function getMessageWhenNothingHasBeenOutput(): ?string
{
    return '<success>✔ No problems found</success>';
}

            
getPackageList() protected method
protected Yiisoft\YiiDevTool\App\Component\Package\PackageList getPackageList ( )

                protected function getPackageList(): PackageList
{
    return $this->packageList;
}

            
getTargetPackages() protected method
protected Yiisoft\YiiDevTool\App\Component\Package\Package[] getTargetPackages ( )

                protected function getTargetPackages(): array
{
    if ($this->targetPackages === null) {
        throw new RuntimeException('Target packages are not initialized.');
    }
    return $this->targetPackages;
}

            
initPackageList() protected method
protected void initPackageList ( )

                protected function initPackageList(): void
{
    $io = $this->getIO();
    try {
        $ownerPackages = require $this->getAppRootDir() . 'owner-packages.php';
        if (!preg_match('/^[a-z0-9][a-z0-9-]*[a-z0-9]$/i', $ownerPackages)) {
            $io->error([
                'The packages owner can only contain the characters [a-z0-9-], and the character \'-\' cannot appear at the beginning or at the end.',
                'See <file>owner-packages.php</file> to set the packages owner.',
            ]);
            exit(1);
        }
        $packagesRootDir = $this->getApplication()->getConfig('packagesRootDir') ??  $this->getAppRootDir() . 'dev';
        $this->packageList = new PackageList(
            $ownerPackages,
            $this->getAppRootDir() . 'packages.php',
            packagesRootDir: $packagesRootDir,
        );
        $this->errorList = new PackageErrorList();
    } catch (InvalidArgumentException $e) {
        $io->error([
            'Invalid local package configuration <file>packages.local.php</file>',
            $e->getMessage(),
            'See <file>packages.local.php.example</file> for configuration examples.',
        ]);
        exit(1);
    }
}

            
initTargetPackages() protected method
protected void initTargetPackages ( \Symfony\Component\Console\Input\InputInterface $input )
$input \Symfony\Component\Console\Input\InputInterface

                protected function initTargetPackages(InputInterface $input): void
{
    if ($this->packageList === null) {
        throw new RuntimeException('Package list is not initialized.');
    }
    $io = $this->getIO();
    $commaSeparatedPackageIds = $input->getArgument('packages');
    if ($commaSeparatedPackageIds === null) {
        $this->targetPackagesSpecifiedExplicitly = false;
        $this->targetPackages = $this->packageList->getEnabledPackages();
        return;
    }
    $targetPackageIds = array_unique(explode(',', $commaSeparatedPackageIds));
    $problemsFound = false;
    $targetPackages = [];
    foreach ($targetPackageIds as $targetPackageId) {
        $package = $this->packageList->getPackage($targetPackageId);
        if ($package === null) {
            $io->error("Package <package>$targetPackageId</package> not found in <file>packages.php</file>");
            $problemsFound = true;
            continue;
        }
        if ($package->disabled()) {
            $io->error("Package <package>$targetPackageId</package> disabled in <file>packages.local.php</file>");
            $problemsFound = true;
            continue;
        }
        $targetPackages[] = $package;
    }
    if ($problemsFound) {
        exit(1);
    }
    $this->targetPackagesSpecifiedExplicitly = true;
    $this->targetPackages = $targetPackages;
}

            
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));
}

            
processPackage() protected method

protected void processPackage ( Yiisoft\YiiDevTool\App\Component\Package\Package $package )
$package Yiisoft\YiiDevTool\App\Component\Package\Package

                protected function processPackage(Package $package): void
{
    $io = $this->getIO();
    $io->preparePackageHeader($package, 'Linting package {package}');
    if ($package->isMonoRepository()) {
        $io->info('The operation has been skipped because the package is monorepo.');
        return;
    }
    $process = new Process([
        './vendor/bin/phpcs',
        $package->getPath(),
        $io->hasColorSupport() ? '--colors' : '--no-colors',
        '--standard=PSR12',
        '--ignore=*/vendor/*,*/docs/*',
    ], $this->getAppRootDir());
    $process->run();
    if ($process->getExitCode() > 0) {
        $io
            ->important()
            ->info($process->getOutput() . $process->getErrorOutput());
    } else {
        $io->success('✔ No problems found.');
    }
}

            
registerPackageError() protected method
protected void registerPackageError ( Yiisoft\YiiDevTool\App\Component\Package\Package $package, string $message, string $during )
$package Yiisoft\YiiDevTool\App\Component\Package\Package
$message string
$during string

                protected function registerPackageError(Package $package, string $message, string $during): void
{
    $this->errorList->set($package, $message, $during);
}