UnsupportedVersionException   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 25
wmc 1
lcom 0
cbo 1
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A forVersion() 0 11 1
1
<?php
2
3
/*
4
 * This file is part of the webmozart/json package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
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 Webmozart\Json\Migration;
13
14
use Exception;
15
use Webmozart\Json\Conversion\ConversionFailedException;
16
17
/**
18
 * Thrown when a version is not supported.
19
 *
20
 * @since  1.3
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class UnsupportedVersionException extends ConversionFailedException
25
{
26
    /**
27
     * Creates an exception for an unknown version.
28
     *
29
     * @param string         $version       The version that caused the
30
     *                                      exception
31
     * @param string[]       $knownVersions The known versions
32
     * @param Exception|null $cause         The exception that caused this
33
     *                                      exception
34
     *
35
     * @return static The created exception
36
     */
37 2
    public static function forVersion($version, array $knownVersions, Exception $cause = null)
38
    {
39 2
        usort($knownVersions, 'version_compare');
40
41 2
        return new static(sprintf(
42
            'Cannot process JSON at version %s. The supported versions '.
43 2
            'are %s.',
44
            $version,
45 2
            implode(', ', $knownVersions)
46 2
        ), 0, $cause);
47
    }
48
}
49