Completed
Push — master ( 34244a...852ce3 )
by grégoire
12s
created

PgFloat   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 46
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromPg() 10 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 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
 * PgFloat
16
 *
17
 * Converter for numbers.
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 View Code Duplication
class PgFloat implements ConverterInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 (float)$data;
41
    }
42
43
    /**
44
     * toPg
45
     *
46
     * @see ConverterInterface
47
     */
48
    public function toPg($data, $type, Session $session)
49
    {
50
        return
51
            $data !== null
52
            ? sprintf("%s '%s'", $type, $data)
53
            : sprintf("NULL::%s", $type)
54
            ;
55
    }
56
57
    /**
58
     * toPgStandardFormat
59
     *
60
     * @see ConverterInterface
61
     */
62
    public function toPgStandardFormat($data, $type, Session $session)
63
    {
64
        return
65
            $data !== null
66
            ? sprintf('%s', $data)
67
            : null
68
            ;
69
    }
70
}
71