Point   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 45
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
     * @param  string $description
33
     */
34
    public function __construct($description)
35
    {
36
        $description = trim($description, ' ()');
37
38
        if (!preg_match('/([0-9e\-+\.]+), *([0-9e\-+\.]+)/', $description, $matches)) {
39
            throw new \InvalidArgumentException(
40
                sprintf(
41
                    "Could not parse point representation '%s'.",
42
                    $description
43
                )
44
            );
45
        }
46
47
        $this->x = (float) $matches[1];
48
        $this->y = (float) $matches[2];
49
    }
50
51
    /**
52
     * __toString
53
     *
54
     * Return a string representation of Point.
55
     *
56
     * @return string
57
     */
58
    public function __toString()
59
    {
60
        return sprintf(
61
            "(%s,%s)",
62
            $this->x,
63
            $this->y
64
        );
65
    }
66
}
67