Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ApiKeyGenerator
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 generate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace App\Service\Data;
4
5use Random\RandomException;
6
7class ApiKeyGenerator implements ApiKeyGeneratorInterface
8{
9    /**
10     * @throws RandomException
11     */
12    public function generate(int $length = 32): string
13    {
14        if (0 !== $length % 2) {
15            throw new \InvalidArgumentException('Length must be even');
16        }
17
18        if ($length < 16) {
19            throw new \InvalidArgumentException('Length must be greater than 16');
20        }
21
22        if ($length > 64) {
23            throw new \InvalidArgumentException('Length must be less than 64');
24        }
25
26        return bin2hex(random_bytes($length / 2));
27    }
28}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

ApiKeyGenerator->generate
12    public function generate(int $length = 32): string
13    {
14        if (0 !== $length % 2) {
15            throw new \InvalidArgumentException('Length must be even');
18        if ($length < 16) {
19            throw new \InvalidArgumentException('Length must be greater than 16');
22        if ($length > 64) {
23            throw new \InvalidArgumentException('Length must be less than 64');
26        return bin2hex(random_bytes($length / 2));
27    }
{main}
3namespace App\Service\Data;
4
5use Random\RandomException;
6
7class ApiKeyGenerator implements ApiKeyGeneratorInterface
8{
9    /**
10     * @throws RandomException
11     */
12    public function generate(int $length = 32): string
13    {
14        if (0 !== $length % 2) {
15            throw new \InvalidArgumentException('Length must be even');
16        }
17
18        if ($length < 16) {
19            throw new \InvalidArgumentException('Length must be greater than 16');
20        }
21
22        if ($length > 64) {
23            throw new \InvalidArgumentException('Length must be less than 64');
24        }
25
26        return bin2hex(random_bytes($length / 2));
27    }