Skip to content

Commit

Permalink
Merge pull request #70 from DataValues/addPhpCs
Browse files Browse the repository at this point in the history
Add PHPCS
  • Loading branch information
mariushoch authored Oct 12, 2016
2 parents afd6523 + 847451e commit b582a61
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"data-values/interfaces": "~0.2.0|~0.1.5",
"data-values/common": "~0.3.0|~0.2.0"
},
"require-dev": {
"mediawiki/mediawiki-codesniffer": "~0.5"
},
"autoload": {
"files" : [
"Geo.php"
Expand All @@ -46,5 +49,10 @@
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"scripts": {
"phpcs": [
"vendor/bin/phpcs src/* tests/* --standard=phpcs.xml -sp"
]
}
}
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="DataValuesGeo">
<!-- See https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/MediaWiki/ruleset.xml -->
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="Generic.Arrays.DisallowLongArraySyntax" />
<exclude name="MediaWiki.WhiteSpace.SpaceAfterControlStructure.Incorrect" />
<exclude name="MediaWiki.WhiteSpace.SpaceyParenthesis" />
</rule>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="113" />
</properties>
</rule>

<arg name="extensions" value="php" />
</ruleset>
18 changes: 16 additions & 2 deletions src/Formatters/GeoCoordinateFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,28 @@ private function formatLongitude( $longitude, $precision ) {
);
}

/**
* @param string $coordinate
* @param string $positiveSymbol
* @param string $negativeSymbol
*
* @return string
*/
private function makeDirectionalIfNeeded( $coordinate, $positiveSymbol, $negativeSymbol ) {
if ( $this->options->getOption( self::OPT_DIRECTIONAL ) ) {
return $this->makeDirectional( $coordinate , $positiveSymbol, $negativeSymbol);
return $this->makeDirectional( $coordinate, $positiveSymbol, $negativeSymbol );
}

return $coordinate;
}

/**
* @param string $coordinate
* @param string $positiveSymbol
* @param string $negativeSymbol
*
* @return string
*/
private function makeDirectional( $coordinate, $positiveSymbol, $negativeSymbol ) {
$isNegative = substr( $coordinate, 0, 1 ) === '-';

Expand Down Expand Up @@ -313,7 +327,7 @@ private function getSignificantDigits( $unitsPerDegree, $degreePrecision ) {
* @return string
*/
private function formatNumber( $number, $digits = 0 ) {
//TODO: use NumberLocalizer
// TODO: use NumberLocalizer
$digits = $digits < 0 ? 0 : $digits;
return sprintf( '%.' . (int)$digits . 'F', $number );
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/DmCoordinateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ) {

if( $match ) {
$detectedMinute = true;
} else {
} else {
$match = preg_match( '/^(-)?' . $regExpLoose . '$/i', $segment );
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/Parsers/DmsCoordinateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function areValidCoordinates( array $normalizedCoordinateSegments ) {

if( $match ) {
$detectedSecond = true;
} else {
} else {
$match = preg_match( '/^(-)?' . $regExpLoose . '$/i', $segment );
}
}
Expand Down Expand Up @@ -153,8 +153,7 @@ protected function parseCoordinate( $coordinateSegment ) {

if ( $minutePosition === false ) {
$minutes = 0;
}
else {
} else {
$degSignLength = strlen( $this->getOption( self::OPT_DEGREE_SYMBOL ) );
$minuteLength = $minutePosition - $degreePosition - $degSignLength;
$minutes = substr( $coordinateSegment, $degreePosition + $degSignLength, $minuteLength );
Expand All @@ -164,8 +163,7 @@ protected function parseCoordinate( $coordinateSegment ) {

if ( $secondPosition === false ) {
$seconds = 0;
}
else {
} else {
$secondLength = $secondPosition - $minutePosition - 1;
$seconds = substr( $coordinateSegment, $minutePosition + 1, $secondLength );
}
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/Formatters/GlobeCoordinateFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public function testFormatWithInvalidPrecision_fallsBackToDefaultPrecision() {
/**
* @dataProvider validProvider
*/
public function testFormatterRoundTrip( GlobeCoordinateValue $coord, $expectedValue, FormatterOptions $options ) {
public function testFormatterRoundTrip(
GlobeCoordinateValue $coord,
$expectedValue,
FormatterOptions $options
) {
$formatter = new GlobeCoordinateFormatter( $options );

$parser = new GlobeCoordinateParser(
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/Values/GlobeCoordinateValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public function testGetLongitude( GlobeCoordinateValue $globeCoordinate, array $
public function testGetPrecision( GlobeCoordinateValue $globeCoordinate, array $arguments ) {
$actual = $globeCoordinate->getPrecision();

$this->assertTrue( is_float( $actual ) || is_int( $actual ) || is_null( $actual ), 'Precision is int or float or null' );
$this->assertTrue(
is_float( $actual ) || is_int( $actual ) || $actual === null,
'Precision is int or float or null'
);
$this->assertEquals( $arguments[1], $actual );
}

Expand Down Expand Up @@ -124,7 +127,11 @@ public function testArrayValueCompatibility() {
// These serializations where generated using revision f91f65f989cc3ffacbe924012d8f5b574e0b710c
// The strings are the result of calling getArrayValue on the objects and then feeding this to serialize.

$serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;s:9:"longitude";d:42;s:8:"altitude";N;s:9:"precision";d:0.01;s:5:"globe";s:4:"mars";}';
$serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;'
. 's:9:"longitude";d:42;'
. 's:8:"altitude";N;'
. 's:9:"precision";d:0.01;'
. 's:5:"globe";s:4:"mars";}';

$arrayForm = unserialize( $serialization );
$globeCoordinate = GlobeCoordinateValue::newFromArray( $arrayForm );
Expand All @@ -134,7 +141,11 @@ public function testArrayValueCompatibility() {
$this->assertEquals( 0.01, $globeCoordinate->getPrecision() );
$this->assertEquals( 'mars', $globeCoordinate->getGlobe() );

$serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;s:9:"longitude";d:-42;s:8:"altitude";d:9001;s:9:"precision";d:1;s:5:"globe";s:33:"http://www.wikidata.org/entity/Q2";}';
$serialization = 'a:5:{s:8:"latitude";d:-4.2000000000000002;'
. 's:9:"longitude";d:-42;'
. 's:8:"altitude";d:9001;'
. 's:9:"precision";d:1;'
. 's:5:"globe";s:33:"http://www.wikidata.org/entity/Q2";}';

$arrayForm = unserialize( $serialization );
$globeCoordinate = GlobeCoordinateValue::newFromArray( $arrayForm );
Expand Down

0 comments on commit b582a61

Please sign in to comment.