Completed
Push — master ( 99e9b8...3071de )
by Bernhard
02:07
created

VersionFieldVersioner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseVersion() 0 8 2
A updateVersion() 0 4 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\Versioner;
13
14
use stdClass;
15
16
/**
17
 * Expects the version to be set in the "version" field of a JSON object.
18
 *
19
 * @since  1.3
20
 *
21
 * @author Bernhard Schussek <[email protected]>
22
 */
23
class VersionFieldVersioner implements JsonVersioner
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function parseVersion(stdClass $jsonData)
29
    {
30 2
        if (!isset($jsonData->version)) {
31 1
            throw new CannotParseVersionException('Cannot find "version" property in JSON object.');
32
        }
33
34 1
        return $jsonData->version;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 2
    public function updateVersion(stdClass $jsonData, $version)
41
    {
42 2
        $jsonData->version = $version;
43 2
    }
44
}
45