Passed
Push — master ( 402f33...7c44c5 )
by Pol
02:04
created

BelgianNationalNumber::isValidNationalNumber()   B

Complexity

Conditions 11
Paths 17

Size

Total Lines 62
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 11.6653

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 33
c 1
b 0
f 0
nc 17
nop 1
dl 0
loc 62
ccs 28
cts 34
cp 0.8235
crap 11.6653
rs 7.3166

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\BelgianNationalNumberFaker\Provider;
6
7
use drupol\BelgianNationalNumberFaker\Validator\BelgianNationalNumberValidator;
8
use Faker\Provider\Base;
9
use Faker\Provider\DateTime;
10
11
/**
12
 * Class BelgianNationalNumber.
13
 */
14
final class BelgianNationalNumber extends Base
15
{
16
    /**
17
     * Generate a random Belgian National Number.
18
     *
19
     * @return string
20
     *
21
     * @see https://en.wikipedia.org/wiki/National_identification_number
22
     */
23 1
    public function belgianNationalIdentificationNumber(): string
24
    {
25
        do {
26 1
            $probe = \mb_substr(DateTime::date('Ymd'), 2) . static::randomNumber(5, true);
27 1
        } while (false === BelgianNationalNumberValidator::isValid($probe));
28
29 1
        return $probe;
30
    }
31
}
32