Total Complexity | 4 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | final class RandomOrg extends AbstractSource |
||
23 | { |
||
24 | /** |
||
25 | * The Random.Org API. |
||
26 | */ |
||
27 | protected RandomOrgAPIInterface $randomOrgAPI; |
||
28 | |||
29 | public function __construct(RandomOrgAPIInterface $randomOrgAPI) |
||
30 | { |
||
31 | $this->randomOrgAPI = $randomOrgAPI; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Generate a random string of the specified size. |
||
36 | * |
||
37 | * @param int $size |
||
38 | * The size of the requested random string |
||
39 | * |
||
40 | * @return string |
||
41 | * A string of the requested size |
||
42 | */ |
||
43 | public function generate($size): string |
||
44 | { |
||
45 | $provider = (new Provider())->withResource('generateStrings') |
||
46 | ->withParameters([ |
||
47 | 'n' => 1, |
||
48 | 'length' => $size, |
||
49 | 'characters' => implode( |
||
50 | '', |
||
51 | array_merge( |
||
52 | range('A', 'Z'), |
||
53 | range('a', 'z'), |
||
54 | range(0, 9) |
||
55 | ) |
||
56 | ), |
||
57 | ]); |
||
58 | |||
59 | $result = $this->randomOrgAPI->getData($provider); |
||
60 | |||
61 | return $result[0]; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Return an instance of Strength indicating the strength of the source. |
||
66 | * |
||
67 | * @return \SecurityLib\Strength |
||
68 | * An instance of one of the strength classes |
||
69 | */ |
||
70 | public static function getStrength(): Strength |
||
71 | { |
||
72 | return new Strength(Strength::HIGH); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * If the source is currently available. |
||
77 | * Reasons might be because the library is not installed. |
||
78 | */ |
||
79 | public static function isSupported(): bool |
||
82 | } |
||
83 | } |
||
84 |