Skip to content

Commit ca248ee

Browse files
committed
Add backwards compatibility with ByPropertyIdArray
1 parent b1d93dc commit ca248ee

3 files changed

Lines changed: 47 additions & 13 deletions

File tree

RELEASE-NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
* Added `ByPropertyIdGrouper`
1414
* Added `BestStatementsFinder`
1515

16+
#### Deprecations
17+
18+
* Deprecated `ByPropertyIdArray::buildIndex`, `ByPropertyIdArray::getByPropertyId` and `ByPropertyIdArray::getPropertyIds`
19+
1620
## Version 1.0 (2014-09-02)
1721

1822
#### Breaking changes

src/ByPropertyIdArrayNew.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use InvalidArgumentException;
66
use OutOfBoundsException;
7+
use Wikibase\DataModel\Entity\PropertyId;
78

89
/**
910
* Helper for managing objects grouped by property id.
@@ -40,14 +41,43 @@ public function __construct( array $propertyIdProviders ) {
4041
}
4142
}
4243

44+
/**
45+
* @since 0.2
46+
* @deprecated since 1.1
47+
*/
48+
public function buildIndex() {}
49+
50+
/**
51+
* @since 0.2
52+
* @deprecated since 1.1
53+
*
54+
* @param PropertyId $propertyId
55+
* @return PropertyIdProvider[]
56+
*
57+
* @throws OutOfBoundsException
58+
*/
59+
public function getByPropertyId( PropertyId $propertyId ) {
60+
return $this->byPropertyIdGrouper->getForPropertyId( $propertyId );
61+
}
62+
63+
/**
64+
* @since 0.2
65+
* @deprecated since 1.1
66+
*
67+
* @return PropertyId[]
68+
*/
69+
public function getPropertyIds() {
70+
return $this->byPropertyIdGrouper->getPropertyIds();
71+
}
72+
4373
/**
4474
* Returns a list of all PropertyIdProvider instances grouped by their PropertyId.
4575
*
46-
* @since 1.1
76+
* @since 0.2
4777
*
4878
* @return PropertyIdProvider[]
4979
*/
50-
public function getFlatArray() {
80+
public function toFlatArray() {
5181
return $this->flatArray;
5282
}
5383

@@ -74,15 +104,15 @@ public function getIndex( PropertyIdProvider $propertyIdProvider ) {
74104
/**
75105
* Adds the given PropertyIdProvider to the array at the given index.
76106
*
77-
* @since 1.1
107+
* @since 0.2
78108
*
79109
* @param PropertyIdProvider $propertyIdProvider
80110
* @param int $index
81111
*
82112
* @throws InvalidArgumentException
83113
* @throws OutOfBoundsException
84114
*/
85-
public function addAtIndex( PropertyIdProvider $propertyIdProvider, $index ) {
115+
public function addObjectAtIndex( PropertyIdProvider $propertyIdProvider, $index ) {
86116
$this->assertValidIndex( $index );
87117

88118
$groupIndices = $this->getFlatArrayGroupIndices();
@@ -168,7 +198,7 @@ public function moveToIndex( $oldIndex, $newIndex ) {
168198
/**
169199
* Moves the given PropertyIdProvider to the new index and returns it.
170200
*
171-
* @since 1.1
201+
* @since 0.2
172202
*
173203
* @param PropertyIdProvider $propertyIdProvider
174204
* @param int $index
@@ -177,7 +207,7 @@ public function moveToIndex( $oldIndex, $newIndex ) {
177207
* @throws InvalidArgumentException
178208
* @throws OutOfBoundsException
179209
*/
180-
public function moveObject( PropertyIdProvider $propertyIdProvider, $index ) {
210+
public function moveObjectToIndex( PropertyIdProvider $propertyIdProvider, $index ) {
181211
return $this->moveToIndex( $this->getIndex( $propertyIdProvider ), $index );
182212
}
183213

tests/unit/ByPropertyIdArrayNewTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class ByPropertyIdArrayNewTest extends \PHPUnit_Framework_TestCase {
1717
public function testGetFlatArray() {
1818
$byPropertyIdArray = $this->getByPropertyIdArray();
1919
$expectedTypes = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' );
20-
$this->assertEquals( $expectedTypes, $this->getTypes( $byPropertyIdArray->getFlatArray() ) );
20+
$this->assertEquals( $expectedTypes, $this->getTypes( $byPropertyIdArray->toFlatArray() ) );
2121
}
2222

2323
public function testGetIndex() {
2424
$byPropertyIdArray = $this->getByPropertyIdArray();
2525
$propertyIdProvider = $this->getSnakMock( 'P42', 'foo bar' );
26-
$byPropertyIdArray->addAtIndex( $propertyIdProvider, 2 );
26+
$byPropertyIdArray->addObjectAtIndex( $propertyIdProvider, 2 );
2727
$this->assertEquals( 2, $byPropertyIdArray->getIndex( $propertyIdProvider ) );
2828
}
2929

30-
public function provideAddAtIndex() {
30+
public function provideAddObjectAtIndex() {
3131
$cases = array();
3232

3333
$cases[] = array(
@@ -64,12 +64,12 @@ public function provideAddAtIndex() {
6464
}
6565

6666
/**
67-
* @dataProvider provideAddAtIndex
67+
* @dataProvider provideAddObjectAtIndex
6868
*/
69-
public function testAddAtIndex( PropertyIdProvider $propertyIdProvider, $index, $expectedTypes ) {
69+
public function testAddObjectAtIndex( PropertyIdProvider $propertyIdProvider, $index, $expectedTypes ) {
7070
$byPropertyIdArray = $this->getByPropertyIdArray();
71-
$byPropertyIdArray->addAtIndex( $propertyIdProvider, $index );
72-
$this->assertEquals( $expectedTypes, $this->getTypes( $byPropertyIdArray->getFlatArray() ) );
71+
$byPropertyIdArray->addObjectAtIndex( $propertyIdProvider, $index );
72+
$this->assertEquals( $expectedTypes, $this->getTypes( $byPropertyIdArray->toFlatArray() ) );
7373
}
7474

7575
private function getByPropertyIdArray() {

0 commit comments

Comments
 (0)