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.

CharacterSlicer::slice()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 8.9197
cc 4
eloc 14
nc 6
nop 2
1
<?php
2
3
namespace UCD\Infrastructure\Repository\CharacterRepository\FileRepository;
4
5
use UCD\Unicode\Codepoint;
6
use UCD\Unicode\CodepointAssigned;
7
8
class CharacterSlicer
9
{
10
    /**
11
     * @param CodepointAssigned[]|\Traversable $characters
12
     * @param int $size
13
     * @return \Generator
14
     */
15
    public static function slice($characters, $size)
16
    {
17
        $start = Codepoint::MIN;
18
        $tally = 0;
19
        $chunk = [];
20
21
        foreach ($characters as $character) {
22
            array_push($chunk, $character);
23
            $codepoint = $character->getCodepoint();
24
            $current = $codepoint->getValue();
25
26
            if ((++$tally % $size) === 0) {
27
                yield (new Range($start, $current)) => $chunk;
28
                $chunk = [];
29
                $start = ++$current;
30
            }
31
        }
32
33
        if (count($chunk) > 0) {
34
            yield (new Range($start, Codepoint::MAX)) => $chunk;
35
        }
36
    }
37
}