Skip to content

Commit 8e06998

Browse files
committed
Merge pull request #458 from wmde/guidrename
ClaimGuid -> StatementGuid
2 parents ef6c2f2 + 1e3ad9b commit 8e06998

10 files changed

Lines changed: 126 additions & 102 deletions

Aliases.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,19 @@
1313
*/
1414
class Claim extends \Wikibase\DataModel\Statement\Statement {}
1515

16+
/**
17+
* @deprecated since 3.0.0, use the base class instead.
18+
*/
19+
class ClaimGuid extends \Wikibase\DataModel\Statement\StatementGuid {}
20+
21+
/**
22+
* @deprecated since 3.0.0, use the base class instead.
23+
*/
24+
class ClaimGuidParser extends \Wikibase\DataModel\Statement\StatementGuidParser {}
25+
26+
/**
27+
* @deprecated since 3.0.0, use the base class instead.
28+
*/
29+
class ClaimGuidParsingException extends \Wikibase\DataModel\Statement\StatementGuidParsingException {}
30+
1631
}

WikibaseDataModel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222

2323
// Aliases introduced in 3.0.0
2424
class_alias( 'Wikibase\DataModel\Statement\Statement', 'Wikibase\DataModel\Claim\Claim' );
25+
class_alias( 'Wikibase\DataModel\Statement\StatementGuid', 'Wikibase\DataModel\Claim\ClaimGuid' );
26+
class_alias( 'Wikibase\DataModel\Statement\StatementGuidParser', 'Wikibase\DataModel\Claim\ClaimGuidParser' );
27+
class_alias( 'Wikibase\DataModel\Statement\StatementGuidParsingException', 'Wikibase\DataModel\Claim\ClaimGuidParsingException' );

src/Claim/ClaimGuidParser.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Claim/ClaimGuidParsingException.php

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22

3-
namespace Wikibase\DataModel\Claim;
3+
namespace Wikibase\DataModel\Statement;
44

55
use Comparable;
66
use InvalidArgumentException;
77
use Wikibase\DataModel\Entity\EntityId;
88

