<commit_before><?php

namespace Formjack;

use Formjack\Field\AbstractField;
use Formjack\Layout\AbstractLayout;
use Formjack\Layout\DefaultLayout;

class Form {

    /**
     * @var AbstractLayout Layout instance
     */
    private $layout;

    /**
     * @var AbstractField[] Array of form fields
     */
    private $fields;

    /**
     * @var array Array of validation errors
     */
    private $errors;

    /**
     * @param array Array of form fields
     */
    public function __construct(array $fields = array()) {
        foreach ($fields as $field) {
            if ($field instanceof AbstractField) {
                $this->addField($field);
            }
        }
    }

    /**
     * @param  AbstractLayout|null $layout
     * @return $this
     */
    public function setLayout(AbstractLayout $layout = null) {
        $this->layout = ($layout !== null)? $layout : new DefaultLayout();

        return $this;
    }

    /**
     * @return array
     */
    public function getFields() {
        return $this->fields;
    }

    /**
     * @param array $fields
     */
    public function setFields(array $fields) {
        foreach ($fields as $field) {
            if ($field instanceof AbstractField) {
                $this->addField($field);
            }
        }
    }

    /**
     * @param  AbstractField $field
     * @return $this
     */
    public function addField(AbstractField $field) {
        $field->setParent($this);
        $this->fields[$field->getName()] = $field;

        return $this;
    }

    /**
     * @param  string $name
     * @return $this
     */
    public function removeField($name) {
        if (isset($this->fields[$name])) {
            unset($this->fields[$name]);
        }

        return $this;
    }

    /**
     * @return void
     */
    public function renderField($name) {
        if (isset($this->fields[$name])) {
            echo $this->layout->renderField($this->fields[$name]);
        }
    }
<commit_msg>Implemented form render method.<commit_after><?php

namespace Formjack;

use Formjack\Field\AbstractField;
use Formjack\Layout\AbstractLayout;
use Formjack\Layout\DefaultLayout;

class Form {

    /**
     * @var AbstractLayout Layout instance
     */
    private $layout;

    /**
     * @var AbstractField[] Array of form fields
     */
    private $fields;

    /**
     * @var array Array of validation errors
     */
    private $errors;

    /**
     * @param array Array of form fields
     */
    public function __construct(array $fields = array()) {
        foreach ($fields as $field) {
            if ($field instanceof AbstractField) {
                $this->addField($field);
            }
        }
    }

    /**
     * @param  AbstractLayout|null $layout
     * @return $this
     */
    public function setLayout(AbstractLayout $layout = null) {
        $this->layout = ($layout !== null)? $layout : new DefaultLayout();

        return $this;
    }

    /**
     * @return array
     */
    public function getFields() {
        return $this->fields;
    }

    /**
     * @param array $fields
     */
    public function setFields(array $fields) {
        foreach ($fields as $field) {
            if ($field instanceof AbstractField) {
                $this->addField($field);
            }
        }
    }

    /**
     * @param  AbstractField $field
     * @return $this
     */
    public function addField(AbstractField $field) {
        $field->setParent($this);
        $this->fields[$field->getName()] = $field;

        return $this;
    }

    /**
     * @param  string $name
     * @return $this
     */
    public function removeField($name) {
        if (isset($this->fields[$name])) {
            unset($this->fields[$name]);
        }

        return $this;
    }

    /**
     * @return void
     */
    public function render() {
        foreach ($this->fields as $field) {
            echo $this->layout->renderField($field);
        }
    }

    /**
     * @return void
     */
    public function renderField($name) {
        if (isset($this->fields[$name])) {
            echo $this->layout->renderField($this->fields[$name]);
        }
    }

{'fraction_non_alphanumeric': 0.13888222595346605, 'fraction_numerical': 0.0, 'mean_word_length': 1.8156650911546253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '7066928', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1154, 'n_words': 274}