PgString::fromPg()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
/*
3
 * This file is part of Pomm's Foundation package.
4
 *
5
 * (c) 2014 - 2017 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 - 2017 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
     * toPgStandardFormat
41
     *
42
     * @see ConverterInterface
43
     */
44
    public function toPgStandardFormat($data, $type, Session $session)
45
    {
46
        return $data;
47
    }
48
49
    /**
50
     * @see ConverterInterface
51
     */
52
    public function fromPg($data, $type, Session $session)
53
    {
54
        return $data !== null ? (string) $data : null;
55
    }
56
}
57