<commit_before><?php

namespace Phisby;

use RuntimeException;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use Phisby\Constraint\StatusCodeConstraint;
use Phisby\Constraint\HeadersConstraint;
use Phisby\Constraint\JSONTypesConstraint;
use Phisby\Constraint\BodyContainsConstraint;
use Phisby\Constraint\JSONConstraint;

/**
 * Phisby is a library designed to easily test REST API endpoints
 *
 * Example:
 * <code>
 * <?php
 * use Phisby\Phisby;
 *
 * $frisby = new Phisby();
 *
 * $frisby
 *   ->get('http://localhost/api/1.0/users/3.json')
 *   ->expectStatus(200)
 *   ->expectJSONTypes('.', [
 *     'id'        => 'integer',
 *     'username'  => 'string',
 *     'is_admin'  => 'boolean'
 *   ])
 *   ->expectJSON('.', [
 *     'id'        => 3,
 *     'username'  => 'johndoe',
 *     'is_admin'  => false
 *   ])
 *   ->send();
 *
 * </code>
 *
 * @author <NAME> <<EMAIL>>
 */
class Phisby
{
    /**
     * @var array Request options
     */
    private $client;

    /**
     * @var \Phisby\Phisby[]
     */
    private $children = [];

    /**
     * @var \Phisby\Expectation
     */
    private $expectation;

    /**
     * @var array Request options
     */
    private $options = [];

    /**
     * @var string Request method
     */
    private $method;

    /**
     * @var array Request data
     */
    private $data;

    /**
     * @var string Request url
     */
    private $url;

    /**
     * @var callable Assertion failure callback
     */
    private $onFailureCallback;

    /**
     * @param \GuzzleHttp\ClientInterface $client
     */
    public function __construct(ClientInterface $client)
    {
        $this->client      = $client ?: new Client();
        $this->expectation = new Expectation();
    }

    /**
     * Creates a new Phisby
     *
     * @return \Phisby\Phisby
     */
    public function create()
    {
        $phisby = new Phisby($this->client);

        $phisby->withOptions($this->options);

        $this->children[] = $phisby;

        return $phisby;
    }

    /**
     * @return \Phisby\Response[]
     */
    public function sendAll()
    {
        $responses = [];

        foreach ($this->children as $phisby) {
            $responses[] = $phisby->send();
        }

        return $responses;
    }

    /**
     * @return \Phisby\Response
     */
    public function send()
    {
        $options = $this->options;
        $method  = $this->method;
        $url     = $this->url;

        if ($this->data !== null) {
            $options['json'] = $this->data;
        }

        try {
            $resp = $this->client->request($method, $url, $options);
        } catch (RequestException $e) {
            if ( ! $e->hasResponse()) {
                throw $e;
            }
<commit_msg>added nullable at constructor<commit_after><?php

namespace Phisby;

use RuntimeException;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use Phisby\Constraint\StatusCodeConstraint;
use Phisby\Constraint\HeadersConstraint;
use Phisby\Constraint\JSONTypesConstraint;
use Phisby\Constraint\BodyContainsConstraint;
use Phisby\Constraint\JSONConstraint;

/**
 * Phisby is a library designed to easily test REST API endpoints
 *
 * Example:
 * <code>
 * <?php
 * use Phisby\Phisby;
 *
 * $frisby = new Phisby();
 *
 * $frisby
 *   ->get('http://localhost/api/1.0/users/3.json')
 *   ->expectStatus(200)
 *   ->expectJSONTypes('.', [
 *     'id'        => 'integer',
 *     'username'  => 'string',
 *     'is_admin'  => 'boolean'
 *   ])
 *   ->expectJSON('.', [
 *     'id'        => 3,
 *     'username'  => 'johndoe',
 *     'is_admin'  => false
 *   ])
 *   ->send();
 *
 * </code>
 *
 * @author <NAME> <<EMAIL>>
 */
class Phisby
{
    /**
     * @var array Request options
     */
    private $client;

    /**
     * @var \Phisby\Phisby[]
     */
    private $children = [];

    /**
     * @var \Phisby\Expectation
     */
    private $expectation;

    /**
     * @var array Request options
     */
    private $options = [];

    /**
     * @var string Request method
     */
    private $method;

    /**
     * @var array Request data
     */
    private $data;

    /**
     * @var string Request url
     */
    private $url;

    /**
     * @var callable Assertion failure callback
     */
    private $onFailureCallback;

    /**
     * @param \GuzzleHttp\ClientInterface $client (opcional)
     */
    public function __construct(ClientInterface $client = null)
    {
        $this->client      = $client ?: new Client();
        $this->expectation = new Expectation();
    }

    /**
     * Creates a new Phisby
     *
     * @return \Phisby\Phisby
     */
    public function create()
    {
        $phisby = new Phisby($this->client);

        $phisby->withOptions($this->options);

        $this->children[] = $phisby;

        return $phisby;
    }

    /**
     * @return \Phisby\Response[]
     */
    public function sendAll()
    {
        $responses = [];

        foreach ($this->children as $phisby) {
            $responses[] = $phisby->send();
        }

        return $responses;
    }

    /**
     * @return \Phisby\Response
     */
    public function send()
    {
        $options = $this->options;
        $method  = $this->method;
        $url     = $this->url;

        if ($this->data !== null) {
            $options['json'] = $this->data;
        }

        try {
            $resp = $this->client->request($method, $url, $options);
        } catch (RequestException $e) {
            if (!$e->hasResponse()) {
                throw $e;
            }

{'fraction_non_alphanumeric': 0.15851930570315267, 'fraction_numerical': 0.002479631597591215, 'mean_word_length': 1.9243915069911963, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 67, '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': '1420313', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1784, 'n_words': 369}