<commit_before><?php

namespace Heyday\Beam\Command;

use Heyday\Beam\Config\JsonConfigLoader;
use Stecman\Component\Symfony\Console\BashCompletion\Completion;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;

/**
 * Class BeamCompletionCommand
 * @package Heyday\Beam\Command
 */
class BeamCompletionCommand extends CompletionCommand
{
    protected function configure()
    {
        parent::configure();
    }

    /**
     * @return string
     */
    protected function runCompletion()
    {
        $application = $this->getApplication();
        $handler = $this->handler;
        $context = $this->handler->getContext();

        // Trigger the merging of TransferMethod definition
        $commandName = $handler->getInput()->getFirstArgument();
        if($application->has($commandName)){
            $command = $application->get($commandName);

            if ($command instanceof TransferCommand) {

                try {
                    $words = $context->getWords();
                    unset($words[$context->getWordIndex()]);
                    array_shift($words);
                    $input = new ArgvInput($words, $command->getDefinition());
                } catch (\RuntimeException $e) {
                    // Input isn't parsable - ignore
                }

                if (isset($input)) {
                    $command->guessTarget($input);
                }
            }
        }

        try {
            $config = $this->getConfig();
        } catch (\Exception $e) {
            $config = null;
            $projectPath = null;
        }

        // Add argument handlers
        $handler->addHandlers(
            array(
                Completion::makeGlobalHandler(
                    'target',
                    Completion::TYPE_ARGUMENT,
                    function () use ($config) {
                        if (!$config) {
                            return null;
                        } elseif (is_array($config['servers'])) {
                            return array_keys($config['servers']);
                        }
                    }
                )
            )
        );

        // Add option handlers
        $handler->addHandlers(
            array(
                Completion::makeGlobalHandler(
                    'ref',
                    Completion::TYPE_OPTION,
                    function () {
                        $raw = shell_exec('git show-ref --abbr');
                        if (preg_match_all('/refs\/(?:heads|tags)?\/?(.*)/', $raw, $matches)) {
                            return $matches[1];
                        }
                    }
                ),
                Completion::makeGlobalHandler(
                    'tags',
                    Completion::TYPE_OPTION,
                    function () use ($config) {
                        if (!$config) {
                            return;
                        }

                        if (isset($config['commands']) && is_array($config['commands'])) {
<commit_msg>Replace use of deprecated static method Completion::makeGlobalHandler<commit_after><?php

namespace Heyday\Beam\Command;

use Heyday\Beam\Config\JsonConfigLoader;
use Stecman\Component\Symfony\Console\BashCompletion\Completion;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;

/**
 * Class BeamCompletionCommand
 * @package Heyday\Beam\Command
 */
class BeamCompletionCommand extends CompletionCommand
{
    protected function configure()
    {
        parent::configure();
    }

    /**
     * @return string
     */
    protected function runCompletion()
    {
        $application = $this->getApplication();
        $handler = $this->handler;
        $context = $this->handler->getContext();

        // Trigger the merging of TransferMethod definition
        $commandName = $handler->getInput()->getFirstArgument();
        if($application->has($commandName)){
            $command = $application->get($commandName);

            if ($command instanceof TransferCommand) {

                try {
                    $words = $context->getWords();
                    unset($words[$context->getWordIndex()]);
                    array_shift($words);
                    $input = new ArgvInput($words, $command->getDefinition());
                } catch (\RuntimeException $e) {
                    // Input isn't parsable - ignore
                }

                if (isset($input)) {
                    $command->guessTarget($input);
                }
            }
        }

        try {
            $config = $this->getConfig();
        } catch (\Exception $e) {
            $config = null;
            $projectPath = null;
        }

        // Add argument handlers
        $handler->addHandlers(
            array(
                new Completion(
                    Completion::ALL_COMMANDS,
                    'target',
                    Completion::TYPE_ARGUMENT,
                    function () use ($config) {
                        if (!$config) {
                            return null;
                        } elseif (is_array($config['servers'])) {
                            return array_keys($config['servers']);
                        }
                    }
                )
            )
        );

        // Add option handlers
        $handler->addHandlers(
            array(
                new Completion(
                    Completion::ALL_COMMANDS,
                    'ref',
                    Completion::TYPE_OPTION,
                    function () {
                        $raw = shell_exec('git show-ref --abbr');
                        if (preg_match_all('/refs\/(?:heads|tags)?\/?(.*)/', $raw, $matches)) {
                            return $matches[1];
                        }
                    }
                ),
                new Completion(
                    Completion::ALL_COMMANDS,
                    'tags',
                    Completion::TYPE_OPTION,
                    function () use ($config) {
                        if (!$config) {
                            return;
                        }

                        if (isset($config['commands']) && is_array($config['commands'])) {

{'fraction_non_alphanumeric': 0.1148244672696612, 'fraction_numerical': 0.00030660738923808065, 'mean_word_length': 1.3110166489550124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2217338', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1489, 'n_words': 276}