Skip to content

Commit

Permalink
Merge pull request #9 from longitude-one/map-feature
Browse files Browse the repository at this point in the history
* switch replaced by match
* some tests added
  • Loading branch information
Alexandre-T authored Mar 19, 2024
2 parents 1f1ae32 + 0000d60 commit d175b38
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 39 deletions.
38 changes: 12 additions & 26 deletions lib/LongitudeOne/Geo/String/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,17 @@ protected function getType(&$value): int
return self::T_FLOAT;
}

switch ($value) {
case ':':
return self::T_COLON;
case '\'':
case "\xe2\x80\xb2": // prime
return self::T_APOSTROPHE;
case '"':
case "\xe2\x80\xb3": // double prime
return self::T_QUOTE;
case ',':
return self::T_COMMA;
case '-':
return self::T_MINUS;
case '+':
return self::T_PLUS;
case '°':
return self::T_DEGREE;
case 'N':
case 'S':
return self::T_CARDINAL_LAT;
case 'E':
case 'W':
return self::T_CARDINAL_LON;
default:
return self::T_NONE;
}
return match ($value) {
':' => self::T_COLON,
'\'', "\xe2\x80\xb2" => self::T_APOSTROPHE,
'"', "\xe2\x80\xb3" => self::T_QUOTE,
',' => self::T_COMMA,
'-' => self::T_MINUS,
'+' => self::T_PLUS,
'°' => self::T_DEGREE,
'N', 'S' => self::T_CARDINAL_LAT,
'E', 'W' => self::T_CARDINAL_LON,
default => self::T_NONE,
};
}
}
14 changes: 3 additions & 11 deletions quality/php-mess-detector/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
<exclude name="CyclomaticComplexity"/>
<exclude name="ExcessiveClassComplexity"/>
</rule>

<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<!-- Set the report level to 17, because of historical code -->
<property name="reportLevel" value="17" />
<!-- The report level was 17, because of historical code. Now 11 because of optimizations. -->
<property name="reportLevel" value="11" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
Expand All @@ -40,12 +39,5 @@
<!-- Import the entire controversial rule set -->
<rule ref="rulesets/controversial.xml" />
<!-- Import the entire design rule set -->
<rule ref="rulesets/design.xml">
<exclude name="CouplingBetweenObjects"/>
</rule>
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<properties>
<property name="maximum" value="16" />
</properties>
</rule>
<rule ref="rulesets/design.xml"/>
</ruleset>
9 changes: 8 additions & 1 deletion quality/php-mess-detector/test-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
<!-- Import the entire unused code rule set, but UnusedPrivateMethod -->
<rule ref="rulesets/unusedcode.xml" />
<!-- Import the entire codeside rule -->
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/codesize.xml">
<exclude name="ExcessiveMethodLength"/>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
<properties>
<property name="minimum" value="116"/>
</properties>
</rule>
<!-- Import the entire naming rule set -->
<rule ref="rulesets/naming.xml" />
<!-- Import the entire controversial rule set -->
Expand Down
18 changes: 18 additions & 0 deletions tests/LongitudeOne/Geo/String/Tests/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ public static function dataProvider(): \Generator
new Token('"', Lexer::T_QUOTE, 11),
new Token('N', Lexer::T_CARDINAL_LAT, 13),
]];
yield ["40° 26\xe2\x80\xb2 46\xe2\x80\xb3 N", [
new Token(40, Lexer::T_INTEGER, 0),
new Token('°', Lexer::T_DEGREE, 2),
new Token(26, Lexer::T_INTEGER, 5),
new Token("\xe2\x80\xb2", Lexer::T_APOSTROPHE, 7),
new Token(46, Lexer::T_INTEGER, 11),
new Token("\xe2\x80\xb3", Lexer::T_QUOTE, 13),
new Token('N', Lexer::T_CARDINAL_LAT, 17),
]];
yield ['40° 26′ 46″ N', [
new Token(40, Lexer::T_INTEGER, 0),
new Token('°', Lexer::T_DEGREE, 2),
new Token(26, Lexer::T_INTEGER, 5),
new Token('', Lexer::T_APOSTROPHE, 7),
new Token(46, Lexer::T_INTEGER, 11),
new Token('', Lexer::T_QUOTE, 13),
new Token('N', Lexer::T_CARDINAL_LAT, 17),
]];
yield ['40° 26\' 46" N 79° 58\' 56" W', [
new Token(40, Lexer::T_INTEGER, 0),
new Token('°', Lexer::T_DEGREE, 2),
Expand Down
10 changes: 9 additions & 1 deletion tests/LongitudeOne/Geo/String/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ public static function dataSourceGood(): \Generator
yield ['45.24°', 45.24];
yield ['+45.24°', 45.24];
yield ['45.24° S', -45.24];
yield ['45.24°N', 45.24];
yield ['45.83°N', 45.83];
yield ['45.24°S', -45.24];
yield ['40° 26\' 46" N', 40.44611111111111];
yield ['40° 26\' 46"N', 40.44611111111111];
yield ['40° 26\' 46" S', -40.44611111111111];
yield ['40° 26\' 46"S', -40.44611111111111];
yield ['40° 26′ 46″ N', 40.44611111111111];
yield ['40° 26′ 46″N', 40.44611111111111];
yield ['40° 26′ 46″ S', -40.44611111111111];
yield ['40° 26′ 46″S', -40.44611111111111];
yield ["40° 26\xe2\x80\xb2 46\xe2\x80\xb3 N", 40.44611111111111];
yield ["40° 26\xe2\x80\xb2 46\xe2\x80\xb3N", 40.44611111111111];
yield ["40° 26\xe2\x80\xb2 46\xe2\x80\xb3 S", -40.44611111111111];
yield ["40° 26\xe2\x80\xb2 46\xe2\x80\xb3S", -40.44611111111111];
yield ['40:26', 40.4333333333333333];
yield ['40:26:46', 40.44611111111111];
yield ['79:56:55W', -79.94861111111111];
Expand Down

0 comments on commit d175b38

Please sign in to comment.