<commit_before><?php

namespace Waldo\OpenIdConnect\RelyingPartyBundle\Security\Http\Logout;

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * OpenId Connect Logout
 *
 * @author <NAME> <<EMAIL>>
 */
class OICLogout
{
    /**
     * @var TokenStorageInterface 
     */
    private $tokenStorage;

    /**
     * @var HttpUtils  
     */
    private $httpUtils;

    /**
     * @var RouterInterface  
     */
    private $router;

    /**
     * @var array  
     */
    private $options;

    /**
     * @param TokenStorageInterface $tokenStorage
     * @param HttpUtils $httpUtils
     */
    public function __construct(array $options, TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, RouterInterface $router)
    {
        $this->tokenStorage = $tokenStorage;
        $this->httpUtils = $httpUtils;
        $this->router = $router;
        $this->options = $options;  
    }

    
    public function logout(Request $request)
    {
        $request->getSession()->clear();
        $request->getSession()->invalidate();
        $this->tokenStorage->setToken(null);
        
        echo "<pre>:";
        var_dump($request->server->get("HTTP_REFERER"));
        echo "</pre>";exit;



        if($request->server->get("HTTP_REFERER") != $this->httpUtils->generateUri($request, "_oic_rp_logout")) {
            return new RedirectResponse($this->getRedirectAfterLogoutURI($request));
        }
        
        if(array_key_exists("logout", $this->options['endpoints_url'])) {
            return new RedirectResponse($this->getOIDCLogoutEndPointURI($request));
        }        
        
        return new RedirectResponse($this->getRedirectAfterLogoutURI($request));
    }
    
    private function getRedirectAfterLogoutURI(Request $request)
    {
        if($this->router->getRouteCollection()->get($this->options['redirect_after_logout'])) {
            return $this->httpUtils->generateUri($request, $this->options['redirect_after_logout']);<commit_msg>Clean code<commit_after><?php

namespace Waldo\OpenIdConnect\RelyingPartyBundle\Security\Http\Logout;

use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * OpenId Connect Logout
 *
 * @author <NAME> <<EMAIL>>
 */
class OICLogout
{
    /**
     * @var TokenStorageInterface 
     */
    private $tokenStorage;

    /**
     * @var HttpUtils  
     */
    private $httpUtils;

    /**
     * @var RouterInterface  
     */
    private $router;

    /**
     * @var array  
     */
    private $options;

    /**
     * @param TokenStorageInterface $tokenStorage
     * @param HttpUtils $httpUtils
     */
    public function __construct(array $options, TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, RouterInterface $router)
    {
        $this->tokenStorage = $tokenStorage;
        $this->httpUtils = $httpUtils;
        $this->router = $router;
        $this->options = $options;  
    }

    
    public function logout(Request $request)
    {
        $request->getSession()->clear();
        $request->getSession()->invalidate();
        $this->tokenStorage->setToken(null);
 
        $redirectResponse = new RedirectResponse($this->getRedirectAfterLogoutURI($request));
 
        if($request->server->get("HTTP_REFERER") != $this->httpUtils->generateUri($request, "_oic_rp_logout")) {
            $redirectResponse = new RedirectResponse($this->getRedirectAfterLogoutURI($request));
        }
        
        if(array_key_exists("logout", $this->options['endpoints_url'])) {
            $redirectResponse = new RedirectResponse($this->getOIDCLogoutEndPointURI($request));
        }        
        
        return $redirectResponse;
    }
    
    private function getRedirectAfterLogoutURI(Request $request)
    {
        if($this->router->getRouteCollection()->get($this->options['redirect_after_logout'])) {
            return $this->httpUtils->generateUri($request, $this->options['redirect_after_logout']);
{'fraction_non_alphanumeric': 0.13453631795340337, 'fraction_numerical': 0.0, 'mean_word_length': 3.0583873957367933, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, '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': '800202', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1226, 'n_words': 187}