<commit_before><?php

namespace Kreait\Firebase\Http;

use Kreait\Firebase\Exception\InvalidArgumentException;
use Psr\Http\Message\RequestInterface;

class Middleware
{
    /**
     * Ensures that the ".json" suffix is added to URIs and that the content type is set correctly.
     *
     * @return callable
     */
    public static function ensureJson(): callable
    {
        return function (callable $handler) {
            return function (RequestInterface $request, array $options = []) use ($handler) {
                $uri = $request->getUri();
                $path = $uri->getPath();

                try {
                    if (substr($path, -5) !== '.json') {
                        $uri = $uri->withPath($path.'.json');
                        $request = $request->withUri($uri);
                    }

                    $request = $request->withHeader('Content-Type', 'application/json');
                } catch (\InvalidArgumentException $e) {
                    return new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
                }

                return $handler($request, $options);
            };
        };
    }

    /**
     * Adds custom authentication to a request.
     *
     * @param \Kreait\Firebase\Http\Auth $override
     *
     * @return callable
     */
    public static function overrideAuth(Auth $override): callable
    {
        return function (callable $handler) use ($override) {
            return function (RequestInterface $request, array $options = []) use ($handler, $override) {
                return $handler($override->authenticateRequest($request), $options);
            };
        };
    }
}
<commit_msg>Don't catch what can actually never happen :)<commit_after><?php

namespace Kreait\Firebase\Http;

use Kreait\Firebase\Exception\InvalidArgumentException;
use Psr\Http\Message\RequestInterface;

class Middleware
{
    /**
     * Ensures that the ".json" suffix is added to URIs and that the content type is set correctly.
     *
     * @return callable
     */
    public static function ensureJson(): callable
    {
        return function (callable $handler) {
            return function (RequestInterface $request, array $options = []) use ($handler) {
                $uri = $request->getUri();
                $path = $uri->getPath();

                if (substr($path, -5) !== '.json') {
                    /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
                    $uri = $uri->withPath($path.'.json');
                    $request = $request->withUri($uri);
                }

                /** @noinspection ExceptionsAnnotatingAndHandlingInspection */
                $request = $request->withHeader('Content-Type', 'application/json');

                return $handler($request, $options);
            };
        };
    }

    /**
     * Adds custom authentication to a request.
     *
     * @param \Kreait\Firebase\Http\Auth $override
     *
     * @return callable
     */
    public static function overrideAuth(Auth $override): callable
    {
        return function (callable $handler) use ($override) {
            return function (RequestInterface $request, array $options = []) use ($handler, $override) {
                return $handler($override->authenticateRequest($request), $options);
            };
        };
    }
}

{'fraction_non_alphanumeric': 0.12578055307760927, 'fraction_numerical': 0.0005947071067499256, 'mean_word_length': 1.9612676056338028, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '1189145', 'n_tokens_mistral': 892, 'n_tokens_neox': 851, 'n_words': 216}