CAPICOM   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 0
cbo 2
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStrength() 0 4 1
A isSupported() 0 4 1
A generate() 0 13 2
1
<?php
2
3
/*
4
 * The RandomLib library for securely generating random numbers and strings in PHP
5
 *
6
 * @author     Anthony Ferrara <[email protected]>
7
 * @copyright  2011 The Authors
8
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
9
 * @version    Build @@version@@
10
 */
11
12
/**
13
 * The Capicom Random Number Source
14
 *
15
 * This uses the Windows CapiCom Com object to generate random numbers
16
 *
17
 * PHP version 5.3
18
 *
19
 * @category   PHPCryptLib
20
 * @package    Random
21
 * @subpackage Source
22
 *
23
 * @author     Anthony Ferrara <[email protected]>
24
 * @copyright  2011 The Authors
25
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
26
 *
27
 * @version    Build @@version@@
28
 */
29
namespace RandomLib\Source;
30
31
use SecurityLib\Strength;
32
33
/**
34
 * The Capicom Random Number Source
35
 *
36
 * This uses the Windows CapiCom Com object to generate random numbers
37
 *
38
 * @category   PHPCryptLib
39
 * @package    Random
40
 * @subpackage Source
41
 *
42
 * @author     Anthony Ferrara <[email protected]>
43
 * @codeCoverageIgnore
44
 */
45
class CAPICOM extends \RandomLib\AbstractSource
46
{
47
48
    /**
49
     * Return an instance of Strength indicating the strength of the source
50
     *
51
     * @return \SecurityLib\Strength An instance of one of the strength classes
52
     */
53
    public static function getStrength()
54
    {
55
        return new Strength(Strength::MEDIUM);
56
    }
57
58
    /**
59
     * If the source is currently available.
60
     * Reasons might be because the library is not installed
61
     *
62
     * @return bool
63
     */
64
    public static function isSupported()
65
    {
66
        return class_exists('\\COM', false);
67
    }
68
69
    /**
70
     * Generate a random string of the specified size
71
     *
72
     * @param int $size The size of the requested random string
73
     *
74
     * @return string A string of the requested size
75
     */
76
    public function generate($size)
77
    {
78
        try {
79
            $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...
80
            $data = base64_decode($util->GetRandom($size, 0));
81
82
            return str_pad($data, $size, chr(0));
83
        } catch (\Exception $e) {
84
            unset($e);
85
86
            return static::emptyValue($size);
87
        }
88
    }
89
}
90