<commit_before><?php

namespace OpenCFP\Http\API;

use OpenCFP\Application;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\JsonResponse as Response;

class ApiController 
{
    /**
     * @var Application
     */
    protected $app;

    protected $statusCode = Response::HTTP_OK;

    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    public function setStatusCode($status)
    {
        $this->statusCode = $status;
        return $this;
    }

    public function getStatusCode()
    {
        return $this->statusCode;
    }

    /**
     * Returns a rendered Twig response.
     *
     * @param array $data
     * @param array $headers
     *
     * @return mixed
     */
    public function respond(array $data, array $headers = [])
    {
        return new Response($data, $this->getStatusCode(), $headers);
    }

    public function respondUnauthorized($message = 'Unauthorized')
    {
        return $this->setStatusCode(Response::HTTP_UNAUTHORIZED)->respondWithError($message);
    }

    public function respondForbidden($message = 'Forbidden')
    {
        return $this->setStatusCode(Response::HTTP_FORBIDDEN)->respondWithError($message);
    }

    public function respondNotFound($message = 'Resource not found')
    {
        return $this->setStatusCode(Response::HTTP_NOT_FOUND)->respond($message);
    }

    public function respondInternalError($message = 'Internal server error')
    {
        return $this->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR)->respondWithError($message);
    }

    public function respondWithError($message)
    {
        if ($this->statusCode === Response::HTTP_OK) {
            trigger_error(
                "You need to stellar reason to error with a 200 HTTP status code, Mr. Spock.",
                E_USER_WARNING
            );
        }
        return $this->respond([
            'message' => $message,
        ]);
    }

    /**
     * @param string $route  Route name to redirect to
     * @param int    $status
     *
     * @return RedirectResponse
     */
    public function redirectTo($route, $status = 302)
    {
        return $this->app->redirect($this->url($route), $status);
    }
} <commit_msg>Add docblocks to base controller for API<commit_after><?php

namespace OpenCFP\Http\API;

use OpenCFP\Application;
use Symfony\Component\HttpFoundation\JsonResponse as Response;

class ApiController 
{
    protected $statusCode = Response::HTTP_OK;

    /**
     * @param $status
     *
     * @return $this
     */
    public function setStatusCode($status)
    {
        $this->statusCode = $status;
        return $this;
    }

    /**
     * @return int
     */
    public function getStatusCode()
    {
        return $this->statusCode;
    }

    /**
     * Returns a rendered Twig response.
     *
     * @param array $data
     * @param array $headers
     *
     * @return mixed
     */
    public function respond(array $data, array $headers = [])
    {
        return new Response($data, $this->getStatusCode(), $headers);
    }

    /**
     * @param string $message
     *
     * @return mixed
     */
    public function respondUnauthorized($message = 'Unauthorized')
    {
        return $this->setStatusCode(Response::HTTP_UNAUTHORIZED)->respondWithError($message);
    }

    /**
     * @param string $message
     *
     * @return mixed
     */
    public function respondForbidden($message = 'Forbidden')
    {
        return $this->setStatusCode(Response::HTTP_FORBIDDEN)->respondWithError($message);
    }

    /**
     * @param string $message
     *
     * @return mixed
     */
    public function respondNotFound($message = 'Resource not found')
    {
        return $this->setStatusCode(Response::HTTP_NOT_FOUND)->respond($message);
    }

    /**
     * @param string $message
     *
     * @return mixed
     */
    public function respondInternalError($message = 'Internal server error')
    {
        return $this->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR)->respondWithError($message);
    }

    /**
     * @param $message
     *
     * @return mixed
     */
    public function respondWithError($message)
    {
        if ($this->statusCode === Response::HTTP_OK) {
            trigger_error(
                "You need to stellar reason to error with a 200 HTTP status code, Mr. Spock.",
                E_USER_WARNING
            );
        }
        return $this->respond([
            'message' => $message,
        ]);
    }
} 
{'fraction_non_alphanumeric': 0.12045003309066843, 'fraction_numerical': 0.001985440105890139, 'mean_word_length': 2.326485693323551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '921371', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1268, 'n_words': 279}