PgCircle::getTypeClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

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 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of PommProject's Foundation package.
4
 *
5
 * (c) 2014 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\Geometry;
11
12
use PommProject\Foundation\Converter\TypeConverter;
13
use PommProject\Foundation\Converter\ConverterInterface;
14
use PommProject\Foundation\Session\Session;
15
16
/**
17
 * PgCircle
18
 *
19
 * Converter for PostgreSQL Circle type.
20
 *
21
 * @package Foundation
22
 * @copyright 2014 Grégoire HUBERT
23
 * @author Grégoire HUBERT
24
 * @license X11 {@link http://opensource.org/licenses/mit-license.php}
25
 * @see ConverterInterface
26
 */
27
class PgCircle extends TypeConverter
28
{
29
    protected $point_converter;
30
31
    /**
32
     * getTypeClassName
33
     *
34
     * Circle class name
35
     *
36
     * @see TypeConverter
37
     */
38
    protected function getTypeClassName()
39
    {
40
        return '\PommProject\Foundation\Converter\Type\Circle';
41
    }
42
43
    /**
44
     * toPg
45
     *
46
     * @see ConverterInterface
47
     */
48
    public function toPg($data, $type, Session $session)
49
    {
50
        if ($data === null) {
51
            return sprintf("NULL::%s", $type);
52
        }
53
54
        $data = $this->checkData($data);
55
56
        return
57
            sprintf(
58
                "%s(%s,%s)",
59
                $type,
60
                $this
61
                    ->getPointConverter($session)
62
                    ->toPg($data->center, 'point', $session),
63
                $data->radius
64
            );
65
    }
66
67
    /**
68
     * getPointConverter
69
     *
70
     * Cache the point converter.
71
     *
72
     * @param  Session $session
73
     * @return ConverterInterface
74
     */
75
    protected function getPointConverter(Session $session)
76
    {
77
        if ($this->point_converter === null) {
78
            $this->point_converter = $session
79
                ->getClientUsingPooler('converter', 'point');
80
        }
81
82
        return $this->point_converter;
83
    }
84
}
85