TicketIdentityGenerator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ConferenceTools\Tickets\Service\Identity;
4
5
use Carnage\Cqrs\Aggregate\Identity\GeneratorInterface;
6
use RandomLib\Factory;
7
8
/**
9
 * Class TicketIdentityGenerator
10
 *
11
 * Generates a short (7 character identifier)
12
 *
13
 * 10^-6 prob of collision for approx 1500 tickets, should be adequate for most events.
14
 * Purchase Id is also used when modifying tickets online so collisions are only really an issue for manual check ins
15
 * this problem can be resolved by using a sufficiently smart human.
16
 */
17
class TicketIdentityGenerator implements GeneratorInterface
18
{
19
    private $random;
20
21
    public function __construct()
22
    {
23
        $this->random = (new Factory())->getMediumStrengthGenerator();
24
    }
25
26
    public function generateIdentity()
27
    {
28
        return rtrim(strtr(base64_encode($this->random->generate(5)), '+/', '-_'), '=');
29
    }
30
}