Completed
Branch master (9455de)
by Michael
03:34 queued 01:29
created

Support::mcryptCiphers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 21
ccs 18
cts 18
cp 1
rs 9.3142
cc 1
eloc 18
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Dcrypt\Support;
4
5
class Support
6
{
7
8 1
    public static function mcryptCiphers()
9
    {
10
        return array(
11 1
            MCRYPT_3DES,
12 1
            MCRYPT_BLOWFISH,
13 1
            MCRYPT_BLOWFISH_COMPAT,
14 1
            MCRYPT_DES,
15 1
            MCRYPT_LOKI97,
16 1
            MCRYPT_CAST_128,
17 1
            MCRYPT_CAST_256,
18 1
            MCRYPT_RC2,
19 1
            MCRYPT_RIJNDAEL_128,
20 1
            MCRYPT_RIJNDAEL_192,
21 1
            MCRYPT_RIJNDAEL_256,
22 1
            MCRYPT_SAFERPLUS,
23 1
            MCRYPT_SERPENT,
24 1
            MCRYPT_TRIPLEDES,
25 1
            MCRYPT_TWOFISH,
26 1
            MCRYPT_XTEA,
27 1
        );
28
    }
29
30 1
    public static function mcryptModes()
31
    {
32
        return array(
33 1
            MCRYPT_MODE_CBC,
34 1
            MCRYPT_MODE_CFB,
35 1
            MCRYPT_MODE_ECB,
36 1
            MCRYPT_MODE_OFB,
37 1
            MCRYPT_MODE_NOFB,
38 1
        );
39
    }
40
41
    /**
42
     * Change a random byte, randomly. This function is used in unit testing
43
     * only and never in the namespaced areas of code.
44
     * 
45
     * @param string $input
46
     * @return string
47
     */
48 4
    public static function swaprandbyte($input)
49
    {
50
        // @codeCoverageIgnoreStart
51
        $len = strlen($input);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52
        $input = str_split($input);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53
        $offset = rand(0, $len - 1);
54
        $byte = $input[$offset];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
55
        $rbyte = \Dcrypt\Random::bytes(1);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56
        if ($byte === $rbyte) {
57
            $rbyte = (ord($rbyte) + 1) % 256;
58
            $rbyte = chr($rbyte);
59
        }
60
        $input[$offset] = $rbyte;
61
62
        // @codeCoverageIgnoreEnd
63 4
        return implode($input);
64
    }
65
66
}
67