<commit_before><?php declare( strict_types=1 );

namespace ChriCo\Fields\Element;

class CollectionElement extends Element implements CollectionElementInterface {

	/**
	 * Default attribute type "collection" to assign it to the right view.
	 *
	 * @var array
	 */
	protected $attributes = [
		'type' => 'collection'
	];

	/**
	 * @var ElementInterface[]
	 */
	protected $elements = [];

	public function add_element( ElementInterface $element ) {

		$this->elements[ $element->get_id() ] = $element;
	}

	public function add_elements( array $elements = [] ) {

		array_walk( $elements, [ $this, 'add_element' ] );
	}

	public function get_elements(): array {

		return $this->elements;
	}
}<commit_msg>added support for set_value for children in CollectionElements.<commit_after><?php declare( strict_types=1 );

namespace ChriCo\Fields\Element;

class CollectionElement extends Element implements CollectionElementInterface {

	/**
	 * Default attribute type "collection" to assign it to the right view.
	 *
	 * @var array
	 */
	protected $attributes = [
		'type' => 'collection'
	];

	/**
	 * @var ElementInterface[]
	 */
	protected $elements = [];

	public function add_element( ElementInterface $element ) {

		$this->elements[ $element->get_id() ] = $element;
	}

	public function add_elements( array $elements = [] ) {

		array_walk( $elements, [ $this, 'add_element' ] );
	}

	public function get_elements(): array {

		return $this->elements;
	}

	/**
	 * If the key is "value" and the $value an array, we assign all values to the children.
	 *
	 * {@inheritdoc}
	 */
	public function set_attribute( $key, $value ) {

		if ( $key === 'value' && is_array( $value ) ) {
			foreach ( $value as $k => $v ) {
				if ( isset( $this->elements[ $k ] ) ) {
					$this->elements[ $k ]->set_value( $v );
				}
			}
		} else {
			parent::set_attribute( $key, $value );
		}
	}
}
{'fraction_non_alphanumeric': 0.1472785485592316, 'fraction_numerical': 0.0010672358591248667, 'mean_word_length': 3.6296296296296298, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4312266', 'n_tokens_mistral': 630, 'n_tokens_neox': 570, 'n_words': 162}