UrlParser::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 10
cc 3
nc 3
nop 1
crap 3.0416
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\Melvin\Parsers;
6
7
class UrlParser
8
{
9
    private const EMPTY_VALUES = [
10
        '',
11
        'n.v.t.',
12
        'n.v.t',
13
    ];
14
15 6
    public function parse(string $url): ?string
16
    {
17 6
        if (in_array($url, self::EMPTY_VALUES, true)) {
18 6
            return null;
19
        }
20
21 6
        if (!str_contains($url, '://')) {
22
            $url = 'https://'.$url;
23
        }
24
25 6
        return $url;
26
    }
27
}
28