Completed
Push — master ( 1a9043...984777 )
by Valentyn
08:31
created

GuestsFixtures   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
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 29
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
     * @throws \Doctrine\DBAL\DBALException
16
     */
17
    public function load(ObjectManager $manager): void
18
    {
19
        if ($manager instanceof EntityManager === false) {
20
            throw new \InvalidArgumentException('UsersFixtures $manager should be instance of EntityManager');
21
        }
22
23
        /** @var $manager EntityManager */
24
        $this->createGuestSession(self::GUEST_SESSION_TOKEN, $manager);
25
    }
26
27
    /**
28
     * @param string $token
29
     * @param EntityManager $manager
30
     * @throws \Doctrine\DBAL\DBALException
31
     */
32
    private function createGuestSession(string $token, EntityManager $manager): void
33
    {
34
        $date = new \DateTimeImmutable('+1 week');
35
        $manager->getConnection()->exec("INSERT INTO guest_sessions (id, token, expires_at) VALUES (NEXTVAL('guest_sessions_id_seq'), '{$token}', '{$date->format('m-d-Y')}');");
36
    }
37
}