Completed
Push — master ( 4d4232...ffcfa4 )
by Anthony
14:02 queued 11:53
created

CAPICOM::isSupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * The Capicom Random Number Source
4
 *
5
 * This uses the Windows CapiCom Com object to generate random numbers
6
 *
7
 * PHP version 5.3
8
 *
9
 * @category   PHPCryptLib
10
 * @package    Random
11
 * @subpackage Source
12
 * @author     Anthony Ferrara <[email protected]>
13
 * @copyright  2011 The Authors
14
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
15
 * @version    Build @@version@@
16
 */
17
18
namespace RandomLib\Source;
19
20
use SecurityLib\Strength;
21
22
/**
23
 * The Capicom Random Number Source
24
 *
25
 * This uses the Windows CapiCom Com object to generate random numbers
26
 *
27
 * @category   PHPCryptLib
28
 * @package    Random
29
 * @subpackage Source
30
 * @author     Anthony Ferrara <[email protected]>
31
 * @codeCoverageIgnore
32
 */
33
class CAPICOM extends \RandomLib\AbstractSource {
34
35
    /**
36
     * Return an instance of Strength indicating the strength of the source
37
     *
38
     * @return \SecurityLib\Strength An instance of one of the strength classes
39
     */
40
    public static function getStrength() {
41
        return new Strength(Strength::MEDIUM);
42
    }
43
44
    /**
45
     * If the source is currently available.
46
     * Reasons might be because the library is not installed
47
     *
48
     * @return boolean
49
     */
50
    public static function isSupported() {
51
        return class_exists('\\COM', false);
52
    }
53
54
    /**
55
     * Generate a random string of the specified size
56
     *
57
     * @param int $size The size of the requested random string
58
     *
59
     * @return string A string of the requested size
60
     */
61
    public function generate($size) {
62
        try {
63
            $util = new \COM('CAPICOM.Utilities.1');
0 ignored issues
show
Unused Code introduced by
The call to com::__construct() has too many arguments starting with 'CAPICOM.Utilities.1'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
            $data = base64_decode($util->GetRandom($size, 0));
65
            return str_pad($data, $size, chr(0));
66
        } catch (\Exception $e) {
67
            unset($e);
68
            return static::emptyValue($size);
69
        }
70
    }
71
72
}
73