<commit_before><?php

namespace Etu\Core\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="etu_users_sessions")
 * @ORM\Entity()
 */
class Session
{
    const TYPE_ORGA = 'orga';
    const TYPE_USER = 'user';

    /**
     * @var integer
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=10, nullable=true)
     */
    protected $entityType;

    /**
     * @var integer
     *
     * @ORM\Column(type="integer")
     */
    protected $entityId;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=200)
     */
    protected $name;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=64)
     */
    protected $token;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $expireAt;

    /**
     * Constructor
     */
    public function __construct($type, $id)
    {
        $this->entityType = $type;
        $this->entityId = $id;
        $this->expireAt = new \DateTime('+1 year');
        $this->token = hash('sha256', time() . uniqid('', true));
    }

    public function createName()
    {
        if (! empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        $browser = get_browser();

        $name = [];
        $name[] = $browser->browser;
        $name[] = $browser->version;
        $name[] = $browser->platform;
        $name[] = '('. gethostbyaddr($ip) .')';

        $this->name = implode(' ', $name);
    }

    /**
     * @return int<commit_msg>Check for get_browser availability to avoid errors<commit_after><?php

namespace Etu\Core\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="etu_users_sessions")
 * @ORM\Entity()
 */
class Session
{
    const TYPE_ORGA = 'orga';
    const TYPE_USER = 'user';

    /**
     * @var integer
     *
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=10, nullable=true)
     */
    protected $entityType;

    /**
     * @var integer
     *
     * @ORM\Column(type="integer")
     */
    protected $entityId;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=200)
     */
    protected $name;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=64)
     */
    protected $token;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $expireAt;

    /**
     * Constructor
     */
    public function __construct($type, $id)
    {
        $this->entityType = $type;
        $this->entityId = $id;
        $this->expireAt = new \DateTime('+1 year');
        $this->token = hash('sha256', time() . uniqid('', true));
    }

    public function createName()
    {
        if (! empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        if (function_exists('get_browser')) {
            $browser = get_browser();

            $name = [];
            $name[] = $browser->browser;
            $name[] = $browser->version;
            $name[] = $browser->platform;
            $name[] = '('. gethostbyaddr($ip) .')';

            $this->name = implode(' ', $name);
        } else {
            $this->name = $ip . ' (' . gethostbyaddr($ip) . ')';
        }
    }

    /**
     * @return int
{'fraction_non_alphanumeric': 0.1811686654758867, 'fraction_numerical': 0.005613676958407757, 'mean_word_length': 1.912332838038633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '516369', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1287, 'n_words': 213}