Completed
Pull Request — master (#2184)
by Maciej
25:09
created

IntType::convertToDatabaseValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Types;
6
7
/**
8
 * The Int type.
9
 */
10
class IntType extends Type implements Incrementable, Versionable
11
{
12 289
    public function convertToDatabaseValue($value)
13
    {
14 289
        return $value !== null ? (int) $value : null;
15
    }
16
17 16
    public function convertToPHPValue($value)
18
    {
19 16
        return $value !== null ? (int) $value : null;
20
    }
21
22
    public function closureToMongo() : string
23
    {
24
        return '$return = (int) $value;';
25
    }
26
27 23
    public function closureToPHP() : string
28
    {
29 23
        return '$return = (int) $value;';
30
    }
31
32
    public function diff($old, $new)
33
    {
34
        return $new - $old;
35
    }
36
37
    public function getNextVersion($current)
38
    {
39
        return max(1, (int) $current + 1);
40
    }
41
}
42