GuestsFixtures::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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