Completed
Push — master ( 5880f8...5ed87e )
by Karsten
02:08
created

BaseUtil::createRandomToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Created by IntelliJ IDEA.
4
 * User: gerk
5
 * Date: 12.04.17
6
 * Time: 06:51
7
 */
8
9
namespace PeekAndPoke\Component\Toolbox;
10
11
12
/**
13
 * @author Karsten J. Gerber <[email protected]>
14
 */
15
abstract class BaseUtil
16
{
17
    /**
18
     * Use this method to soothe warning of your IDE like "unused parameter"
19
     *
20
     * @param array ...$args
21
     */
22 1
    public static function noop(... $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24 1
    }
25
26
    /**
27
     * @param int $length
28
     *
29
     * @return string
30
     */
31 8
    public static function createRandomToken($length = 10)
32
    {
33 8
        $result = '';
34
35 8
        while (\strlen($result) < $length) {
36 7
            $result .= str_replace('.', '', uniqid('', true));
37
        }
38
39 8
        return \substr($result, 0, $length);
40
    }
41
42
    /**
43
     * @param string $dir
44
     * @param int    $mode
45
     *
46
     * @codeCoverageIgnore
47
     */
48
    public static function ensureDirectory($dir, $mode = 0777)
49
    {
50
        $old = error_reporting(0);
51
52
        if (@is_dir($dir)) {
53
            return;
54
        }
55
56
        if (! @mkdir($dir, $mode, true) && ! @is_dir($dir)) {
57
            error_reporting($old);
58
            throw new \RuntimeException('Could not create directory');
59
        }
60
61
        error_reporting($old);
62
    }
63
}
64