Completed
Push — 2.0 ( 143803...4e64fa )
by grégoire
08:42 queued 04:22
created

PgString   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 33
c 4
b 1
f 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toPgStandardFormat() 0 4 1
A fromPg() 0 4 2
A toPg() 0 7 2
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