Helper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultCharacters() 0 4 1
A random() 0 11 3
1
<?php
2
/*
3
 * This file is part of badcow-common.
4
 *
5
 * (c) Samuel Williams <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Badcow\Common;
12
13
class Helper
14
{
15
    /**
16
     * Generates the default characters
17
     *
18
     * @return array
19
     */
20 18
    private static function defaultCharacters()
21
    {
22 18
        return array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
23
    }
24
25
    /**
26
     * @param int $len
27
     * @param array $chars Use custom characters. Defaults to upper and lower case alphanumeric characters.
28
     * @return string
29
     */
30 18
    public static function random($len = 32, array $chars = null)
31
    {
32 18
        $chars = $chars ?: self::defaultCharacters();
33 18
        $output = '';
34
35 18
        for ($i = 0; $i < $len; $i++) {
36 18
            $output .= $chars[array_rand($chars)];
37 12
        }
38
39 18
        return $output;
40
    }
41
}