<commit_before><?php

namespace CodeTool\ArtifactDownloader\Scope\Config\Processor\Rule;

use CodeTool\ArtifactDownloader\CmdRunner\Command\Factory\CmdRunnerCommandFactoryInterface;
use CodeTool\ArtifactDownloader\Command\Collection\CommandCollectionInterface;
use CodeTool\ArtifactDownloader\Result\Factory\ResultFactoryInterface;
use CodeTool\ArtifactDownloader\Scope\Config\ScopeConfigRuleInterface;
use CodeTool\ArtifactDownloader\Scope\Info\ScopeInfoInterface;

class ScopeConfigProcessorRuleTypeExecHandler implements ScopeConfigProcessorRuleTypeHandlerInterface
{
    /**
     * @var ResultFactoryInterface
     */
    private $resultFactory;

    /**
     * @var CmdRunnerCommandFactoryInterface
     */
    private $cmdRunnerCommandFactory;

    /**
     * @param ResultFactoryInterface           $resultFactory
     * @param CmdRunnerCommandFactoryInterface $cmdRunnerCommandFactory
     */
    public function __construct(
        ResultFactoryInterface $resultFactory,
        CmdRunnerCommandFactoryInterface $cmdRunnerCommandFactory
    ) {
        $this->resultFactory = $resultFactory;
        $this->cmdRunnerCommandFactory = $cmdRunnerCommandFactory;
    }

    /**
     * @inheritdoc
     */
    public function getSupportedTypes()
    {
        return ['exec'];
    }

    /**
     * @inheritdoc
     */
    public function buildCollection(
        CommandCollectionInterface $collection,
        ScopeInfoInterface $scopeInfo,
        ScopeConfigRuleInterface $scopeConfigRule
    ) {
        $clearEnv = filter_var(
            $scopeConfigRule->getOrDefault('clear_env', true),
            FILTER_VALIDATE_BOOLEAN,
            FILTER_NULL_ON_FAILURE
        );

        if (null === $clearEnv) {
            $clearEnv = true;
        }

        $env = [];
        if ($scopeConfigRule->has('env')) {
            $env = $scopeConfigRule->getOrDefault('env')->toArray();
        }

        $collection->add($this->cmdRunnerCommandFactory->createExecCommand(
            $scopeConfigRule->get('cmd'),
            $scopeConfigRule->getOrDefault('cwd', $scopeInfo->getAbsPathByForTarget('')),
            $clearEnv,
            $env
        ));

        return $this->resultFactory->createSuccessful();
    }
}
<commit_msg>Do not clear env by default<commit_after><?php

namespace CodeTool\ArtifactDownloader\Scope\Config\Processor\Rule;

use CodeTool\ArtifactDownloader\CmdRunner\Command\Factory\CmdRunnerCommandFactoryInterface;
use CodeTool\ArtifactDownloader\Command\Collection\CommandCollectionInterface;
use CodeTool\ArtifactDownloader\Result\Factory\ResultFactoryInterface;
use CodeTool\ArtifactDownloader\Scope\Config\ScopeConfigRuleInterface;
use CodeTool\ArtifactDownloader\Scope\Info\ScopeInfoInterface;

class ScopeConfigProcessorRuleTypeExecHandler implements ScopeConfigProcessorRuleTypeHandlerInterface
{
    /**
     * @var ResultFactoryInterface
     */
    private $resultFactory;

    /**
     * @var CmdRunnerCommandFactoryInterface
     */
    private $cmdRunnerCommandFactory;

    /**
     * @param ResultFactoryInterface           $resultFactory
     * @param CmdRunnerCommandFactoryInterface $cmdRunnerCommandFactory
     */
    public function __construct(
        ResultFactoryInterface $resultFactory,
        CmdRunnerCommandFactoryInterface $cmdRunnerCommandFactory
    ) {
        $this->resultFactory = $resultFactory;
        $this->cmdRunnerCommandFactory = $cmdRunnerCommandFactory;
    }

    /**
     * @inheritdoc
     */
    public function getSupportedTypes()
    {
        return ['exec'];
    }

    /**
     * @inheritdoc
     */
    public function buildCollection(
        CommandCollectionInterface $collection,
        ScopeInfoInterface $scopeInfo,
        ScopeConfigRuleInterface $scopeConfigRule
    ) {
        $clearEnv = filter_var(
            $scopeConfigRule->getOrDefault('clear_env', false),
            FILTER_VALIDATE_BOOLEAN,
            FILTER_NULL_ON_FAILURE
        );

        if (null === $clearEnv) {
            $clearEnv = false;
        }

        $env = [];
        if ($scopeConfigRule->has('env')) {
            $env = $scopeConfigRule->getOrDefault('env')->toArray();
        }

        $collection->add($this->cmdRunnerCommandFactory->createExecCommand(
            $scopeConfigRule->get('cmd'),
            $scopeConfigRule->getOrDefault('cwd', $scopeInfo->getAbsPathByForTarget('')),
            $clearEnv,
            $env
        ));

        return $this->resultFactory->createSuccessful();
    }
}

{'fraction_non_alphanumeric': 0.09915518008003557, 'fraction_numerical': 0.0, 'mean_word_length': 2.9673721340388006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3878622', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1159, 'n_words': 169}