GuestsFixtures   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 31
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 9 2
A createGuestSession() 0 5 1
1
<?php
2
3
namespace App\Guests\DataFixtures;
4
5
use Doctrine\Bundle\FixturesBundle\Fixture;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Doctrine\ORM\EntityManager;
8
9
class GuestsFixtures extends Fixture
10
{
11
    const GUEST_SESSION_TOKEN = 'pqSDo1qw2nXZtyPqEz3x9ds';
12
13
    /**
14
     * @param ObjectManager $manager
15
     *
16
     * @throws \Doctrine\DBAL\DBALException
17
     */
18
    public function load(ObjectManager $manager): void
19
    {
20
        if ($manager instanceof EntityManager === false) {
21
            throw new \InvalidArgumentException('UsersFixtures $manager should be instance of EntityManager');
22
        }
23
24
        /* @var $manager EntityManager */
25
        $this->createGuestSession(self::GUEST_SESSION_TOKEN, $manager);
26
    }
27
28
    /**
29
     * @param string        $token
30
     * @param EntityManager $manager
31
     *
32
     * @throws \Doctrine\DBAL\DBALException
33
     */
34
    private function createGuestSession(string $token, EntityManager $manager): void
35
    {
36
        $date = new \DateTimeImmutable('+1 week');
37
        $manager->getConnection()->exec("INSERT INTO guest_sessions (id, token, expires_at) VALUES (NEXTVAL('guest_sessions_id_seq'), '{$token}', '{$date->format('m-d-Y')}');");
38
    }
39
}
40