<commit_before><?php

namespace Aidantwoods\BetterOptions\Groups;

use Exception;
use Aidantwoods\BetterOptions\Group;
use Aidantwoods\BetterOptions\Option;
use Aidantwoods\BetterOptions\Response;
use Aidantwoods\BetterOptions\GroupObject;

class ANDGroup implements Group
{
    private $objects = array(),
            $name;

    /**
     * Add an object to the group
     *
     * @param GroupObject &$object the object to add
     *
     * @return Group return the current group instance
     */
    public function add(GroupObject $object) : Group
    {
        $this->objects[] = $object;

        return $this;
    }

    /**
     * Get objects in a group
     *
     * @return GroupObject[]
     *  return an array of GroupObject objects
     */
    public function get() : array
    {
        return $this->objects;
    }

    /**
     * Give the group a name so that it may be easily retrieved
     *
     * @param string $name the group name
     */
    public function setName(string $name)
    {
        $this->name = $name;
    }

    /**
     * Get the group a name
     *
     * @return string the group name
     */
    public function getName() : ?string
    {
        return $this->name;
    }

    /**
     * Validate the group is complete.
     * A group is responsible for defining its own completeness 
     *
     * @return bool true if the group is complete, false otherwise
     */
    public function isSet() : bool
    {
        if (count($this->objects) < 1)
        {
            throw new Exception("ANDGroup contains too few objects");
        }

        $i = 0;

        foreach ($this->objects as $object)
        {
            if ($object->isSet())
            {
                $i++;
            }
        }

        return count($this->objects) === $i;
    }

    /**
     * Object may offer a response to its unset state. An object MUST return
     * the responses of its members when their unset state contributes to its
     * unset state. An object SHOULD nest member responses.
     *
     * @return Response[] return an array of Response objects, or Response
     * objects nested in another array
     */
    public function respond() : array
    {
        $responses = array();

        if ( ! $this->isSet())
        {
            $responses[] = new Response(
                $this->getPrintableName().' must all be set'
            );
            
            $memberResponses = array();

            foreach ($this->objects as $object)
            {
                $memberResponses[] = $object->respond();
            }

            // $responses[] = $memberResponses;
        }

        return $responses;
    }

    /**
     * Get the printable names of all members, and return these delimited in<commit_msg>update response to make sense in more cases<commit_after><?php

namespace Aidantwoods\BetterOptions\Groups;

use Exception;
use Aidantwoods\BetterOptions\Group;
use Aidantwoods\BetterOptions\Option;
use Aidantwoods\BetterOptions\Response;
use Aidantwoods\BetterOptions\GroupObject;

class ANDGroup implements Group
{
    private $objects = array(),
            $name;

    /**
     * Add an object to the group
     *
     * @param GroupObject &$object the object to add
     *
     * @return Group return the current group instance
     */
    public function add(GroupObject $object) : Group
    {
        $this->objects[] = $object;

        return $this;
    }

    /**
     * Get objects in a group
     *
     * @return GroupObject[]
     *  return an array of GroupObject objects
     */
    public function get() : array
    {
        return $this->objects;
    }

    /**
     * Give the group a name so that it may be easily retrieved
     *
     * @param string $name the group name
     */
    public function setName(string $name)
    {
        $this->name = $name;
    }

    /**
     * Get the group a name
     *
     * @return string the group name
     */
    public function getName() : ?string
    {
        return $this->name;
    }

    /**
     * Validate the group is complete.
     * A group is responsible for defining its own completeness 
     *
     * @return bool true if the group is complete, false otherwise
     */
    public function isSet() : bool
    {
        if (count($this->objects) < 1)
        {
            throw new Exception("ANDGroup contains too few objects");
        }

        $i = 0;

        foreach ($this->objects as $object)
        {
            if ($object->isSet())
            {
                $i++;
            }
        }

        return count($this->objects) === $i;
    }

    /**
     * Object may offer a response to its unset state. An object MUST return
     * the responses of its members when their unset state contributes to its
     * unset state. An object SHOULD nest member responses.
     *
     * @return Response[] return an array of Response objects, or Response
     * objects nested in another array
     */
    public function respond() : array
    {
        $responses = array();

        if ( ! $this->isSet())
        {
            $responses[] = new Response(
                $this->getPrintableName().' must be set'
            );
            
            $memberResponses = array();

            foreach ($this->objects as $object)
            {
                $memberResponses[] = $object->respond();
            }

            // $responses[] = $memberResponses;
        }

        return $responses;
    }

    /**
     * Get the printable names of all members, and return these delimited in
{'fraction_non_alphanumeric': 0.09996391194514616, 'fraction_numerical': 0.0007217610970768675, 'mean_word_length': 1.7536015896671635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '5489392', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1466, 'n_words': 499}