Helper::defaultCharacters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
}