<commit_before><?php

namespace Pum\Bundle\AppBundle\Extension\Security;

use Doctrine\ORM\EntityManager;
use Pum\Bundle\AppBundle\Entity\User;
use Pum\Bundle\AppBundle\Entity\Group;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;

class SecurityManager
{
    /**
     * @var EntityManager 
     */
    protected $em;

    /**
     * @var EncoderFactory 
     */
    protected $encoder;

    public function __construct(EntityManager $entityManager, EncoderFactory $encoder)
    {
        $this->em      = $entityManager;
        $this->encoder = $encoder;
    }

    public function createSuperAdminGroup($name = 'Super administrators')
    {
        $superAdminGroup = new Group($name);
        $superAdminGroup
            ->setPermissions(Group::getKnownPermissions())
        ;

        $this->em->persist($superAdminGroup);
        $this->em->flush();

        return $superAdminGroup;
    }

    public function createUserGroup()
    {
        $userGroup = new Group('Users');
        $userGroup
            ->setPermissions(array(
                'ROLE_PA_LIST',
                'ROLE_PA_VARS',
                'ROLE_PA_VIEW_EDIT',
                'ROLE_PA_CUSTOM_VIEWS',
                'ROLE_PA_ROUTING',
            ))
        ;
        ;

        $this->em->persist($userGroup);
        $this->em->flush();

        return $userGroup;
    }

    public function createSuperAdmin($email, $fullname, $pwd)
    {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new \RuntimeException(sprintf('Your email "%s" is invalid.', $email));
        }

        $user = new User($email);
        $user
            ->setFullname($fullname)
            ->setPassword($pwd, $this->encoder)
            ->addGroup($this->createSuperAdminGroup())
        ;

        $this->em->persist($user);
        $this->em->flush();

        return $user;
    }

    public function createUser($email, $fullname, $pwd, Group $group = null)
    {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new \RuntimeException(sprintf('Your email "%s" is invalid.', $email));
        }

        $user = new User($email);
        $user
            ->setFullname($fullname)
            ->setPassword($pwd, $this->encoder)
        ;

        if (null !== $group) {
            $user->addGroup($group);
        }

        $this->em->persist($user);
        $this->em->flush();

        return $user;
    }
}
<commit_msg>fix group<commit_after><?php

namespace Pum\Bundle\AppBundle\Extension\Security;

use Doctrine\ORM\EntityManager;
use Pum\Bundle\AppBundle\Entity\User;
use Pum\Bundle\AppBundle\Entity\Group;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;

class SecurityManager
{
    /**
     * @var EntityManager 
     */
    protected $em;

    /**
     * @var EncoderFactory 
     */
    protected $encoder;

    public function __construct(EntityManager $entityManager, EncoderFactory $encoder)
    {
        $this->em      = $entityManager;
        $this->encoder = $encoder;
    }

    public function createSuperAdminGroup($name = 'Super administrators')
    {
        $superAdminGroup = new Group($name);
        $superAdminGroup
            ->setPermissions(Group::getKnownPermissions())
            ->setAdmin(true)
        ;

        $this->em->persist($superAdminGroup);
        $this->em->flush();

        return $superAdminGroup;
    }

    public function createUserGroup()
    {
        $userGroup = new Group('Users');
        $userGroup
            ->setPermissions(array(
                'ROLE_PA_LIST',
                'ROLE_PA_VARS',
                'ROLE_PA_VIEW_EDIT',
                'ROLE_PA_CUSTOM_VIEWS',
                'ROLE_PA_ROUTING',
            ))
        ;
        ;

        $this->em->persist($userGroup);
        $this->em->flush();

        return $userGroup;
    }

    public function createSuperAdmin($email, $fullname, $pwd)
    {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new \RuntimeException(sprintf('Your email "%s" is invalid.', $email));
        }

        $user = new User($email);
        $user
            ->setFullname($fullname)
            ->setPassword($pwd, $this->encoder)
            ->setGroup($this->createSuperAdminGroup())
        ;

        $this->em->persist($user);
        $this->em->flush();

        return $user;
    }

    public function createUser($email, $fullname, $pwd, Group $group = null)
    {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new \RuntimeException(sprintf('Your email "%s" is invalid.', $email));
        }

        $user = new User($email);
        $user
            ->setFullname($fullname)
            ->setPassword($pwd, $this->encoder)
        ;

        if (null !== $group) {
            $user->setGroup($group);
        }

        $this->em->persist($user);
        $this->em->flush();

        return $user;
    }
}

{'fraction_non_alphanumeric': 0.13784715183458343, 'fraction_numerical': 0.0, 'mean_word_length': 1.986682808716707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, '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': '6035637', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1441, 'n_words': 250}