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

GuestsFixtures::createGuestSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
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
}