<commit_before><?php

namespace Good\Manners;

use Good\Manners\Comparison\Collection\HasA;
use Good\Manners\Comparison\Collection\HasOnly;
use Good\Manners\Comparison\EqualTo;

class CollectionComparisonsHolder
{
    private $comparisons = [];

    private $collectedType;

    public function __construct($collectedType)
    {
        $this->collectedType = $collectedType;
    }

    public function getComparisons()
    {
        return $this->comparisons;
    }

    public function hasA($comparison = null)
    {
        if ($comparison == null)
        {
            $condition = $collectedType::condition();

            $this->conditions[] = new HasA($condition);

            return $condition;
        }

        if (!($comparison instanceof Comparison))
        {
            $comparison = new EqualTo($comparison);
        }

        $this->comparisons[] = new HasA($comparison);
    }

    public function hasOnly($comparison = null)
    {
        if ($comparison == null)
        {
            $condition = $collectedType::condition();

            $this->conditions[] = new HasOnly($condition);

            return $condition;<commit_msg>[#143] Throw exception for invalid API usage<commit_after><?php

namespace Good\Manners;

use Good\Manners\Comparison\Collection\HasA;
use Good\Manners\Comparison\Collection\HasOnly;
use Good\Manners\Comparison\EqualTo;

class CollectionComparisonsHolder
{
    private $comparisons = [];

    private $collectedType;

    public function __construct($collectedType)
    {
        $this->collectedType = $collectedType;
    }

    public function getComparisons()
    {
        return $this->comparisons;
    }

    public function hasA($comparison = null)
    {
        if ($comparison == null)
        {
            if ($this->collectedType == null)
            {
                throw new \Exception("Unable to use hasA without an argument for a collection of scalar values");
            }

            $condition = $this->collectedType::condition();

            $this->comparisons[] = new HasA($condition);

            return $condition;
        }

        if (!($comparison instanceof Comparison))
        {
            $comparison = new EqualTo($comparison);
        }

        $this->comparisons[] = new HasA($comparison);
    }

    public function hasOnly($comparison = null)
    {
        if ($comparison == null)
        {
            if ($this->collectedType == null)
            {
                throw new \Exception("Unable to use hasA without an argument for a collection of scalar values");
            }

            $condition = $this->collectedType::condition();

            $this->comparisons[] = new HasOnly($condition);

            return $condition;
{'fraction_non_alphanumeric': 0.11314536799707067, 'fraction_numerical': 0.0010984987184181618, 'mean_word_length': 2.2255017709563165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2879746', 'n_tokens_mistral': 738, 'n_tokens_neox': 699, 'n_words': 167}