<commit_before><?php
/**
 * implements the common builder interface
 */
abstract class TestDataBuilder_Builder
{

    /**
     * @return TestDataBuilder_Builder
     */
    public function but()
    {
        return clone $this;
    }

    /**
     * @return object
     */
    abstract public function build();

    /**
     * @param array $values
     * @return array
     */
    protected function buildIfValuesAreBuilder(array $values)
    {
        $checkedValues = array();
        foreach ($values as $key => $value) {
            $checkedValues[$key] = $this->buildIfValueIsABuilder($value);
        }
        return $checkedValues;
    }

    /**
     * @param mixed $value
     * @return mixed $value
     */
    protected function buildIfValueIsABuilder($value)
    {
        if ($value instanceof TestDataBuilder_Builder) {
            $value = $value->build();
            return $value;
        }
        return $value;
    }
}<commit_msg>introduce static method buildIfPossible to make it reusable for custom builders<commit_after><?php
/**
 * implements the common builder interface
 */
abstract class TestDataBuilder_Builder
{

    /**
     * @return TestDataBuilder_Builder
     */
    public function but()
    {
        return clone $this;
    }

    /**
     * @return object
     */
    abstract public function build();

    /**
     * @param array $values
     * @return array
     */
    protected function buildIfValuesAreBuilder(array $values)
    {
        $checkedValues = array();
        foreach ($values as $key => $value) {
            $checkedValues[$key] = $this->buildIfValueIsABuilder($value);
        }
        return $checkedValues;
    }

    /**
     * @param mixed $value
     * @return mixed $value
     */
    protected function buildIfValueIsABuilder($value)
    {
        return self::buildIfPossible($value);
    }

    /**
     * @param TestDataBuilder_Builder|mixed $value
     * @return mixed
     */
    public static function buildIfPossible($value)
    {
        if ($value instanceof TestDataBuilder_Builder) {
            return $value->build();
        }
        return $value;
    }
}
{'fraction_non_alphanumeric': 0.11303129378794956, 'fraction_numerical': 0.0, 'mean_word_length': 2.0998552821997105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3807342', 'n_tokens_mistral': 594, 'n_tokens_neox': 582, 'n_words': 143}