Shortener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toBase() 0 14 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