<commit_before><?php
/**
 * This file is part of the Tmdb PHP API created by <NAME>.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package Tmdb
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2013, <NAME>
 * @version 0.0.1
 */
namespace Tmdb\Event;

use Tmdb\Exception\RuntimeException;
use Tmdb\HttpClient\HttpClientEventSubscriber;
use Tmdb\HttpClient\Response;

/**
 * Class RequestSubscriber
 * @package Tmdb\Event
 */
class RequestSubscriber extends HttpClientEventSubscriber
{
    public static function getSubscribedEvents()
    {
        return [
            TmdbEvents::REQUEST => 'send',
        ];
    }

    public function send(RequestEvent $event)
    {
        // Preparation of request parameters / Possibility to use for logging and caching etc.
        $event->getDispatcher()->dispatch(TmdbEvents::BEFORE_REQUEST, $event);

        if ($event->isPropagationStopped() && $event->hasResponse()) {
            return $event->getResponse();
        }

        $response = $this->sendRequest($event);
        $event->setResponse($response);

        // Possibility to cache the request
        $event->getDispatcher()->dispatch(TmdbEvents::AFTER_REQUEST, $event);

        return $response;
    }

    /**
     * Call upon the adapter to create an response object
     *
     * @param  RequestEvent $event
     * @throws \Exception
     * @return Response
     */
    public function sendRequest(RequestEvent $event)
    {
        $response = null;

        try {
            switch ($event->getMethod()) {
                case 'GET':
                    $response = $this->getHttpClient()->getAdapter()->get($event->getRequest());
                    break;
                case 'HEAD':
                    $response = $this->getHttpClient()->getAdapter()->head($event->getRequest());
                    break;
                case 'POST':
                    $response = $this->getHttpClient()->getAdapter()->post($event->getRequest());
                    break;
                case 'PUT':
                    $response = $this->getHttpClient()->getAdapter()->put($event->getRequest());
                    break;
                case 'PATCH':
                    $response = $this->getHttpClient()->getAdapter()->patch($event->getRequest());
                    break;
                case 'DELETE':
                    $response = $this->getHttpClient()->getAdapter()->delete($event->getRequest());
                    break;
                default:
                    throw new RuntimeException(sprintf('Unkown request method "%s".', $event->getMethod()));
            }
        } catch (\Exception $e) {
            // @todo create an exception that extracts the error and reports it in a generic clear way
            throw $e;
        }

        return $response;
    }
}<commit_msg>Removing try catch block because this should be down at a higher level<commit_after><?php
/**
 * This file is part of the Tmdb PHP API created by <NAME>.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package Tmdb
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2013, <NAME>
 * @version 0.0.1
 */
namespace Tmdb\Event;

use Tmdb\Exception\RuntimeException;
use Tmdb\HttpClient\HttpClientEventSubscriber;
use Tmdb\HttpClient\Response;

/**
 * Class RequestSubscriber
 * @package Tmdb\Event
 */
class RequestSubscriber extends HttpClientEventSubscriber
{
    public static function getSubscribedEvents()
    {
        return [
            TmdbEvents::REQUEST => 'send',
        ];
    }

    public function send(RequestEvent $event)
    {
        // Preparation of request parameters / Possibility to use for logging and caching etc.
        $event->getDispatcher()->dispatch(TmdbEvents::BEFORE_REQUEST, $event);

        if ($event->isPropagationStopped() && $event->hasResponse()) {
            return $event->getResponse();
        }

        $response = $this->sendRequest($event);
        $event->setResponse($response);

        // Possibility to cache the request
        $event->getDispatcher()->dispatch(TmdbEvents::AFTER_REQUEST, $event);

        return $response;
    }

    /**
     * Call upon the adapter to create an response object
     *
     * @param  RequestEvent $event
     * @throws \Exception
     * @return Response
     */
    public function sendRequest(RequestEvent $event)
    {
        $response = null;

        switch ($event->getMethod()) {
            case 'GET':
                $response = $this->getHttpClient()->getAdapter()->get($event->getRequest());
                break;
            case 'HEAD':
                $response = $this->getHttpClient()->getAdapter()->head($event->getRequest());
                break;
            case 'POST':
                $response = $this->getHttpClient()->getAdapter()->post($event->getRequest());
                break;
            case 'PUT':
                $response = $this->getHttpClient()->getAdapter()->put($event->getRequest());
                break;
            case 'PATCH':
                $response = $this->getHttpClient()->getAdapter()->patch($event->getRequest());
                break;
            case 'DELETE':
                $response = $this->getHttpClient()->getAdapter()->delete($event->getRequest());
                break;
            default:
                throw new RuntimeException(sprintf('Unkown request method "%s".', $event->getMethod()));
        }

        return $response;
    }
}
{'fraction_non_alphanumeric': 0.1305515759312321, 'fraction_numerical': 0.002507163323782235, 'mean_word_length': 2.1253497481813093, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 85, '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': '4024149', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1412, 'n_words': 364}