<commit_before><?php

namespace Symfony\Component\DependencyInjection\Configuration\Builder;

/**
 * This class builds an if expression.
 *
 * @author <NAME> <<EMAIL>>
 */
class ExprBuilder
{
    public $parent;
    public $ifPart;
    public $thenPart;

    /**
     * Constructor
     *
     * @param Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder $parent The parent node
     */
    public function __construct($parent)
    {
        $this->parent = $parent;
    }

    /**
     * Sets a closure to use as tests.
     *
     * The default one tests if the value is true.
     *
     * @param \Closure $closure
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifTrue(\Closure $closure = null)
    {
        if (null === $closure) {
            $closure = function($v) { return true === $v; };
        }

        $this->ifPart = $closure;

        return $this;
    }

    /**
     * Tests if the value is a string.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifString()
    {
        $this->ifPart = function($v) { return is_string($v); };

        return $this;
    }

    /**
     * Tests if the value is null.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifNull()
    {
        $this->ifPart = function($v) { return null === $v; };

        return $this;
    }

    /**
     * Tests if the value is an array.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifArray()
    {
        $this->ifPart = function($v) { return is_array($v); };

        return $this;
    }

    /**
     * Sets the closure to run if the test pass.
     *
     * @param \Closure $closure
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function then(\Closure $closure)
    {
        $this->thenPart = $closure;

        return $this;
    }

    /**
     * Sets a closure replacing the key with an attribute of the value when it is an array.
     *
     * @param string $attribute
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function thenReplaceKeyWithAttribute($attribute)
    {
        $this->thenPart = function($v) {
            $newValue = array();
            foreach ($v as $k => $oldValue) {
                if (is_array($oldValue) && isset($oldValue['id'])) {
                    $k = $oldValue['id'];
                }

                $newValue[$k] = $oldValue;
            }

            return $newValue;
        };

        return $this;
    }

    /**
     * Sets a closure returning an empty array.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function thenEmptyArray()
    {
        $this->thenPart = function($v) { return array(); };

        return $this;
    }

    /**
     * Returns the parent node
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder
     */
    public function end()
    {
        if (null === $this->ifPart) {
            throw new \RuntimeException('You must specify an if part.');
        }
        if (null === $this->thenPart) {
            throw new \RuntimeException('You must specify a then part.');
        }

        return $this->parent;
    }
}<commit_msg>Fixed ExprBuilder to really use the parameter when replacing a key with an attribute<commit_after><?php

namespace Symfony\Component\DependencyInjection\Configuration\Builder;

/**
 * This class builds an if expression.
 *
 * @author <NAME> <<EMAIL>>
 */
class ExprBuilder
{
    public $parent;
    public $ifPart;
    public $thenPart;

    /**
     * Constructor
     *
     * @param Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder $parent The parent node
     */
    public function __construct($parent)
    {
        $this->parent = $parent;
    }

    /**
     * Sets a closure to use as tests.
     *
     * The default one tests if the value is true.
     *
     * @param \Closure $closure
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifTrue(\Closure $closure = null)
    {
        if (null === $closure) {
            $closure = function($v) { return true === $v; };
        }

        $this->ifPart = $closure;

        return $this;
    }

    /**
     * Tests if the value is a string.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifString()
    {
        $this->ifPart = function($v) { return is_string($v); };

        return $this;
    }

    /**
     * Tests if the value is null.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifNull()
    {
        $this->ifPart = function($v) { return null === $v; };

        return $this;
    }

    /**
     * Tests if the value is an array.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function ifArray()
    {
        $this->ifPart = function($v) { return is_array($v); };

        return $this;
    }

    /**
     * Sets the closure to run if the test pass.
     *
     * @param \Closure $closure
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function then(\Closure $closure)
    {
        $this->thenPart = $closure;

        return $this;
    }

    /**
     * Sets a closure replacing the key with an attribute of the value when it is an array.
     *
     * @param string $attribute
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function thenReplaceKeyWithAttribute($attribute)
    {
        $this->thenPart = function($v) use ($attribute) {
            $newValue = array();
            foreach ($v as $k => $oldValue) {
                if (is_array($oldValue) && isset($oldValue[$attribute])) {
                    $k = $oldValue[$attribute];
                }

                $newValue[$k] = $oldValue;
            }

            return $newValue;
        };

        return $this;
    }

    /**
     * Sets a closure returning an empty array.
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder
     */
    public function thenEmptyArray()
    {
        $this->thenPart = function($v) { return array(); };

        return $this;
    }

    /**
     * Returns the parent node
     *
     * @return Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder
     */
    public function end()
    {
        if (null === $this->ifPart) {
            throw new \RuntimeException('You must specify an if part.');
        }
        if (null === $this->thenPart) {
            throw new \RuntimeException('You must specify a then part.');
        }

        return $this->parent;
    }
}
{'fraction_non_alphanumeric': 0.11986111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 2.0054257095158596, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2540036', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1986, 'n_words': 499}