<commit_before># Entity collection class

`Phproberto\Joomla\Entity\EntityCollection`

> Class to perform common actions on groups of entities.

## Index <a id="index"></a>

* [Usage](#usage)
* [Methods](#methods)
    * [add(EntityInterface $entity)](#add)
    * [clear()](#clear)
    * [count()](#count)
    * [current()](#current)
    * [has($id)](#has)
    * [get($id)](#get)
    * [ids()](#ids)
    * [isEmpty()](#isEmpty)
    * [key()](#key)
    * [next()](#next)
    * [remove($id)](#remove)
    * [rewind()](#rewind)
    * [valid()](#valid)
    * [write(EntityInterface $entity, $overwrite = true)](#write)

## Usage <a id="usage"></a>

A couple of fast examples:

```php
<?php
JLoader::import('phproberto_entity.library');

use Joomla\Registry\Registry;
use Phproberto\Joomla\Entity\Content\Article;
use Phproberto\Joomla\Entity\EntityCollection;

$articles = new EntityCollection(array(Article::instance(69), Article::instance(70), Article::instance(71)));

// Collection implements Iterator so you can traverse it like
foreach ($articles as $articleId => $article)
{
    echo $articleId . '. ' . $article->get('title') . '<br />';
}

// It also implements Countable
echo 'Collecton has ' . $articles->count() . ' entities <br />';

// Check if an article is in the collection
if ($articles->has(69))
{
    echo $articles->get(69)->getId() . '. ' . $articles->get(69)->get('title') . '<br />';
}

// Add entities
$articles->add(Article::instance(72));<commit_msg>[doc] example collection returned by entity<commit_after># Entity collection class

`Phproberto\Joomla\Entity\EntityCollection`

> Class to perform common actions on groups of entities.

## Index <a id="index"></a>

* [Usage](#usage)
* [Methods](#methods)
    * [add(EntityInterface $entity)](#add)
    * [clear()](#clear)
    * [count()](#count)
    * [current()](#current)
    * [has($id)](#has)
    * [get($id)](#get)
    * [ids()](#ids)
    * [isEmpty()](#isEmpty)
    * [key()](#key)
    * [next()](#next)
    * [remove($id)](#remove)
    * [rewind()](#rewind)
    * [valid()](#valid)
    * [write(EntityInterface $entity, $overwrite = true)](#write)

## Usage <a id="usage"></a>

A couple of fast examples:

```php
<?php
JLoader::import('phproberto_entity.library');

use Joomla\Registry\Registry;
use Phproberto\Joomla\Entity\Content\Article;
use Phproberto\Joomla\Entity\EntityCollection;

$articles = new EntityCollection(array(Article::instance(69), Article::instance(70), Article::instance(71)));

// Collection implements Iterator so you can traverse it like
foreach ($articles as $articleId => $article)
{
    echo $articleId . '. ' . $article->get('title') . '<br />';
}

// It also implements Countable
echo 'Collecton has ' . $articles->count() . ' entities <br />';

// Other entities can return collections
$article = Article::instance(71);

foreach ($article->getTags() as $tagId => $tag)
{
    echo 'Tag ' . $tagId . '. ' . $tag->get('title') . '<br />';
}

// Check if an article is in the collection
if ($articles->has(69))
{
    echo $articles->get(69)->getId() . '. ' . $articles->get(69)->get('title') . '<br />';
}

// Add entities
$articles->add(Article::instance(72));
{'fraction_non_alphanumeric': 0.21243686868686867, 'fraction_numerical': 0.00946969696969697, 'mean_word_length': 4.317114093959732, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 41, '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': '2192837', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1035, 'n_words': 229}