File   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A generate() 0 9 2
1
<?php
2
namespace Sesshin\EntropyGenerator;
3
4
use Sesshin\Exception;
5
6
class File implements EntropyGeneratorInterface
7
{
8
    private $file;
9
    private $length;
10
11
    /**
12
     * @param string $file
13
     * @param int $length
14
     */
15
    public function __construct($file = '/dev/urandom', $length = 512)
16
    {
17
        $this->file = $file;
18
        $this->length = $length;
19
    }
20
21
    /**
22
     * @return string
23
     * @throws Exception
24
     */
25
    public function generate()
26
    {
27
        $entropy = file_get_contents($this->file, false, null, 0, $this->length);
28
        if (empty($entropy)) {
29
            throw new Exception('Entropy file is empty.');
30
        }
31
32
        return $entropy;
33
    }
34
}
35