GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ChecksumIterator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0
ccs 22
cts 22
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A serializeCurrent() 0 5 2
A setSerializer() 0 4 1
A current() 0 4 1
A getChecksum() 0 10 2
A __toString() 0 4 1
1
<?php
2
3
namespace Gielfeldt\Iterators;
4
5
class ChecksumIterator extends TraversableIterator
6
{
7
    protected $algo;
8
9
    protected $callback;
10
11 3
    public function __construct(\Traversable $iterator, $algo = 'sha256')
12
    {
13 3
        $this->algo = $algo;
14 3
        $this->callback = \Closure::fromCallable([static::class, 'serializeCurrent']);
15 3
        parent::__construct($iterator);
16 3
    }
17
18 2
    public static function serializeCurrent($iterator)
19
    {
20 2
        $current = $iterator->current();
21 2
        return is_scalar($current) ? $current : serialize($current);
22
    }
23
24 1
    public function setSerializer(callable $callback)
25
    {
26 1
        $this->callback = \Closure::fromCallable($callback);
27 1
    }
28
29 3
    public function current()
30
    {
31 3
        return hash($this->algo, ($this->callback)($this->getInnerIterator()));
32
    }
33
34 3
    public function getChecksum()
35
    {
36 3
        $ctx = hash_init($this->algo);
37 3
        $this->rewind();
38 3
        while ($this->valid()) {
39 3
            hash_update($ctx, ($this->callback)($this));
40 3
            $this->next();
41
        }
42 3
        return hash_final($ctx);
43
    }
44
45 3
    public function __toString()
46
    {
47 3
        return $this->getChecksum();
48
    }
49
}
50