<commit_before><?php
namespace Corley\MaintenanceBundle\Listener;

use Symfony\Component\HttpFoundation\Response;

class SoftLockListener
{
    private $requestStack;
    private $maintenancePage;
    private $lock;

    private $whitePaths;
    private $whiteIps;

    public function __construct($maintenancePage, $maintenanceLock, array $whitePaths, array $whiteIps)
    {
        $this->maintenancePage = $maintenancePage;
        $this->lock = file_exists($maintenanceLock);
        $this->whiteIps = $this->whiteIps;

        array_walk($whitePaths, function(&$elem) {
            $elem = "/" . str_replace("/", "\\/", $elem) . "/";
        });

        $this->whitePaths = array_replace(array("/^\/_/"), $whitePaths);
        $this->whiteIps = array_replace(array(), $whiteIps);
    }

    public function setRequestStack($requestStack)
    {
        $this->requestStack = $requestStack;
    }

    public function onKernelRequest($event)
    {
        if ($this->isUnderMaintenance()) {
            $response = new Response();
            $response->setStatusCode(503);
            $response->setContent(file_get_contents($this->maintenancePage));

            $event->setResponse($response);
            $event->stopPropagation();
        }
    }

    private function isUnderMaintenance()
    {
        $path = $this->requestStack->getCurrentRequest()->getPathInfo();
        return ($this->lock && $this->isIpNotAuthorized() && $this->isPathUnderMaintenance($path));
    }<commit_msg>Type hinted softlock<commit_after><?php
namespace Corley\MaintenanceBundle\Listener;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class SoftLockListener
{
    private $requestStack;
    private $maintenancePage;
    private $lock;

    private $whitePaths;
    private $whiteIps;

    public function __construct($maintenancePage, $maintenanceLock, array $whitePaths, array $whiteIps)
    {
        $this->maintenancePage = $maintenancePage;
        $this->lock = file_exists($maintenanceLock);
        $this->whiteIps = $this->whiteIps;

        array_walk($whitePaths, function(&$elem) {
            $elem = "/" . str_replace("/", "\\/", $elem) . "/";
        });

        $this->whitePaths = array_replace(array("/^\/_/"), $whitePaths);
        $this->whiteIps = array_replace(array(), $whiteIps);
    }

    public function setRequestStack($requestStack)
    {
        $this->requestStack = $requestStack;
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        if ($this->isUnderMaintenance()) {
            $response = new Response();
            $response->setStatusCode(503);
            $response->setContent(file_get_contents($this->maintenancePage));

            $event->setResponse($response);
            $event->stopPropagation();
        }
    }

    private function isUnderMaintenance()
    {
        $path = $this->requestStack->getCurrentRequest()->getPathInfo();
        return ($this->lock && $this->isIpNotAuthorized() && $this->isPathUnderMaintenance($path));
    }
{'fraction_non_alphanumeric': 0.14425268642136113, 'fraction_numerical': 0.0019537609899055682, 'mean_word_length': 3.010443864229765, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '6247890', 'n_tokens_mistral': 879, 'n_tokens_neox': 862, 'n_words': 141}