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

PgString::toPgStandardFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 4
c 1
b 1
f 0
rs 10
cc 1
eloc 2
nc 1
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
 * PgString
16
 *
17
 * Converter for strings types.
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 PgString implements ConverterInterface
26
{
27
    /**
28
     * toPg
29
     *
30
     * @see ConverterInterface
31
     */
32
    public function toPg($data, $type, Session $session)
33
    {
34
        return $data !== null
35
            ? sprintf("%s %s",  $type, $session->getConnection()->escapeLiteral($data))
36
            : sprintf("NULL::%s", $type)
37
            ;
38
    }
39
40
    /**
41
     * toPgStandardFormat
42
     *
43
     * @see ConverterInterface
44
     */
45
    public function toPgStandardFormat($data, $type, Session $session)
46
    {
47
        return $data;
48
    }
49
50
    /**
51
     * @see ConverterInterface
52
     */
53
    public function fromPg($data, $type, Session $session)
54
    {
55
        return $data !== null ? (string) $data : null;
56
    }
57
}
58