<commit_before><?php

namespace Helldar\ApiResponse\Services;

use Symfony\Component\HttpFoundation\JsonResponse;

class ApiResponseService
{
    /**
     * @var mixed
     */
    protected $content = null;

    /**
     * @var int
     */
    protected $status_code = 200;

    /**
     * @var array
     */
    protected $headers = [];

    /**
     * @return \Helldar\ApiResponse\Services\ApiResponseService
     */
    public static function init()
    {
        return new self();
    }

    /**
     * @param int $status
     *
     * @return $this
     */
    public function status($status = 200)
    {
        $this->status_code = (int) $status;

        return $this;
    }

    /**
     * @param mixed $content
     *
     * @return $this
     */
    public function content($content = null)
    {
        $this->content = $content;

        return $this;
    }

    /**
     * @param array $headers
     *
     * @return $this
     */
    public function headers($headers = [])
    {
        $this->headers = array_merge($this->headers, $headers);

        return $this;
    }

    /**
     * @deprecated
     *
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function send()
    {
        return $this->response();
    }

    /**
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function response()
    {
        if ($this->isError()) {
            $this->setErrorContent();
        }

        return $this->jsonResponse();
    }

    protected function isError()
    {
        return $this->status_code >= 400;
    }

    protected function setErrorContent()
    {
        $this->content = [
            'error' => [
                'code' => $this->status_code,
                'msg' => $this->content,
            ],
        ];
    }

    /**
     * @return JsonResponse
     */
    protected function jsonResponse()
    {
        return JsonResponse::create($this->content, $this->status_code, $this->headers)
            ->send();
    }
}<commit_msg>Fixed error of output of duplicate messages on successful sending<commit_after><?php

namespace Helldar\ApiResponse\Services;

use Symfony\Component\HttpFoundation\JsonResponse;

class ApiResponseService
{
    /**
     * @var mixed
     */
    protected $content = null;

    /**
     * @var int
     */
    protected $status_code = 200;

    /**
     * @var array
     */
    protected $headers = [];

    /**
     * @return \Helldar\ApiResponse\Services\ApiResponseService
     */
    public static function init()
    {
        return new self();
    }

    /**
     * @param int $status
     *
     * @return $this
     */
    public function status($status = 200)
    {
        $this->status_code = (int) $status;

        return $this;
    }

    /**
     * @param mixed $content
     *
     * @return $this
     */
    public function content($content = null)
    {
        $this->content = $content;

        return $this;
    }

    /**
     * @param array $headers
     *
     * @return $this
     */
    public function headers($headers = [])
    {
        $this->headers = array_merge($this->headers, $headers);

        return $this;
    }

    /**
     * @deprecated
     *
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function send()
    {
        return $this->response();
    }

    /**
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function response()
    {
        if ($this->isError()) {
            $this->setErrorContent();
        }

        return $this->jsonResponse();
    }

    protected function isError()
    {
        return $this->status_code >= 400;
    }

    protected function setErrorContent()
    {
        $this->content = [
            'error' => [
                'code' => $this->status_code,
                'msg'  => $this->content,
            ],
        ];
    }

    /**
     * @return JsonResponse
     */
    protected function jsonResponse()
    {
        return JsonResponse::create($this->content, $this->status_code, $this->headers);
    }
}
{'fraction_non_alphanumeric': 0.1390922401171303, 'fraction_numerical': 0.004392386530014641, 'mean_word_length': 1.6913985554826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, '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': '1866551', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1178, 'n_words': 234}