<commit_before><?php

declare(strict_types=1);

namespace ForceHttpsModule;

use Psr\Http\Message\ResponseInterface;
use Webmozart\Assert\Assert;
use Zend\Expressive\Router\RouteResult;
use Zend\Http\PhpEnvironment\Response;
use Zend\Router\RouteMatch;

trait HttpsTrait
{
    /** @var bool */
    private $needsWwwPrefix;

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

    private function isSchemeHttps(string $uriScheme) : bool
    {
        return $uriScheme === 'https';
    }

    /**
     * Check Config if is going to be forced to https.
     *
     * @param  RouteMatch|RouteResult|null $match
     */
    private function isGoingToBeForcedToHttps($match = null) : bool
    {
        $is404 = $match === null || ($match instanceof RouteResult && $match->isFailure());
        if (isset($this->config['allow_404']) &&
            $this->config['allow_404'] === true &&
            $is404
        ) {
            return true;
        }

        if ($is404) {
            return false;
        }

        Assert::notNull($match);
        if (! $this->config['force_all_routes'] &&
            ! \in_array(
                $match->getMatchedRouteName(),
                $this->config['force_specific_routes']
            )
        ) {
            return false;
        }

        return true;
    }

    /**
     * Check if Setup Strict-Transport-Security need to be skipped.
     *
     * @param RouteMatch|RouteResult|null $match
     * @param Response|ResponseInterface  $response
     *
     */
    private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null, $response) : bool
    {
        return ! $this->isSchemeHttps($uriScheme) ||
            ! $this->isGoingToBeForcedToHttps($match) ||
            ! isset(
                $this->config['strict_transport_security']['enable'],
                $this->config['strict_transport_security']['value']<commit_msg>combine if when possible<commit_after><?php

declare(strict_types=1);

namespace ForceHttpsModule;

use Psr\Http\Message\ResponseInterface;
use Webmozart\Assert\Assert;
use Zend\Expressive\Router\RouteResult;
use Zend\Http\PhpEnvironment\Response;
use Zend\Router\RouteMatch;

trait HttpsTrait
{
    /** @var bool */
    private $needsWwwPrefix;

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

    private function isSchemeHttps(string $uriScheme) : bool
    {
        return $uriScheme === 'https';
    }

    /**
     * Check Config if is going to be forced to https.
     *
     * @param  RouteMatch|RouteResult|null $match
     */
    private function isGoingToBeForcedToHttps($match = null) : bool
    {
        $is404 = $match === null || ($match instanceof RouteResult && $match->isFailure());
        if ($is404) {
            if (! isset($this->config['allow_404'])) {
                return false;
            }

            return $this->config['allow_404'];
        }

        Assert::notNull($match);
        if (! $this->config['force_all_routes'] &&
            ! \in_array(
                $match->getMatchedRouteName(),
                $this->config['force_specific_routes']
            )
        ) {
            return false;
        }

        return true;
    }

    /**
     * Check if Setup Strict-Transport-Security need to be skipped.
     *
     * @param RouteMatch|RouteResult|null $match
     * @param Response|ResponseInterface  $response
     *
     */
    private function isSkippedHttpStrictTransportSecurity(string $uriScheme, $match = null, $response) : bool
    {
        return ! $this->isSchemeHttps($uriScheme) ||
            ! $this->isGoingToBeForcedToHttps($match) ||
            ! isset(
                $this->config['strict_transport_security']['enable'],
                $this->config['strict_transport_security']['value']
{'fraction_non_alphanumeric': 0.12708058124174373, 'fraction_numerical': 0.007661822985468956, 'mean_word_length': 2.2807625649913343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1259603', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1093, 'n_words': 211}