<commit_before><commit_msg>Adding AttributeCollection Trait<commit_after><?php namespace Arcanedev\Markup\Entities\Traits;

use Arcanedev\Markup\Entities\Tag\AttributeCollection;

trait Attributeable
{
    /* ------------------------------------------------------------------------------------------------
     |  Properties
     | ------------------------------------------------------------------------------------------------
     */
    /** @var AttributeCollection */
    protected $attributes;

    /* ------------------------------------------------------------------------------------------------
     |  Constructor
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Init Attribute Collection
     */
    private function initAttributes()
    {
        $this->attributes = new AttributeCollection;
    }

    /* ------------------------------------------------------------------------------------------------
     |  Getters & Setters
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Set many attributes
     *
     * @param  array $attributes
     *
     * @return self
     */
    public function setAttributes(array $attributes)
    {
        $this->attributes->addMany($attributes);

        return $this;
    }

    /**
     * Set many attributes (Alias)
     *
     * @param  array $attributes
     *
     * @return self
     */
    public function attrs(array $attributes)
    {
        return $this->setAttributes($attributes);
    }

    /**
     * Get Attributes
     *
     * @return array
     */
    public function getAttributes()
    {
        return $this->attributes->toArray();
    }

    /**
     * Set Attribute
     *
     * @param  string       $name
     * @param  string|array $value
     *
     * @return self
     */
    public function attr($name, $value)
    {
        $this->attributes->add($name, $value);

        return $this;
    }

    /* ------------------------------------------------------------------------------------------------
     |  Main Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Get Attributes
     *
     * @return string
     */
    public function renderAttributes()
    {
        return $this->attributes->render();
    }

    /* ------------------------------------------------------------------------------------------------
     |  Check Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Check if has attributes
     *
     * @return bool
     */
    public function hasAttributes()
    {
        return ! empty($this->attributes) and
        ! $this->attributes->isEmpty();
    }
}
{'fraction_non_alphanumeric': 0.4152777777777778, 'fraction_numerical': 0.0, 'mean_word_length': 0.7017129356172475, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, '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': '806312', 'n_tokens_mistral': 568, 'n_tokens_neox': 559, 'n_words': 109}