Completed
Pull Request — master (#83)
by
unknown
02:42
created

Box   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

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