Code Duplication    Length = 42-52 lines in 2 locations

src/Plugin/RandomLib/Source/RandomOrg.php 1 location

@@ 33-84 (lines=52) @@
30
 * @author     Pol Dellaiera <[email protected]>
31
 * @codeCoverageIgnore
32
 */
33
class RandomOrg extends \RandomLib\AbstractSource {
34
35
  /**
36
   * The Random.Org API.
37
   *
38
   * @var RandomOrgAPI
39
   */
40
  protected $randomOrgAPI;
41
42
  /**
43
   * RandomOrg constructor.
44
   */
45
  public function __construct() {
46
    $this->randomOrgAPI = new RandomOrgAPI();
47
    $this->randomOrgAPI->setApiKey(file_get_contents('./apikey'));
48
  }
49
50
  /**
51
   * Return an instance of Strength indicating the strength of the source
52
   *
53
   * @return \SecurityLib\Strength An instance of one of the strength classes
54
   */
55
  public static function getStrength() {
56
    return new Strength(Strength::HIGH);
57
  }
58
59
  /**
60
   * If the source is currently available.
61
   * Reasons might be because the library is not installed
62
   *
63
   * @return bool
64
   */
65
  public static function isSupported() {
66
    return class_exists('RandomOrgAPI');
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
    $result = $this->randomOrgAPI->call('generateStrings', ['n' => 1, 'length' => $size])
79
      ->getResult();
80
81
    return $result['random']['data'][0];
82
  }
83
84
}
85

src/Plugin/RychRandom/Generator/RandomOrg.php 1 location

@@ 13-54 (lines=42) @@
10
 *
11
 * @codeCoverageIgnore
12
 */
13
class RandomOrg implements GeneratorInterface {
14
15
  /**
16
   * The Random.Org API.
17
   *
18
   * @var RandomOrgAPI
19
   */
20
  protected $randomOrgAPI;
21
22
  /**
23
   * RandomOrg constructor.
24
   */
25
  public function __construct() {
26
    $this->randomOrgAPI = new RandomOrgAPI();
27
    $this->randomOrgAPI->setApiKey(file_get_contents('./apikey'));
28
  }
29
30
  /**
31
   * {@inheritdoc}
32
   */
33
  public static function getPriority() {
34
    return GeneratorInterface::PRIORITY_HIGH;
35
  }
36
37
  /**
38
   * {@inheritdoc}
39
   */
40
  public static function isSupported() {
41
    return class_exists('RandomOrgAPI');
42
  }
43
44
  /**
45
   * {@inheritdoc}
46
   */
47
  public function generate($size) {
48
    $result = $this->randomOrgAPI->call('generateStrings', ['n' => 1, 'length' => $size])
49
      ->getResult();
50
51
    return $result['random']['data'][0];
52
  }
53
54
}
55