UsersInitializer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A init() 0 28 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\UsersBundle\Bundle\Initializer;
15
16
use DateTime;
17
use Doctrine\ORM\EntityManagerInterface;
18
use Zikula\CoreBundle\Bundle\Initializer\BundleInitializerInterface;
19
use Zikula\UsersBundle\Entity\User;
20
use Zikula\UsersBundle\UsersConstant;
21
22
class UsersInitializer implements BundleInitializerInterface
23
{
24
    public function __construct(private readonly EntityManagerInterface $entityManager)
25
    {
26
    }
27
28
    public function init(): void
29
    {
30
        $now = new DateTime();
31
        $then = new DateTime('1970-01-01 00:00:00');
32
33
        // Anonymous
34
        $user = (new User())->setId(UsersConstant::USER_ID_ANONYMOUS);
35
        $user->setUsername('guest');
36
        $user->setEmail('');
37
        $user->setActivated(UsersConstant::ACTIVATED_ACTIVE)
38
            ->setApprovedDate($then)
39
            ->setApprovedBy(UsersConstant::USER_ID_ADMIN)
40
            ->setRegistrationDate($then)
41
            ->setLastLogin($then);
42
        $this->entityManager->persist($user);
43
44
        // Admin
45
        $user = (new User())->setId(UsersConstant::USER_ID_ADMIN);
46
        $user->setUsername('admin');
47
        $user->setEmail('');
48
        $user->setActivated(UsersConstant::ACTIVATED_ACTIVE)
49
            ->setApprovedDate($now)
50
            ->setApprovedBy(UsersConstant::USER_ID_ADMIN)
51
            ->setRegistrationDate($now)
52
            ->setLastLogin($then);
53
        $this->entityManager->persist($user);
54
55
        $this->entityManager->flush();
56
    }
57
}
58