TicketIdentityGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateIdentity() 0 3 1
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
}