InvalidUrlException::invalidUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Exception;
13
14
/**
15
 * Thrown during setup if the configuration for a proxy client is invalid.
16
 */
17
class InvalidUrlException extends InvalidArgumentException
18
{
19
    /**
20
     * @param string $url    the invalid URL
21
     * @param string $reason Further explanation why the URL was invalid (optional)
22
     *
23
     * @return self
24
     */
25 1
    public static function invalidUrl($url, $reason = null)
26
    {
27 1
        $msg = sprintf('URL "%s" is invalid.', $url);
28 1
        if ($reason) {
29
            $msg .= sprintf(' Reason: %s', $reason);
30
        }
31
32 1
        return new self($msg);
33
    }
34
35
    /**
36
     * @param string $server  Invalid server
37
     * @param array  $allowed Allowed URL parts
38
     *
39
     * @return self
40
     */
41 2
    public static function invalidUrlParts($server, array $allowed)
42
    {
43 2
        return new self(sprintf(
44 2
            'Server "%s" is invalid. Only %s URL parts are allowed.',
45
            $server,
46 2
            implode(', ', $allowed)
47
        ));
48
    }
49
}
50