<commit_before><?php

namespace Lexik\Bundle\MaintenanceBundle\Listener;

use Lexik\Bundle\MaintenanceBundle\Drivers\DriverFactory;
use Lexik\Bundle\MaintenanceBundle\Exception\ServiceUnavailableException;

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

use Symfony\Component\HttpFoundation\IpUtils;

/**
 * Listener to decide if user can access to the site
 *
 * @package LexikMaintenanceBundle
 * @author  <NAME> <<EMAIL>>
 */
class MaintenanceListener
{
    /**
     * Service driver factory
     *
     * @var \Lexik\Bundle\MaintenanceBundle\Drivers\DriverFactory
     */
    protected $driverFactory;

    /**
     * Authorized data
     *
     * @var array
     */
    protected $authorizedIps;
    protected $path;
    protected $host;
    protected $ips;
    protected $query;
    protected $route;
    protected $attributes;

    /**
     * Constructor Listener
     *
     * @param DriverFactory $driverFactory The driver factory
     * @param array         $authorizedIps The ips allowed
     * @param String        $authorizedUri The regex to match the request uri
     * @param String        $authorizedRoute The regex to match the current route
     */
    public function __construct(DriverFactory $driverFactory, $path = null, $host = null, $ips = null, $query = array(), $route = null, $attributes = array())
    {
        $this->driverFactory = $driverFactory;
        $this->path = $path;
        $this->host = $host;
        $this->ips = $ips;
        $this->query = $query;
        $this->route = $route;
        $this->attributes = $attributes;
    }

    /**
     * @param GetResponseEvent $event GetResponseEvent
     *
     * @return void
     *
     * @throws ServiceUnavailableException
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        
        if(is_array($this->query)) {
            foreach ($this->query as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->get($key))) {
                    return false;
                }
            }
        }

        if(is_array($this->attributes)) {
            foreach ($this->attributes as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
                    return false;
                }
            }
        }

        if (null !== $this->path && !empty($this->path) && preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
            return;
        }

        if (null !== $this->host && !empty($this->host) && preg_match('{'.$this->host.'}i', $request->getHost())) {
            return;
        }

        if (count($this->ips) !== 0 && IpUtils::checkIp($request->getClientIp(), $this->ips)) {
            return true;
        }

        if (null !== $this->route && !preg_match('{'.$this->route.'}', $request->get('_route'))) {
            return;
        }

        // Get driver class defined in your configuration
        $driver = $this->driverFactory->getDriver();

        if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
            throw new ServiceUnavailableException();
        }

        return;
    }
}
<commit_msg>Updated phpdoc and remove needless return values<commit_after><?php

namespace Lexik\Bundle\MaintenanceBundle\Listener;

use Lexik\Bundle\MaintenanceBundle\Drivers\DriverFactory;
use Lexik\Bundle\MaintenanceBundle\Exception\ServiceUnavailableException;

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

use Symfony\Component\HttpFoundation\IpUtils;

/**
 * Listener to decide if user can access to the site
 *
 * @package LexikMaintenanceBundle
 * @author  <NAME> <<EMAIL>>
 */
class MaintenanceListener
{
    /**
     * Service driver factory
     *
     * @var \Lexik\Bundle\MaintenanceBundle\Drivers\DriverFactory
     */
    protected $driverFactory;

    /**
     * Authorized data
     *
     * @var array
     */
    protected $authorizedIps;
    protected $path;
    protected $host;
    protected $ips;
    protected $query;
    protected $route;
    protected $attributes;

    /**
     * Constructor Listener
     * 
     * Accepts a driver factory, and several arguments to be compared against the
     * incoming request.
     * When the maintenance mode is enabled, the request will be allowed to bypass
     * it if at least one of the provided arguments is not empty and matches the
     *  incoming request.
     *
     * @param DriverFactory $driverFactory The driver factory
     * @param String $path A regex for the path
     * @param String $host A regex for the host
     * @param array $ips The list of IP addresses
     * @param array $query Query arguments
     * @param String $route Route name
     * @param array $attributes Attributes
     */
    public function __construct(DriverFactory $driverFactory, $path = null, $host = null, $ips = null, $query = array(), $route = null, $attributes = array())
    {
        $this->driverFactory = $driverFactory;
        $this->path = $path;
        $this->host = $host;
        $this->ips = $ips;
        $this->query = $query;
        $this->route = $route;
        $this->attributes = $attributes;
    }

    /**
     * @param GetResponseEvent $event GetResponseEvent
     *
     * @return void
     *
     * @throws ServiceUnavailableException
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        
        if(is_array($this->query)) {
            foreach ($this->query as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->get($key))) {
                    return;
                }
            }
        }

        if(is_array($this->attributes)) {
            foreach ($this->attributes as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
                    return;
                }
            }
        }

        if (null !== $this->path && !empty($this->path) && preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
            return;
        }

        if (null !== $this->host && !empty($this->host) && preg_match('{'.$this->host.'}i', $request->getHost())) {
            return;
        }

        if (count($this->ips) !== 0 && IpUtils::checkIp($request->getClientIp(), $this->ips)) {
            return;
        }

        if (null !== $this->route && !preg_match('{'.$this->route.'}', $request->get('_route'))) {
            return;
        }

        // Get driver class defined in your configuration
        $driver = $this->driverFactory->getDriver();

        if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
            throw new ServiceUnavailableException();
        }

        return;
    }
}

{'fraction_non_alphanumeric': 0.1407512402551382, 'fraction_numerical': 0.00028348688873139615, 'mean_word_length': 2.3189087488240827, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, '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': '2467975', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1945, 'n_words': 461}