PgString   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

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