Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/221082
Change subject: Drop duplicate EraParser
......................................................................
Drop duplicate EraParser
Replaced with an identically named but slightly refactored class (e.g.
constant names changed) in DataValues Time.
Change-Id: Icf89f34b61c8cdb6c3de3f55f9361b18d31dacd6
---
D lib/includes/parsers/EraParser.php
M lib/includes/parsers/MWTimeIsoParser.php
M lib/includes/parsers/YearTimeParser.php
D lib/tests/phpunit/parsers/EraParserTest.php
M lib/tests/phpunit/parsers/YearTimeParserTest.php
5 files changed, 7 insertions(+), 204 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/82/221082/1
diff --git a/lib/includes/parsers/EraParser.php
b/lib/includes/parsers/EraParser.php
deleted file mode 100644
index 1b64c16..0000000
--- a/lib/includes/parsers/EraParser.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-
-namespace Wikibase\Lib\Parsers;
-
-use ValueParsers\ParseException;
-use ValueParsers\StringValueParser;
-
-/**
- * @since 0.5
- *
- * @licence GNU GPL v2+
- * @author Adam Shorland
- *
- * @todo move me to DataValues-time
- */
-class EraParser extends StringValueParser {
-
- const FORMAT_NAME = 'era';
-
- /**
- * @since 0.5
- */
- const BEFORE_CURRENT_ERA = '-';
-
- /**
- * @since 0.5
- */
- const CURRENT_ERA = '+';
-
- /**
- * @var string regex snippet matching BEFORE_CURRENT_ERA
- */
- private $BCEregex =
'(B\.?\s*C\.?(\s*E\.?)?|Before\s+(Christ|Common\s+Era))';
-
- /**
- * @var string regex snippet matching CURRENT_ERA
- */
- private $CEregex =
'(C\.?\s*E\.?|A\.?\s*D\.?|Common\s+Era|After\s+Christ|Anno\s+Domini)';
-
- /**
- * Parses the provided string and returns the era
- *
- * @param string $value
- *
- * @throws ParseException
- * @return array( 0 => parsed era constant, 1 => $value with no era
data )
- */
- protected function stringParse( $value ) {
- $value = trim( $value );
-
- $char1 = substr( $value, 0, 1 );
- if( $char1 === self::BEFORE_CURRENT_ERA || $char1 ===
self::CURRENT_ERA ) {
- $eraFromSign = $char1;
- }
- if( preg_match( '/' . $this->BCEregex . '$/i', $value ) ) {
- $eraFromString = self::BEFORE_CURRENT_ERA;
- } elseif( preg_match( '/' . $this->CEregex . '$/i', $value ) ) {
- $eraFromString = self::CURRENT_ERA;
- }
-
- if( isset( $eraFromSign ) && isset( $eraFromString ) ) {
- throw new ParseException(
- 'Parsed two eras from the same string',
- $value,
- self::FORMAT_NAME
- );
- }
-
- $cleanValue = $this->cleanValue( $value );
- if( isset( $eraFromString ) ) {
- return array( $eraFromString, $cleanValue );
- }
- if( isset( $eraFromSign ) ) {
- return array( $eraFromSign, $cleanValue );
- }
- // Default to CE
- return array( self::CURRENT_ERA, $cleanValue );
- }
-
- /**
- * Removes any parse-able Era information from the given string value
- *
- * @param string $value
- *
- * @return string
- */
- private function cleanValue( $value ) {
- $char1 = substr( $value, 0, 1 );
- if( $char1 === self::BEFORE_CURRENT_ERA || $char1 ===
self::CURRENT_ERA ) {
- $value = substr( $value, 1 );
- }
-
- return preg_replace( '/\s*(' . $this->BCEregex . '|' .
$this->CEregex . ')$/i', '',
- $value );
- }
-
-}
diff --git a/lib/includes/parsers/MWTimeIsoParser.php
b/lib/includes/parsers/MWTimeIsoParser.php
index d8b0457..ca0ac32 100644
--- a/lib/includes/parsers/MWTimeIsoParser.php
+++ b/lib/includes/parsers/MWTimeIsoParser.php
@@ -179,14 +179,8 @@
* @return TimeValue
*/
private function getTimeFromYear( $year, $isBce ) {
- if( $isBce ) {
- $sign = EraParser::BEFORE_CURRENT_ERA;
- } else {
- $sign = EraParser::CURRENT_ERA;
- }
-
+ $sign = $isBce ? '-' : '+';
$timeString = $sign . $year . '-00-00T00:00:00Z';
-
return $this->isoTimestampParser->parse( $timeString );
}
diff --git a/lib/includes/parsers/YearTimeParser.php
b/lib/includes/parsers/YearTimeParser.php
index 5c69a04..658ac89 100644
--- a/lib/includes/parsers/YearTimeParser.php
+++ b/lib/includes/parsers/YearTimeParser.php
@@ -5,6 +5,7 @@
use DataValues\TimeValue;
use Language;
use ValueParsers\CalendarModelParser;
+use ValueParsers\EraParser;
use ValueParsers\IsoTimestampParser;
use ValueParsers\ParseException;
use ValueParsers\ParserOptions;
@@ -65,7 +66,7 @@
list( $sign, $year ) = $this->eraParser->parse( $value );
// Negative dates usually don't have a month, assume non-digits
are thousands separators
- if( $sign === EraParser::BEFORE_CURRENT_ERA ) {
+ if ( $sign === '-' ) {
$separatorMap = $this->lang->separatorTransformTable();
if ( is_array( $separatorMap ) && array_key_exists(
',', $separatorMap ) ) {
diff --git a/lib/tests/phpunit/parsers/EraParserTest.php
b/lib/tests/phpunit/parsers/EraParserTest.php
deleted file mode 100644
index 3e5eaf8..0000000
--- a/lib/tests/phpunit/parsers/EraParserTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-
-namespace Wikibase\Lib\Parsers\Test;
-
-use ValueParsers\Test\StringValueParserTest;
-use Wikibase\Lib\Parsers\EraParser;
-
-/**
- * @covers Wikibase\Lib\Parsers\EraParser
- *
- * @group ValueParsers
- * @group WikibaseLib
- * @group Wikibase
- * @group TimeParsers
- *
- * @licence GNU GPL v2+
- * @author Adam Shorland
- */
-class EraParserTest extends StringValueParserTest {
-
- /**
- * @deprecated since 0.3, just use getInstance.
- */
- protected function getParserClass() {
- throw new \LogicException( 'Should not be called, use
getInstance' );
- }
-
- /**
- * @see ValueParserTestBase::getInstance
- *
- * @return EraParser
- */
- protected function getInstance() {
- return new EraParser();
- }
-
- /**
- * @see ValueParserTestBase::requireDataValue
- *
- * @return bool
- */
- protected function requireDataValue() {
- return false;
- }
-
- /**
- * @see ValueParserTestBase::validInputProvider
- */
- public function validInputProvider() {
- return array(
- array( '+100', array( '+', '100' ) ),
- array( '-100', array( '-', '100' ) ),
- array( ' -100', array( '-', '100' ) ),
- array( '100BC', array( '-', '100' ) ),
- array( '100 BC', array( '-', '100' ) ),
- array( '100 BCE', array( '-', '100' ) ),
- array( '100 AD', array( '+', '100' ) ),
- array( '100 A. D.', array( '+', '100' ) ),
- array( ' 100 B. C. ', array( '-', '100' ) ),
- array( ' 100 Common Era ', array( '+', '100' )
),
- array( '100 CE', array( '+', '100' ) ),
- array( '100CE', array( '+', '100' ) ),
- array( '+100', array( '+', '100' ) ),
- array( '100 Common Era', array( '+', '100' ) ),
- array( '100Common Era', array( '+', '100' ) ),
- array( '100 Before Common Era', array( '-', '100' ) ),
- array( '1 July 2013 Before Common Era', array( '-', '1
July 2013' ) ),
- array( 'June 2013 Before Common Era', array( '-', 'June
2013' ) ),
- array( '10-10-10 Before Common Era', array( '-',
'10-10-10' ) ),
- array( 'FooBefore Common Era', array( '-', 'Foo' ) ),
- array( 'Foo Before Common Era', array( '-', 'Foo' ) ),
- array( '-1 000 000', array( '-', '1 000 000' ) ),
- array( '1 000 000', array( '+', '1 000 000' ) ),
- array( '1 000 000 B.C.', array( '-', '1 000 000' ) ),
- );
- }
-
- /**
- * @see StringValueParserTest::invalidInputProvider
- */
- public function invalidInputProvider() {
- return array(
- array( '-100BC' ),
- array( '-100AD' ),
- array( '-100CE' ),
- array( '+100BC' ),
- array( '+100AD' ),
- array( '+100CE' ),
- array( '+100 Before Common Era' ),
- array( '+100 Common Era' ),
- );
- }
-
-}
diff --git a/lib/tests/phpunit/parsers/YearTimeParserTest.php
b/lib/tests/phpunit/parsers/YearTimeParserTest.php
index bb07478..902dbdc 100644
--- a/lib/tests/phpunit/parsers/YearTimeParserTest.php
+++ b/lib/tests/phpunit/parsers/YearTimeParserTest.php
@@ -4,7 +4,6 @@
use DataValues\TimeValue;
use ValueParsers\Test\StringValueParserTest;
-use Wikibase\Lib\Parsers\EraParser;
use Wikibase\Lib\Parsers\YearTimeParser;
/**
@@ -37,7 +36,7 @@
}
private function getMockEraParser() {
- $mock = $this->getMockBuilder( 'Wikibase\Lib\Parsers\EraParser'
)
+ $mock = $this->getMockBuilder( 'ValueParsers\EraParser' )
->disableOriginalConstructor()
->getMock();
$mock->expects( $this->any() )
@@ -45,10 +44,10 @@
->with( $this->isType( 'string' ) )
->will( $this->returnCallback(
function( $value ) {
- $sign = EraParser::CURRENT_ERA;
+ $sign = '+';
// Tiny parser that supports a single
negative sign only
- if ( $value[0] ===
EraParser::BEFORE_CURRENT_ERA ) {
- $sign =
EraParser::BEFORE_CURRENT_ERA;
+ if ( $value[0] === '-' ) {
+ $sign = '-';
$value = substr( $value, 1 );
}
return array( $sign, $value ) ;
--
To view, visit https://gerrit.wikimedia.org/r/221082
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf89f34b61c8cdb6c3de3f55f9361b18d31dacd6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits