Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
3.70% covered (danger)
3.70%
1 / 27
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Rectangle
3.70% covered (danger)
3.70%
1 / 27
50.00% covered (danger)
50.00%
1 / 2
65.15
0.00% covered (danger)
0.00%
0 / 1
 getElementName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parseCoordinates
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2namespace MultiMaps;
3
4/**
5 * Rectangle class for collection of map elements
6 *
7 * @file Rectangle.php
8 * @ingroup MultiMaps
9 * @author Pavel Astakhov <pastakhov@yandex.ru>
10 * @license GPL-2.0-or-later
11 */
12class Rectangle extends Polygon {
13
14    /**
15     * Returns element name
16     * return string Element name
17     */
18    public function getElementName() {
19        return 'Rectangle'; // TODO i18n?
20    }
21
22    /**
23     * Parse coordinates for rectangle
24     *
25     * @assert ('10,10:20,20') === true
26     * @assert ('10,10:20,20:30,30') === false
27     * @assert ('10,10:20,20:30') === false
28     * @assert ('10,10:20') === false
29     * @assert ('10,10:') === false
30     * @assert ('10,10') === false
31     * @assert ('10') === false
32     *
33     * @global type $egMultiMaps_CoordinatesSeparator
34     * @param string $coordinates
35     * @param string|null $service Name of map service
36     * @return bool
37     */
38    protected function parseCoordinates( $coordinates, $service = null ) {
39        global $egMultiMaps_CoordinatesSeparator;
40
41        $array = explode( $egMultiMaps_CoordinatesSeparator, $coordinates );
42
43        if ( count( $array ) == 2 ) {
44            $point1 = new Point();
45            $point2 = new Point();
46            if ( $point1->parse( $array[0], $service ) ) {
47                if ( $point2->parse( $array[1], $service ) ) {
48                    $this->coordinates[] = $point1;
49                    $this->coordinates[] = $point2;
50                } else {
51                    $this->errormessages[] = \wfMessage( 'multimaps-unable-parse-coordinates', $array[1] )->escaped();
52                    return false;
53                }
54            } else {
55                $this->errormessages[] = \wfMessage( 'multimaps-unable-parse-coordinates', $array[0] )->escaped();
56                return false;
57            }
58        } elseif ( count( $array ) == 1 ) {
59            $point = new Point();
60            if ( $point->parse( $array[0], $service ) ) {
61                $bounds = $point->bounds;
62                if ( $bounds ) {
63                    $this->coordinates[] = $bounds->ne;
64                    $this->coordinates[] = $bounds->sw;
65                } else {
66                    $this->errormessages[] = \wfMessage( 'multimaps-square-wrong-number-points', count( $array ) )->escaped();
67                    return false;
68                }
69            } else {
70                $this->errormessages[] = \wfMessage( 'multimaps-unable-parse-coordinates', $array[0] )->escaped();
71                return false;
72            }
73        } else {
74            $this->errormessages[] = \wfMessage( 'multimaps-square-wrong-number-points', count( $array ) )->escaped();
75            return false;
76        }
77        return true;
78    }
79
80}