Skip to content

Commit

Permalink
Merge 3e989c3 into e94f7b8
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Nov 29, 2019
2 parents e94f7b8 + 3e989c3 commit 3bc0e2c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ composer.json export-ignore
phpcs.xml export-ignore
phpmd.xml export-ignore
phpunit.xml.dist export-ignore
psalm.xml export-ignore
tests export-ignore
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"wikibase/wikibase-codesniffer": "^0.5.0",
"ockcyp/covers-validator": "~1.0",
"phpstan/phpstan": "~0.11.0",
"phpmd/phpmd": "^2.6.1"
"phpmd/phpmd": "^2.6.1",
"vimeo/psalm": "^3.7"
},
"autoload": {
"psr-4": {
Expand All @@ -73,7 +74,8 @@
"cs": [
"vendor/bin/phpcs -p -s",
"vendor/bin/phpstan analyse --level=1 --no-progress src/ tests/",
"vendor/bin/phpmd src/ text phpmd.xml"
"vendor/bin/phpmd src/ text phpmd.xml",
"vendor/bin/psalm --show-info=false"
],
"ci": [
"@test",
Expand Down
28 changes: 28 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<MissingPropertyType errorLevel="suppress" />
<DocblockTypeContradiction errorLevel="suppress" />

<!-- level 6 issues - really bad things -->

<MoreSpecificImplementedParamType errorLevel="suppress" />
<InvalidReturnType errorLevel="suppress" />

</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/Formatters/LatLongFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function getPrecisionFromOptions(): float {
* @throws InvalidArgumentException
*/
public function formatLatLongValue( LatLongValue $value, ?float $precision ): string {
if ( $precision <= 0 || !is_finite( $precision ) ) {
if ( $precision === null || $precision <= 0 || !is_finite( $precision ) ) {
$precision = self::DEFAULT_PRECISION;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Parsers/DdCoordinateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class DdCoordinateParser extends LatLongParserBase {
*/
public const OPT_DEGREE_SYMBOL = 'degree';

/**
* Delimiters used to split a coordinate string when unable to split by using the separator.
* @var string[]
*/
protected $defaultDelimiters;

/**
* @param ParserOptions|null $options
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/DmCoordinateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function parseCoordinate( string $coordinateSegment ): float {

$minutes = substr( $minutes, 0, -1 );

$coordinateSegment = $degrees + $minutes / 60;
$coordinateSegment = (float)$degrees + (float)$minutes / 60;

if ( $isNegative ) {
$coordinateSegment *= -1;
Expand Down
9 changes: 1 addition & 8 deletions src/Parsers/FloatCoordinateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b
// TODO: Implement localized decimal separator.
$baseRegExp = '\d{1,3}(\.\d{1,20})?';

// Cache whether the coordinates are specified in directional format (a mixture of
// directional and non-directional is regarded invalid).
$directional = false;

$match = false;

foreach ( $normalizedCoordinateSegments as $i => $segment ) {
Expand All @@ -63,10 +59,7 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ): b
$segment
);

if ( $directional && !$match ) {
// Latitude is directional, longitude not.
break;
} elseif ( $match ) {
if ( $match ) {
continue;
}

Expand Down
6 changes: 0 additions & 6 deletions src/Parsers/LatLongParserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ abstract class LatLongParserBase implements ValueParser {
*/
public const OPT_SEPARATOR_SYMBOL = 'separator';

/**
* Delimiters used to split a coordinate string when unable to split by using the separator.
* @var string[]
*/
protected $defaultDelimiters;

/**
* @var ParserOptions
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Values/GlobeCoordinateValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function getHash(): string {
return md5(
$this->latLong->getLatitude() . '|'
. $this->latLong->getLongitude() . '|'
. $this->precision . '|'
. (string)$this->precision . '|'
. $this->globe
);
}
Expand Down Expand Up @@ -200,6 +200,8 @@ public function withPrecision( ?float $precision ): self {
/**
* Constructs a new instance from the provided array. Round-trips with @see getArrayValue.
*
* @param array $data
* @return self
* @throws InvalidArgumentException
*/
public static function newFromArray( $data ): self {
Expand Down
2 changes: 2 additions & 0 deletions src/Values/LatLongValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public function getArrayValue(): array {
/**
* Constructs a new instance from the provided array. Round-trips with @see getArrayValue.
*
* @param array $data
* @return self
* @throws InvalidArgumentException
*/
public static function newFromArray( $data ): self {
Expand Down

0 comments on commit 3bc0e2c

Please sign in to comment.