1 | <?php |
||
19 | class DmCoordinateParser extends DdCoordinateParser { |
||
20 | |||
21 | public const FORMAT_NAME = 'dm-coordinate'; |
||
22 | |||
23 | /** |
||
24 | * The symbols representing minutes. |
||
25 | * @since 0.1 |
||
26 | */ |
||
27 | public const OPT_MINUTE_SYMBOL = 'minute'; |
||
28 | |||
29 | /** |
||
30 | * @param ParserOptions|null $options |
||
31 | */ |
||
32 | 21 | public function __construct( ParserOptions $options = null ) { |
|
40 | |||
41 | /** |
||
42 | * @see LatLongParserBase::areValidCoordinates |
||
43 | * |
||
44 | * @param string[] $normalizedCoordinateSegments |
||
45 | * |
||
46 | * @return bool |
||
47 | */ |
||
48 | 18 | protected function areValidCoordinates( array $normalizedCoordinateSegments ): bool { |
|
49 | // At least one coordinate segment needs to have minutes specified. |
||
50 | $regExpStrict = '\d{1,3}' |
||
51 | 18 | . preg_quote( $this->getOption( self::OPT_DEGREE_SYMBOL ) ) |
|
52 | // TODO: Implement localized decimal separator. |
||
53 | 18 | . '(\d{1,2}(\.\d{1,20})?' |
|
54 | 18 | . preg_quote( $this->getOption( self::OPT_MINUTE_SYMBOL ) ) |
|
55 | 18 | . ')'; |
|
56 | 18 | $regExpLoose = $regExpStrict . '?'; |
|
57 | |||
58 | // Cache whether minutes have been detected within the coordinate: |
||
59 | 18 | $detectedMinute = false; |
|
60 | |||
61 | // Cache whether the coordinates are specified in directional format (a mixture of |
||
62 | // directional and non-directional is regarded invalid). |
||
63 | 18 | $directional = false; |
|
64 | |||
65 | 18 | foreach ( $normalizedCoordinateSegments as $i => $segment ) { |
|
66 | $direction = '(' |
||
67 | 18 | . $this->getOption( self::OPT_NORTH_SYMBOL ) . '|' |
|
68 | 18 | . $this->getOption( self::OPT_SOUTH_SYMBOL ) . ')'; |
|
69 | |||
70 | 18 | if ( $i === 1 ) { |
|
71 | $direction = '(' |
||
72 | 16 | . $this->getOption( self::OPT_EAST_SYMBOL ) . '|' |
|
73 | 16 | . $this->getOption( self::OPT_WEST_SYMBOL ) . ')'; |
|
74 | } |
||
75 | |||
76 | 18 | $match = preg_match( |
|
77 | 18 | '/^(' . $regExpStrict . $direction . '|' . $direction . $regExpStrict . ')$/i', |
|
78 | $segment |
||
79 | ); |
||
80 | |||
81 | 18 | if ( $match ) { |
|
82 | 6 | $detectedMinute = true; |
|
83 | } else { |
||
84 | 12 | $match = preg_match( |
|
85 | 12 | '/^(' . $regExpLoose . $direction . '|' . $direction . $regExpLoose . ')$/i', |
|
86 | $segment |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | 18 | if ( $match ) { |
|
91 | 6 | $directional = true; |
|
92 | 12 | } elseif ( !$directional ) { |
|
93 | 12 | $match = preg_match( '/^(-)?' . $regExpStrict . '$/i', $segment ); |
|
94 | |||
95 | 12 | if ( $match ) { |
|
96 | 10 | $detectedMinute = true; |
|
97 | } else { |
||
98 | 2 | $match = preg_match( '/^(-)?' . $regExpLoose . '$/i', $segment ); |
|
99 | } |
||
100 | } |
||
101 | |||
102 | 18 | if ( !$match ) { |
|
103 | 2 | return false; |
|
104 | } |
||
105 | } |
||
106 | |||
107 | 16 | return $detectedMinute; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @see DdCoordinateParser::getNormalizedNotation |
||
112 | * |
||
113 | * @param string $coordinates |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 18 | protected function getNormalizedNotation( string $coordinates ): string { |
|
128 | |||
129 | /** |
||
130 | * @see DdCoordinateParser::parseCoordinate |
||
131 | * |
||
132 | * @param string $coordinateSegment |
||
133 | * |
||
134 | * @return float |
||
135 | */ |
||
136 | 16 | protected function parseCoordinate( string $coordinateSegment ): float { |
|
166 | |||
167 | } |
||
168 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..