Completed
Pull Request — master (#289)
by Gavin
16:24 queued 13:47
created

InvalidUrlException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 33
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidUrl() 0 9 2
A invalidUrlParts() 0 8 1
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 implements HttpCacheExceptionInterface
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
    public static function invalidUrl($url, $reason = null)
26
    {
27
        $msg = sprintf('URL "%s" is invalid.', $url);
28
        if ($reason) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $reason of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
29
            $msg .= sprintf(' Reason: %s', $reason);
30
        }
31
32
        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
    public static function invalidUrlParts($server, array $allowed)
42
    {
43
        return new self(sprintf(
44
            'Server "%s" is invalid. Only %s URL parts are allowed.',
45
            $server,
46
            implode(', ', $allowed)
47
        ));
48
    }
49
}
50