<commit_before><?php

namespace Ihsw\Toxiproxy;

use GuzzleHttp\Exception\ClientException as HttpClientException;
use Ihsw\Toxiproxy\Exception\NotFoundException;
use Psr\Http\Message\ResponseInterface;
use Ihsw\Toxiproxy\Exception\ToxicExistsException;
use Ihsw\Toxiproxy\Exception\UnexpectedStatusCodeException;

class Proxy implements \JsonSerializable
{
    use UrlHelpers;

    /**
     * @var Toxiproxy
     */
    private $toxiproxy;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $listen;

    /**
     * @var string
     */
    private $upstream;

    /**
     * @var bool
     */
    private $enabled;

    /**
     * @var Toxic[]
     */
    private $toxics;

    use ListenHelpers;

    /**
     * Proxy constructor.
     * @param Toxiproxy $toxiproxy
     * @param string $name
     */
    public function __construct(Toxiproxy $toxiproxy, $name)
    {
        $this->toxiproxy = $toxiproxy;
        $this->name = $name;
        $this->toxics = [];
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param $listen
     * @return $this
     */
    public function setListen($listen)
    {
        $this->listen = $listen;
        return $this;
    }

    /**
     * @return string
     */
    public function getListen()
    {
        return $this->listen;
    }

    /**
     * @return string
     */
    public function getUpstream()
    {
        return $this->upstream;
    }

    /**
     * @param string $upstream
     * @return $this
     */
    public function setUpstream($upstream)
    {
        $this->upstream = $upstream;
        return $this;
    }

    /**
     * @return bool
     */
    public function isEnabled()
    {
        return $this->enabled;
    }

    /**
     * @param bool $enabled
     * @return $this
     */
    public function setEnabled($enabled)
    {
        $this->enabled = $enabled;
        return $this;
    }

    /**
     * @return array
     */
    public function jsonSerialize()
    {
        return [
            "name" => $this->name,
            "listen" => $this->listen,
            "upstream" => $this->upstream,
            "enabled" => $this->enabled
        ];
    }

    /**
     * @param ResponseInterface $response
     * @return Toxic
     */
    public function responseToToxic(ResponseInterface $response)
    {
        return $this->contentsToToxic(json_decode($response->getBody(), true));
    }

    /**
     * @param array $contents
     * @return Toxic
     */
    private function contentsToToxic(array $contents)
    {
        $toxic = new Toxic(
            $this,
            $contents["name"],
            $contents["type"],
            $contents["stream"]
        );
        $toxic->setToxicity($contents["toxicity"])
            ->setAttributes($contents["attributes"]);

        return $toxic;
    }

    /**
     * @return \GuzzleHttp\Client
     */
    public function getHttpClient()
    {
        return $this->toxiproxy->getHttpClient();
    }

    /**<commit_msg>Remove unnecessary public visibility.<commit_after><?php

namespace Ihsw\Toxiproxy;

use GuzzleHttp\Exception\ClientException as HttpClientException;
use Ihsw\Toxiproxy\Exception\NotFoundException;
use Psr\Http\Message\ResponseInterface;
use Ihsw\Toxiproxy\Exception\ToxicExistsException;
use Ihsw\Toxiproxy\Exception\UnexpectedStatusCodeException;

class Proxy implements \JsonSerializable
{
    use UrlHelpers;

    /**
     * @var Toxiproxy
     */
    private $toxiproxy;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $listen;

    /**
     * @var string
     */
    private $upstream;

    /**
     * @var bool
     */
    private $enabled;

    /**
     * @var Toxic[]
     */
    private $toxics;

    use ListenHelpers;

    /**
     * Proxy constructor.
     * @param Toxiproxy $toxiproxy
     * @param string $name
     */
    public function __construct(Toxiproxy $toxiproxy, $name)
    {
        $this->toxiproxy = $toxiproxy;
        $this->name = $name;
        $this->toxics = [];
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param $listen
     * @return $this
     */
    public function setListen($listen)
    {
        $this->listen = $listen;
        return $this;
    }

    /**
     * @return string
     */
    public function getListen()
    {
        return $this->listen;
    }

    /**
     * @return string
     */
    public function getUpstream()
    {
        return $this->upstream;
    }

    /**
     * @param string $upstream
     * @return $this
     */
    public function setUpstream($upstream)
    {
        $this->upstream = $upstream;
        return $this;
    }

    /**
     * @return bool
     */
    public function isEnabled()
    {
        return $this->enabled;
    }

    /**
     * @param bool $enabled
     * @return $this
     */
    public function setEnabled($enabled)
    {
        $this->enabled = $enabled;
        return $this;
    }

    /**
     * @return array
     */
    public function jsonSerialize()
    {
        return [
            "name" => $this->name,
            "listen" => $this->listen,
            "upstream" => $this->upstream,
            "enabled" => $this->enabled
        ];
    }

    /**
     * @param ResponseInterface $response
     * @return Toxic
     */
    private function responseToToxic(ResponseInterface $response)
    {
        return $this->contentsToToxic(json_decode($response->getBody(), true));
    }

    /**
     * @param array $contents
     * @return Toxic
     */
    private function contentsToToxic(array $contents)
    {
        $toxic = new Toxic(
            $this,
            $contents["name"],
            $contents["type"],
            $contents["stream"]
        );
        $toxic->setToxicity($contents["toxicity"])
            ->setAttributes($contents["attributes"]);

        return $toxic;
    }

    /**
     * @return \GuzzleHttp\Client
     */
    public function getHttpClient()
    {
        return $this->toxiproxy->getHttpClient();
    }

    /**
{'fraction_non_alphanumeric': 0.134203318833575, 'fraction_numerical': 0.0, 'mean_word_length': 1.7529933481152993, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '2826842', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1867, 'n_words': 365}