Shortener::toBase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
ccs 9
cts 9
cp 1
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MuhamedDidovic\Shortener;
6
7
/**
8
 * Class Shortener.
9
 */
10
class Shortener
11
{
12
    /**
13
     * @var string
14
     */
15
    private $base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
16
17
    /**
18
     * @param     $value
19
     * @param int $base
20
     * @return mixed|string
21
     */
22 22
    public function toBase($value, $base = 62)
23
    {
24 22
        $r = $value % $base;
25 22
        $result = $this->base[$r];
26 22
        $q = floor($value / $base);
27
28 22
        while ($q) {
29 4
            $r = $q % $base;
30 4
            $q = floor($q / $base);
31 4
            $result = $this->base[$r].$result;
32
        }
33
34 22
        return $result;
35
    }
36
}
37