Completed
Pull Request — master (#506)
by Alejandro
13:13
created

generateRandomShortCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core;
6
7
use PUGX\Shortid\Factory as ShortIdFactory;
8
9
function generateRandomShortCode(int $length = 5): string
10
{
11
    static $shortIdFactory;
12
    if ($shortIdFactory === null) {
13
        $shortIdFactory = new ShortIdFactory();
14
    }
15
16
    $alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
17
    return $shortIdFactory->generate($length, $alphabet)->serialize();
18
}
19