<commit_before><?php

namespace Yubikey;

class ResponseCollection implements \Countable, \Iterator, \ArrayAccess
{
    /**
     * Set of \Yubikey\Response objects
     * @var array
     */
    private $responses = array();

    /**
     * Position in the data set (for Iterator)
     * @var integer
     */
    private $position = 0;

    /**
     * Init the object and set the Response objects if provided
     *
     * @param array $responses Response object set
     */
    public function __construct(array $responses = array())
    {
        if (!empty($responses)) {
            foreach ($responses as $response) {
                $this->add($response);
            }
        }
    }

    /**
     * Determine, based on the Response status (success)
     *     if the overall operation was successful
     *
     * @return boolean Success/fail status
     */
    public function success($first = false)
    {
        $success = false;
        if ($first === true) {
            // Sort them by timestamp, pop the first one and return pass/fail
            usort($this->responses, function($r1, $r2) {
                return $r1->getMt() > $r2->getMt();
            });
            $response = $this->responses[0];
            return $response->success();
        } else {
            foreach ($this->responses as $response) {
                if ($response->success() === false) {
                    return false;
                } else {
                    $success = true;
                }
            }
        }
        return $success;
    }

    /**<commit_msg>typehints added on usort response handling<commit_after><?php

namespace Yubikey;

class ResponseCollection implements \Countable, \Iterator, \ArrayAccess
{
    /**
     * Set of \Yubikey\Response objects
     * @var array
     */
    private $responses = array();

    /**
     * Position in the data set (for Iterator)
     * @var integer
     */
    private $position = 0;

    /**
     * Init the object and set the Response objects if provided
     *
     * @param array $responses Response object set
     */
    public function __construct(array $responses = array())
    {
        if (!empty($responses)) {
            foreach ($responses as $response) {
                $this->add($response);
            }
        }
    }

    /**
     * Determine, based on the Response status (success)
     *     if the overall operation was successful
     *
     * @return boolean Success/fail status
     */
    public function success($first = false)
    {
        $success = false;
        if ($first === true) {
            // Sort them by timestamp, pop the first one and return pass/fail
            usort($this->responses, function(\Yubikey\Response $r1, \Yubikey\Response $r2) {
                return $r1->getMt() > $r2->getMt();
            });
            $response = $this->responses[0];
            return $response->success();
        } else {
            foreach ($this->responses as $response) {
                if ($response->success() === false) {
                    return false;
                } else {
                    $success = true;
                }
            }
        }
        return $success;
    }

    /**
{'fraction_non_alphanumeric': 0.1175007771215418, 'fraction_numerical': 0.003730183400683867, 'mean_word_length': 1.578525641025641, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3849319', 'n_tokens_mistral': 873, 'n_tokens_neox': 848, 'n_words': 247}