<commit_before><?php
namespace Sitegeist\MagicWand\Command;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "Sitegeist.MagicWand".   *
 *                                                                        *
 *                                                                        */

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Core\Bootstrap;
use TYPO3\Flow\Cli\CommandController;

abstract class AbstractCommandController extends CommandController
{

    const HIDE_RESULT = 1;
    const HIDE_COMMAND = 2;

    /**
     * @Flow\InjectConfiguration(path="persistence.backendOptions", package="TYPO3.Flow")
     * @var array
     */
    protected $databaseConfiguration;

    /**
     * @Flow\Inject
     * @var Bootstrap
     */
    protected $bootstrap;

    /**
     * @var int
     */
    protected $headlineNumber = 0;

    /**
     * @var array
     */
    protected $secrets = [];


    /**
     * @param string $commands
     * @param array $arguments
     * @param array $options
     */
    protected function executeLocalShellCommand($command, $arguments = [], $options = [])
    {
        $customizedCommand = call_user_func_array('sprintf', array_merge([$command], $arguments));
        if (!in_array(self::HIDE_COMMAND, $options)) {
            $this->outputLine($customizedCommand);
        }
        $customizedCommandResult = shell_exec($customizedCommand);
        if (!in_array(self::HIDE_RESULT, $options)) {
            $this->outputLine($customizedCommandResult);
        }
        return $customizedCommandResult;
    }

    /**
     * @param string $commands
     * @param array $arguments
     * @param array $options
     */
    protected function executeLocalShellCommandWithFlowContext($command, $arguments = [], $options = [])
    {
        $flowCommand = 'FLOW_CONTEXT=' . $this->bootstrap->getContext() . ' ' . $command;
        return $this->executeLocalShellCommand($flowCommand, $arguments, $options);
    }

    /**
     * @param string $commands
     * @param array $arguments
     * @param array $options
     */
    protected function executeLocalFlowCommand($command, $arguments = [], $options = [])
    {
        $flowCommand = './flow ' . $command;
        return $this->executeLocalShellCommandWithFlowContext($flowCommand, $arguments, $options);
    }

    /**
     * @param $line
     */
    protected function outputHeadLine($line = '', $arguments = [])
    {
        $this->headlineNumber++;
        $this->outputLine();
        $this->outputLine('<b>' . $this->headlineNumber . '. ' . $line . '</b>', $arguments);
        $this->outputLine();
    }
<commit_msg>[TASK] Use sprintf instead of string concatenation<commit_after><?php
namespace Sitegeist\MagicWand\Command;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "Sitegeist.MagicWand".   *
 *                                                                        *
 *                                                                        */

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Core\Bootstrap;
use TYPO3\Flow\Cli\CommandController;

abstract class AbstractCommandController extends CommandController
{

    const HIDE_RESULT = 1;
    const HIDE_COMMAND = 2;

    /**
     * @Flow\InjectConfiguration(path="persistence.backendOptions", package="TYPO3.Flow")
     * @var array
     */
    protected $databaseConfiguration;

    /**
     * @Flow\Inject
     * @var Bootstrap
     */
    protected $bootstrap;

    /**
     * @var int
     */
    protected $headlineNumber = 0;

    /**
     * @var array
     */
    protected $secrets = [];


    /**
     * @param string $commands
     * @param array $arguments
     * @param array $options
     */
    protected function executeLocalShellCommand($command, $arguments = [], $options = [])
    {
        $customizedCommand = call_user_func_array('sprintf', array_merge([$command], $arguments));
        if (!in_array(self::HIDE_COMMAND, $options)) {
            $this->outputLine($customizedCommand);
        }
        $customizedCommandResult = shell_exec($customizedCommand);
        if (!in_array(self::HIDE_RESULT, $options)) {
            $this->outputLine($customizedCommandResult);
        }
        return $customizedCommandResult;
    }

    /**
     * @param string $commands
     * @param array $arguments
     * @param array $options
     */
    protected function executeLocalShellCommandWithFlowContext($command, $arguments = [], $options = [])
    {
        $flowCommand = sprintf('FLOW_CONTEXT=%s %s', $this->bootstrap->getContext(), $command);
        return $this->executeLocalShellCommand($flowCommand, $arguments, $options);
    }

    /**
     * @param string $commands
     * @param array $arguments
     * @param array $options
     */
    protected function executeLocalFlowCommand($command, $arguments = [], $options = [])
    {
        $flowCommand = sprintf('./flow %s', $command);
        return $this->executeLocalShellCommandWithFlowContext($flowCommand, $arguments, $options);
    }

    /**
     * @param $line
     */
    protected function outputHeadLine($line = '', $arguments = [])
    {
        $this->headlineNumber++;
        $this->outputLine();
        $this->outputLine('<b>' . $this->headlineNumber . '. ' . $line . '</b>', $arguments);
        $this->outputLine();
    }

{'fraction_non_alphanumeric': 0.13250137639933932, 'fraction_numerical': 0.0029363185905670764, 'mean_word_length': 2.082579185520362, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3108977', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1446, 'n_words': 284}