<commit_before><?php

namespace Digbang\Security\Persistences;

use Cartalyst\Sentinel\Cookies\CookieInterface;
use Cartalyst\Sentinel\Persistences\PersistableInterface;
use Cartalyst\Sentinel\Persistences\PersistenceInterface;
use Cartalyst\Sentinel\Sessions\SessionInterface;
use Cartalyst\Sentinel\Users\UserInterface;
use Digbang\Security\Users\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;

abstract class DoctrinePersistenceRepository extends EntityRepository implements PersistenceRepository
{
    /**
     * @var SessionInterface
     */
    private $session;

    /**
     * @var CookieInterface
     */
    private $cookie;

    /**
     * @var bool
     */
    private $single = false;

    /**
     * @param EntityManager    $entityManager the EntityManager to use
     * @param SessionInterface $session
     * @param CookieInterface  $cookie
     */
    public function __construct(EntityManager $entityManager, SessionInterface $session, CookieInterface $cookie)
    {
        parent::__construct($entityManager, $entityManager->getClassMetadata(
            $this->entityName()
        ));

        $this->session = $session;
        $this->cookie = $cookie;
    }

    /**
     * Checks for a persistence code in the current session.
     *
     * @return string
     */
    public function check(): ?string
    {
        if ($code = $this->session->get()) {
            return $code;
        }

        if ($code = $this->cookie->get()) {
            return $code;
        }

        return null;
    }

    /**
     * Finds a persistence by persistence code.
     *
     * @param  string $code
     *
     * @return Persistence|PersistenceInterface|null
     */
    public function findByPersistenceCode(string $code): ?PersistenceInterface
    {
        return $this->findOneBy(['code' => $code]) ?: null;
    }

    /**
     * Finds a user by persistence code.
     *
     * @param  string $code
     *
     * @return \Digbang\Security\Users\DefaultUser|UserInterface|null
     */
    public function findUserByPersistenceCode(string $code): ?UserInterface
    {<commit_msg>Keep session alive when cookie is present<commit_after><?php

namespace Digbang\Security\Persistences;

use Cartalyst\Sentinel\Cookies\CookieInterface;
use Cartalyst\Sentinel\Persistences\PersistableInterface;
use Cartalyst\Sentinel\Persistences\PersistenceInterface;
use Cartalyst\Sentinel\Sessions\SessionInterface;
use Cartalyst\Sentinel\Users\UserInterface;
use Digbang\Security\Users\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;

abstract class DoctrinePersistenceRepository extends EntityRepository implements PersistenceRepository
{
    /**
     * @var SessionInterface
     */
    private $session;

    /**
     * @var CookieInterface
     */
    private $cookie;

    /**
     * @var bool
     */
    private $single = false;

    /**
     * @param EntityManager    $entityManager the EntityManager to use
     * @param SessionInterface $session
     * @param CookieInterface  $cookie
     */
    public function __construct(EntityManager $entityManager, SessionInterface $session, CookieInterface $cookie)
    {
        parent::__construct($entityManager, $entityManager->getClassMetadata(
            $this->entityName()
        ));

        $this->session = $session;
        $this->cookie = $cookie;
    }

    /**
     * Checks for a persistence code in the current session.
     *
     * @return string
     */
    public function check(): ?string
    {
        if ($code = $this->session->get()) {
            return $code;
        }

        if ($code = $this->cookie->get()) {
            $this->session->put($code);

            return $code;
        }

        return null;
    }

    /**
     * Finds a persistence by persistence code.
     *
     * @param  string $code
     *
     * @return Persistence|PersistenceInterface|null
     */
    public function findByPersistenceCode(string $code): ?PersistenceInterface
    {
        return $this->findOneBy(['code' => $code]) ?: null;
    }

    /**
     * Finds a user by persistence code.
     *
     * @param  string $code
     *
     * @return \Digbang\Security\Users\DefaultUser|UserInterface|null
     */
    public function findUserByPersistenceCode(string $code): ?UserInterface
    {
{'fraction_non_alphanumeric': 0.10874101553443079, 'fraction_numerical': 0.0, 'mean_word_length': 2.6221662468513856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '1882620', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1191, 'n_words': 267}