Completed
Pull Request — 2.0 (#75)
by Julien
04:02
created

PgNumber::toPg()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
1
<?php
2
/*
3
 * This file is part of Pomm's Foundation package.
4
 *
5
 * (c) 2014 - 2015 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Foundation\Converter;
11
12
use PommProject\Foundation\Session\Session;
13
14
/**
15
 * PgNumber
16
 *
17
 * Converter for numbers.
18
 *
19
 * @package   Foundation
20
 * @copyright 2014 - 2015 Grégoire HUBERT
21
 * @author    Grégoire HUBERT
22
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
23
 * @see       ConverterInterface
24
 */
25
class PgNumber implements ConverterInterface
26
{
27
    /**
28
     * fromPg
29
     *
30
     * @see ConverterInterface
31
     */
32 View Code Duplication
    public function fromPg($data, $type, Session $session)
33
    {
34
        $data = trim($data);
35
36
        if ($data === '') {
37
            return null;
38
        }
39
40
        return $data + 0;
41
    }
42
43
    /**
44
     * toPg
45
     *
46
     * @see ConverterInterface
47
     */
48 View Code Duplication
    public function toPg($data, $type, Session $session)
49
    {
50
        return
51
            $data !== null
52
            ? sprintf("%s '%s'", $type, $data + 0)
53
            : sprintf("NULL::%s", $type)
54
            ;
55
    }
56
57
    /**
58
     * toPgStandardFormat
59
     *
60
     * @see ConverterInterface
61
     */
62
    public function toPgStandardFormat($data, $type, Session $session)
63
    {
64
        return
65
            $data !== null
66
            ? sprintf("%s", $data + 0)
67
            : null
68
            ;
69
    }
70
}
71