<commit_before><?php
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2015, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints as Doctrine;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Base user
 *
 * @ORM\Entity(repositoryClass="Darvin\UserBundle\Repository\UserRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\Table(name="user")
 * @Doctrine\UniqueEntity(fields={"email"})
 */
class BaseUser implements \Serializable, AdvancedUserInterface
{
    const BASE_USER_CLASS = __CLASS__;

    const ROLE_USER = 'ROLE_USER';

    /**
     * @var int
     *
     * @ORM\Column(type="integer", unique=true)
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Id
     */
    protected $id;

    /**
     * @var \Darvin\UserBundle\Entity\PasswordResetToken
     *
     * @ORM\OneToOne(targetEntity="Darvin\UserBundle\Entity\PasswordResetToken", mappedBy="user", cascade={"remove"})
     */
    protected $passwordResetToken;

    /**
     * @var bool
     *
     * @ORM\Column(type="boolean")
     */
    protected $locked;

    /**
     * @var bool
     *
     * @ORM\Column(type="boolean")
     */
    protected $enabled;

    /**
     * @var array
     *
     * @ORM\Column(type="simple_array", nullable=true)
     */
    protected $roles;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $password;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $salt;

    /**
     * @var string
     *
     * @ORM\Column(type="string", unique=true)
     *
     * @Assert\Email
     * @Assert\NotBlank
     */
    protected $email;

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

    /**
     * @var string
     *
     * @Assert\NotBlank(groups={"AdminNew", "PasswordReset", "Register"})
     */
    protected $plainPassword;

    /**
     * @param bool $locked  Is locked
     * @param bool $enabled Is enabled
     */
    public function __construct($locked = false, $enabled = true)
    {
        $this->locked = $locked;
        $this->enabled = $enabled;
        $this->roles = [];
        $this->updatedAt = new \DateTime();
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->email;
    }

    /**
     * {@inheritdoc}
     */
    public function serialize()
    {
        return serialize([
            $this->id,
            $this->email,
            $this->password,
            $this->salt,
            $this->roles,
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function unserialize($serialized)
    {
        list(
            $this->id,
            $this->email,
            $this->password,
            $this->salt,
            $this->roles
        ) = unserialize($serialized);
    }

    /**
     * @param string $role Role
     *
     * @return BaseUser
     */
    public function addRole($role)
    {
        if (!empty($role) && !in_array($role, $this->roles)) {
            $this->roles[] = $role;
        }

        return $this;
    }

    /**
     * @param string $role Role
     *
     * @return BaseUser
     */
    public function removeRole($role)
    {
        unset($this->roles[array_search($role, $this->roles)]);

        return $this;
    }

    /**
     * @return BaseUser
     */
    public function generateRandomPlainPassword()<commit_msg>Remove redundant BaseUser::addRole() and BaseUser::removeRole().<commit_after><?php
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2015, <NAME>
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints as Doctrine;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Base user
 *
 * @ORM\Entity(repositoryClass="Darvin\UserBundle\Repository\UserRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\Table(name="user")
 * @Doctrine\UniqueEntity(fields={"email"})
 */
class BaseUser implements \Serializable, AdvancedUserInterface
{
    const BASE_USER_CLASS = __CLASS__;

    const ROLE_USER = 'ROLE_USER';

    /**
     * @var int
     *
     * @ORM\Column(type="integer", unique=true)
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Id
     */
    protected $id;

    /**
     * @var \Darvin\UserBundle\Entity\PasswordResetToken
     *
     * @ORM\OneToOne(targetEntity="Darvin\UserBundle\Entity\PasswordResetToken", mappedBy="user", cascade={"remove"})
     */
    protected $passwordResetToken;

    /**
     * @var bool
     *
     * @ORM\Column(type="boolean")
     */
    protected $locked;

    /**
     * @var bool
     *
     * @ORM\Column(type="boolean")
     */
    protected $enabled;

    /**
     * @var array
     *
     * @ORM\Column(type="simple_array", nullable=true)
     */
    protected $roles;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $password;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $salt;

    /**
     * @var string
     *
     * @ORM\Column(type="string", unique=true)
     *
     * @Assert\Email
     * @Assert\NotBlank
     */
    protected $email;

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

    /**
     * @var string
     *
     * @Assert\NotBlank(groups={"AdminNew", "PasswordReset", "Register"})
     */
    protected $plainPassword;

    /**
     * @param bool $locked  Is locked
     * @param bool $enabled Is enabled
     */
    public function __construct($locked = false, $enabled = true)
    {
        $this->locked = $locked;
        $this->enabled = $enabled;
        $this->roles = [];
        $this->updatedAt = new \DateTime();
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->email;
    }

    /**
     * {@inheritdoc}
     */
    public function serialize()
    {
        return serialize([
            $this->id,
            $this->email,
            $this->password,
            $this->salt,
            $this->roles,
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function unserialize($serialized)
    {
        list(
            $this->id,
            $this->email,
            $this->password,
            $this->salt,
            $this->roles
        ) = unserialize($serialized);
    }

    /**
     * @return BaseUser
     */
    public function generateRandomPlainPassword()
{'fraction_non_alphanumeric': 0.15028248587570622, 'fraction_numerical': 0.0011299435028248588, 'mean_word_length': 2.0508401551055577, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 44, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6157223', 'n_tokens_mistral': 2235, 'n_tokens_neox': 2165, 'n_words': 398}