Completed
Pull Request — 2.0 (#75)
by Julien
02:03
created

Point   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A __toString() 0 8 1
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\Type;
11
12
/**
13
 * Point
14
 *
15
 * PHP type for PostgreSQL's point type.
16
 *
17
 * @package Foundation
18
 * @copyright 2014 Grégoire HUBERT
19
 * @author Grégoire HUBERT
20
 * @license X11 {@link http://opensource.org/licenses/mit-license.php}
21
 */
22
class Point
23
{
24
    public $x;
25
    public $y;
26
27
    /**
28
     * __construct
29
     *
30
     * Create a point from a string description.
31
     *
32
     * @access public
33
     * @param  string $description
34
     */
35
    public function __construct($description)
36
    {
37
        $description = trim($description, ' ()');
38
39
        if (!preg_match('/([0-9e\-+\.]+), *([0-9e\-+\.]+)/', $description, $matches)) {
40
            throw new \InvalidArgumentException(
41
                sprintf(
42
                    "Could not parse point representation '%s'.",
43
                    $description
44
                )
45
            );
46
        }
47
48
        $this->x = (float) $matches[1];
49
        $this->y = (float) $matches[2];
50
    }
51
52
    /**
53
     * __toString
54
     *
55
     * Return a string representation of Point.
56
     *
57
     * @access public
58
     * @return string
59
     */
60
    public function __toString()
61
    {
62
        return sprintf(
63
            "(%s,%s)",
64
            $this->x,
65
            $this->y
66
        );
67
    }
68
}
69