99
/**
10-
* @since 0.5
10+
* @since 3.0
1111
*
1212
* @licence GNU GPL v2+
1313
* @author Adam Shorland
1414
*/
15-
class ClaimGuid implements Comparable {
15+
class StatementGuid implements Comparable {
1616

1717
/**
1818
* The separator for the prefix and suffix of the GUID.
@@ -55,7 +55,7 @@ public function getSerialization() {
5555
}
5656

5757
/**
58-
* @param ClaimGuid $target
58+
* @param StatementGuid $target
5959
*
6060
* @return bool
6161
*/
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Wikibase\DataModel\Statement;
4+
5+
use Wikibase\DataModel\Statement\StatementGuidParsingException;
6+
use Wikibase\DataModel\Entity\EntityIdParser;
7+
use Wikibase\DataModel\Entity\EntityIdParsingException;
8+
9+
/**
10+
* @since 3.0
11+
*
12+
* @licence GNU GPL v2+
13+
* @author Adam Shorland
14+
*/
15+
class StatementGuidParser {
16+
17+
/**
18+
* @var EntityIdParser
19+
*/
20+
private $entityIdParser;
21+
22+
/**
23+
* @param EntityIdParser $entityIdParser
24+
*/
25+
public function __construct( EntityIdParser $entityIdParser ) {
26+
$this->entityIdParser = $entityIdParser;
27+
}
28+
29+
/**
30+
* @param string $serialization
31+
*
32+
* @return StatementGuid
33+
* @throws StatementGuidParsingException
34+
*/
35+
public function parse( $serialization ) {
36+
if ( !is_string( $serialization ) ) {
37+
throw new StatementGuidParsingException( '$serialization must be a string; got ' . gettype( $serialization ) );
38+
}
39+
40+
$keyParts = explode( StatementGuid::SEPARATOR, $serialization );
41+
42+
if ( count( $keyParts ) !== 2 ) {
43+
throw new StatementGuidParsingException( '$serialization does not have the correct number of parts' );
44+
}
45+
46+
try {
47+
return new StatementGuid( $this->entityIdParser->parse( $keyParts[0] ), $keyParts[1] );
48+
}
49+
catch( EntityIdParsingException $exception ) {
50+
throw new StatementGuidParsingException( '$serialization contains invalid EntityId: ' . $exception->getMessage() );
51+
}
52+
}
53+
54+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Wikibase\DataModel\Statement;
4+
5+
/**
6+
* @since 3.0
7+
*
8+
* @licence GNU GPL v2+
9+
* @author Adam Shorland
10+
*/
11+
class StatementGuidParsingException extends \RuntimeException {
12+
13+
}

tests/component/AutoloadingAliasesTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ function( $className ) {
2525
},
2626
array(
2727
// Full qualified aliases go here.
28-
// Remove the dummy get_class call if new aliases are introduced.
29-
get_class()
28+
'Wikibase\DataModel\Claim\Claim',
29+
'Wikibase\DataModel\Claim\ClaimGuid',
30+
'Wikibase\DataModel\Claim\ClaimGuidParser',
31+
'Wikibase\DataModel\Claim\ClaimGuidParsingException',
3032
)
3133
);
3234
}

tests/unit/Claim/ClaimGuidParserTest.php renamed to tests/unit/Claim/StatementGuidParserTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,48 @@
22

33
namespace Wikibase\DataModel\Tests\Claim;
44

5-
use Wikibase\DataModel\Claim\ClaimGuid;
6-
use Wikibase\DataModel\Claim\ClaimGuidParser;
5+
use Wikibase\DataModel\Statement\StatementGuid;
6+
use Wikibase\DataModel\Statement\StatementGuidParser;
77
use Wikibase\DataModel\Entity\BasicEntityIdParser;
88
use Wikibase\DataModel\Entity\ItemId;
99

1010
/**
11-
* @covers Wikibase\DataModel\Claim\ClaimGuidParser
11+
* @covers Wikibase\DataModel\Statement\StatementGuidParser
1212
*
1313
* @group Wikibase
1414
* @group WikibaseDataModel
1515
*
1616
* @licence GNU GPL v2+
1717
* @author Adam Shorland
1818
*/
19-
class ClaimGuidParserTest extends \PHPUnit_Framework_TestCase {
19+
class StatementGuidParserTest extends \PHPUnit_Framework_TestCase {
2020

2121
/**
2222
* @dataProvider guidProvider
2323
*/
24-
public function testCanParseClaimGuid( ClaimGuid $expected ) {
24+
public function testCanParseStatementGuid( StatementGuid $expected ) {
2525
$actual = $this->newParser()->parse( $expected->getSerialization() );
2626

2727
$this->assertEquals( $actual, $expected );
2828
}
2929

3030
protected function newParser() {
31-
return new ClaimGuidParser( new BasicEntityIdParser() );
31+
return new StatementGuidParser( new BasicEntityIdParser() );
3232
}
3333

3434
public function guidProvider() {
3535
return array(
36-
array( new ClaimGuid( new ItemId( 'q42' ), 'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ) ),
37-
array( new ClaimGuid( new ItemId( 'Q1234567' ), 'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF' ) ),
38-
array( new ClaimGuid( new ItemId( 'Q1' ), 'foo' ) ),
36+
array( new StatementGuid( new ItemId( 'q42' ), 'D8404CDA-25E4-4334-AF13-A3290BCD9C0N' ) ),
37+
array( new StatementGuid( new ItemId( 'Q1234567' ), 'D4FDE516-F20C-4154-ADCE-7C5B609DFDFF' ) ),
38+
array( new StatementGuid( new ItemId( 'Q1' ), 'foo' ) ),
3939
);
4040
}
4141

4242
/**
4343
* @dataProvider invalidIdSerializationProvider
4444
*/
4545
public function testCannotParserInvalidId( $invalidIdSerialization ) {
46-
$this->setExpectedException( 'Wikibase\DataModel\Claim\ClaimGuidParsingException' );
46+
$this->setExpectedException( 'Wikibase\DataModel\Statement\StatementGuidParsingException' );
4747
$this->newParser()->parse( $invalidIdSerialization );
4848
}
4949

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace Wikibase\DataModel\Tests\Claim;
44

55
use Exception;
6-
use Wikibase\DataModel\Claim\ClaimGuid;
6+
use Wikibase\DataModel\Statement\StatementGuid;
77
use Wikibase\DataModel\Entity\EntityId;
88
use Wikibase\DataModel\Entity\ItemId;
99

1010
/**
11-
* @covers Wikibase\DataModel\Claim\ClaimGuid
11+
* @covers Wikibase\DataModel\Statement\StatementGuid
1212
*
1313
* @group Wikibase
1414
* @group WikibaseDataModel
@@ -17,7 +17,7 @@
1717
* @licence GNU GPL v2+
1818
* @author Adam Shorland
1919
*/
20-
class ClaimGuidTest extends \PHPUnit_Framework_TestCase {
20+
class StatementGuidTest extends \PHPUnit_Framework_TestCase {
2121

2222
/**
2323
* @dataProvider provideConstructionData
@@ -26,10 +26,10 @@ class ClaimGuidTest extends \PHPUnit_Framework_TestCase {
2626
* @param string $expected
2727
*/
2828
public function testConstructor( EntityId $entityId, $guid, $expected ) {
29-
$claimGuid = new ClaimGuid( $entityId, $guid );
29+
$statementGuid = new StatementGuid( $entityId, $guid );
3030

31-
$this->assertEquals( $expected, $claimGuid->getSerialization() );
32-
$this->assertEquals( $entityId, $claimGuid->getEntityId());
31+
$this->assertEquals( $expected, $statementGuid->getSerialization() );
32+
$this->assertEquals( $entityId, $statementGuid->getEntityId());
3333
}
3434

3535
public function provideConstructionData() {
@@ -59,7 +59,7 @@ public function provideConstructionData() {
5959
*/
6060
public function testBadConstruction( $entityId, $guid ) {
6161
$this->setExpectedException( 'InvalidArgumentException' );
62-
new ClaimGuid( $entityId, $guid );
62+
new StatementGuid( $entityId, $guid );
6363
}
6464

6565
public function provideBadConstruction() {
@@ -74,35 +74,37 @@ public function provideBadConstruction() {
7474
return $argLists;
7575
}
7676

77-
public function provideClaimGuids() {
77+
public function provideStatementGuids() {
7878
$constructionDatas = $this->provideConstructionData();
7979
$argLists = array();
8080

8181
foreach( $constructionDatas as $constructionData ){
82-
$argLists[] = array( new ClaimGuid( $constructionData[0], $constructionData[1] ) );
82+
$argLists[] = array( new StatementGuid( $constructionData[0], $constructionData[1] ) );
8383
}
8484

8585
return $argLists;
8686
}
8787

8888
/**
89-
* @dataProvider provideClaimGuids
90-
* @param ClaimGuid $claimGuid
89+
* @dataProvider provideStatementGuids
90+
*
91+
* @param StatementGuid $statementGuid
9192
*/
92-
public function testEquals( ClaimGuid $claimGuid ) {
93-
$claimGuidCopy = clone $claimGuid;
94-
$this->assertTrue( $claimGuid->equals( $claimGuidCopy ) );
95-
$this->assertTrue( $claimGuidCopy->equals( $claimGuid ) );
93+
public function testEquals( StatementGuid $statementGuid ) {
94+
$statementGuidCopy = clone $statementGuid;
95+
$this->assertTrue( $statementGuid->equals( $statementGuidCopy ) );
96+
$this->assertTrue( $statementGuidCopy->equals( $statementGuid ) );
9697
}
9798

9899
/**
99-
* @dataProvider provideClaimGuids
100-
* @param ClaimGuid $claimGuid
100+
* @dataProvider provideStatementGuids
101+
*
102+
* @param StatementGuid $statementGuid
101103
*/
102-
public function testNotEquals( ClaimGuid $claimGuid ) {
103-
$notEqualClaimGuid = new ClaimGuid( new ItemId( 'q9999' ), 'someguid' );
104-
$this->assertFalse( $claimGuid->equals( $notEqualClaimGuid ) );
105-
$this->assertFalse( $notEqualClaimGuid->equals( $claimGuid ) );
104+
public function testNotEquals( StatementGuid $statementGuid ) {
105+
$notEqualStatementGuid = new StatementGuid( new ItemId( 'q9999' ), 'someguid' );
106+
$this->assertFalse( $statementGuid->equals( $notEqualStatementGuid ) );
107+
$this->assertFalse( $notEqualStatementGuid->equals( $statementGuid ) );
106108
}
107109

108110
}

0 commit comments

Comments
 (0)