NotValidUrlException::value()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
/*
3
 * This file is part of the "andrey-helldar/support" project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Andrey Helldar <[email protected]>
9
 *
10
 * @copyright 2021 Andrey Helldar
11
 *
12
 * @license MIT
13
 *
14
 * @see https://github.com/andrey-helldar/support
15
 */
16
17
namespace Helldar\Support\Exceptions;
18
19
use Exception;
20
21
class NotValidUrlException extends Exception
22
{
23 14
    public function __construct(?string $url)
24
    {
25 14
        $value = $this->value($url);
26
27 14
        $message = $this->message($value);
28
29 14
        parent::__construct($message, 412);
30 14
    }
31
32 14
    protected function value(?string $url): string
33
    {
34 14
        if (! empty($url)) {
35 7
            return 'The "' . $url . '"';
36
        }
37
38 7
        return 'Empty string';
39
    }
40
41 14
    protected function message(string $value): string
42
    {
43 14
        return $value . ' is not a valid URL.';
44
    }
45
}
46