StreamHasher::hash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\Flysystem\Util;
4
5
class StreamHasher
6
{
7
    /**
8
     * @var string
9
     */
10
    private $algo;
11
12
    /**
13
     * StreamHasher constructor.
14
     *
15
     * @param string $algo
16
     */
17 3
    public function __construct($algo)
18
    {
19 3
        $this->algo = $algo;
20 3
    }
21
22
    /**
23
     * @param $resource
24
     *
25
     * @return string
26
     */
27 3
    public function hash($resource)
28
    {
29 3
        rewind($resource);
30 3
        $context = hash_init($this->algo);
31 3
        hash_update_stream($context, $resource);
32 3
        fclose($resource);
33
34 3
        return hash_final($context);
35
    }
36
}
37