Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
Circle | |
0.00% |
0 / 35 |
|
0.00% |
0 / 5 |
182 | |
0.00% |
0 / 1 |
getElementName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
parseCoordinates | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
56 | |||
reset | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getData | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getProperty | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | namespace MultiMaps; |
3 | |
4 | /** |
5 | * Circle class for collection of map elements |
6 | * |
7 | * @file Circle.php |
8 | * @ingroup Circle |
9 | * @author Pavel Astakhov <pastakhov@yandex.ru> |
10 | * @license GPL-2.0-or-later |
11 | * @property-read array $radiuses Radiuses of circles |
12 | */ |
13 | class Circle extends Polygon { |
14 | |
15 | /** |
16 | * Array radiuses of circles |
17 | * @var array |
18 | */ |
19 | protected $radiuses = []; |
20 | |
21 | /** |
22 | * Returns element name |
23 | * return string Element name |
24 | */ |
25 | public function getElementName() { |
26 | return 'Circle'; // TODO i18n? |
27 | } |
28 | |
29 | /** |
30 | * Filling property 'coordinates' |
31 | * @global string $egMultiMaps_CoordinatesSeparator |
32 | * @param string $coordinates |
33 | * @param string|null $service Name of map service |
34 | * @return bool |
35 | */ |
36 | protected function parseCoordinates( $coordinates, $service = null ) { |
37 | global $egMultiMaps_CoordinatesSeparator; |
38 | |
39 | $array = explode( $egMultiMaps_CoordinatesSeparator, $coordinates ); |
40 | |
41 | if ( count( $array ) == 2 ) { |
42 | $point = new Point(); |
43 | if ( $point->parse( $array[0], $service ) ) { |
44 | if ( is_numeric( $array[1] ) ) { |
45 | $this->coordinates[] = $point; |
46 | $this->radiuses[] = (float)$array[1]; |
47 | } else { |
48 | $this->errormessages[] = \wfMessage( 'multimaps-unable-parse-radius', $array[1] )->escaped(); |
49 | return false; |
50 | } |
51 | } else { |
52 | $this->errormessages[] = \wfMessage( 'multimaps-unable-parse-coordinates', $array[0] )->escaped(); |
53 | return false; |
54 | } |
55 | } elseif ( count( $array ) == 1 ) { |
56 | $point = new Point(); |
57 | if ( $point->parse( $array[0], $service ) ) { |
58 | $bounds = $point->bounds; |
59 | if ( $bounds ) { |
60 | $this->coordinates[] = $bounds->center; |
61 | $this->radiuses[] = $bounds->diagonal / 2; |
62 | } else { |
63 | $this->errormessages[] = \wfMessage( 'multimaps-circle-radius-not-defined' )->escaped(); |
64 | return false; |
65 | } |
66 | } else { |
67 | $this->errormessages[] = \wfMessage( 'multimaps-unable-parse-coordinates', $array[0] )->escaped(); |
68 | return false; |
69 | } |
70 | } else { |
71 | $this->errormessages[] = \wfMessage( 'multimaps-circle-wrong-number-parameters', count( $array ) )->escaped(); |
72 | return false; |
73 | } |
74 | return true; |
75 | } |
76 | |
77 | /** |
78 | * Initializes the object again, and makes it invalid |
79 | */ |
80 | public function reset() { |
81 | parent::reset(); |
82 | $this->radiuses = []; |
83 | } |
84 | |
85 | /** |
86 | * Returns an array of data |
87 | * @return array |
88 | */ |
89 | public function getData() { |
90 | return array_merge( |
91 | [ 'radius' => $this->radiuses ], |
92 | parent::getData() |
93 | ); |
94 | } |
95 | |
96 | public function getProperty( $name ) { |
97 | switch ( $name ) { |
98 | case 'radiuses': |
99 | return $this->radiuses; |
100 | default: |
101 | return parent::getProperty( $name ); |
102 | } |
103 | } |
104 | |
105 | } |