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

PgLtree   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 34.04 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 6
lcom 0
cbo 1
dl 16
loc 47
c 3
b 0
f 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromPg() 0 10 2
A toPg() 8 8 2
A toPgStandardFormat() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
 * This file is part of the Pomm 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
 * PgLtree
16
 *
17
 * Ltree converter.
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 PgLtree extends ArrayTypeConverter
26
{
27
    /**
28
     * fromPg
29
     *
30
     * @see ConverterInterface
31
     */
32
    public function fromPg($data, $type, Session $session)
33
    {
34
        $data = trim($data);
35
36
        if ($data === '') {
37
            return null;
38
        }
39
40
        return preg_split('/\./', $data);
41
    }
42
43
    /**
44
     * toPg
45
     *
46
     * @see ConverterInterface
47
     */
48 View Code Duplication
    public function toPg($data, $type, Session $session)
49
    {
50
        return
51
            $data !== null
52
            ? sprintf("ltree '%s'", join('.', $this->checkArray($data)))
53
            : sprintf("NULL::%s", $type)
54
            ;
55
    }
56
57
58
    /**
59
     * toPgStandardFormat
60
     *
61
     * @see ConverterInterface
62
     */
63 View Code Duplication
    public function toPgStandardFormat($data, $type, Session $session)
64
    {
65
        return
66
            $data !== null
67
            ? sprintf("%s", join('.', $this->checkArray($data)))
68
            : null
69
            ;
70
    }
71
}
72