Completed
Push — master ( 4fa802...7f958e )
by Bernhard
08:14
created

UnsupportedVersionException::forVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 3
crap 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\ConversionException;
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 ConversionException
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 3
    public static function forVersion($version, array $knownVersions, Exception $cause = null)
38
    {
39 3
        usort($knownVersions, 'version_compare');
40
41 3
        return new static(sprintf(
42
            'Cannot process JSON at version %s. The supported versions '.
43 3
            'are %s.',
44
            $version,
45 3
            implode(', ', $knownVersions)
46 3
        ), 0, $cause);
47
    }
48
}
49