Skip to content

Commit 3e030af

Browse files
committed
Merge pull request #406 from wmde/masterAsOf2015-03-13
Merge master into 3.0.x-dev
2 parents 30d71da + a57d75a commit 3e030af

22 files changed

Lines changed: 264 additions & 139 deletions

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ php:
88
- hhvm
99
- hhvm-nightly
1010

11+
matrix:
12+
allow_failures:
13+
- php: hhvm-nightly
14+
1115
before_script: composer install --prefer-source
1216

1317
sudo: false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[![Latest Unstable Version](https://poser.pugx.org/wikibase/data-model/v/unstable.svg)](//packagist.org/packages/wikibase/data-model)
1212

1313
**Wikibase DataModel** is the canonical PHP implementation of the
14-
[Data Model](https://meta.wikimedia.org/wiki/Wikidata/Data_model)
14+
[Data Model](https://www.mediawiki.org/wiki/Wikibase/DataModel)
1515
at the heart of the [Wikibase software](http://wikiba.se/).
1616

1717
It is primarily used by the Wikibase MediaWiki extensions, though

RELEASE-NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
* Removed `ClaimList`
1111
* Removed `ClaimListAccess`
1212

13-
## Version 2.6.0 (dev)
13+
## Version 2.6.0 (2015-03-08)
1414

15+
* Added `Reference::isEmpty`
1516
* Empty strings are now detected as invalid in the `SiteLink` constructor
17+
* Empty References are now ignored when added to `ReferenceList`
18+
* The `ReferenceList` constructor now throws an `InvalidArgumentException` when getting a non-iterable input
1619
* The `SnakList` constructor now throws an `InvalidArgumentException` when getting a non-iterable input
1720
* The `AliasGroup::equals` and `Term::equals` methods no longer incorrectly return true for fallback objects
1821

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@
4444
}
4545
},
4646
"scripts": {
47-
"ci": [
48-
"composer test",
49-
"composer cs"
50-
],
5147
"test": [
5248
"composer validate --no-interaction",
5349
"phpunit"
5450
],
5551
"cs": [
56-
"phpcs src/* tests/* --standard=phpcs.xml --extensions=php -sp"
52+
"vendor/bin/phpcs src/* tests/* --standard=phpcs.xml --extensions=php -sp"
53+
],
54+
"ci": [
55+
"composer test",
56+
"composer cs"
5757
]
5858
}
5959
}

src/Entity/DispatchingEntityIdParser.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ public function __construct( array $idBuilders ) {
3939
public function parse( $idSerialization ) {
4040
$this->assertIdIsString( $idSerialization );
4141

42+
if ( empty( $this->idBuilders ) ) {
43+
throw new EntityIdParsingException( 'No id builders are configured' );
44+
}
45+
4246
foreach ( $this->idBuilders as $idPattern => $idBuilder ) {
4347
if ( preg_match( $idPattern, $idSerialization ) ) {
4448
return $this->buildId( $idBuilder, $idSerialization );
4549
}
4650
}
4751

48-
throw $this->newInvalidIdException( $idSerialization );
52+
throw new EntityIdParsingException(
53+
"The serialization \"$idSerialization\" is not recognized by the configured id builders"
54+
);
4955
}
5056

5157
/**
@@ -55,7 +61,7 @@ public function parse( $idSerialization ) {
5561
*/
5662
private function assertIdIsString( $idSerialization ) {
5763
if ( !is_string( $idSerialization ) ) {
58-
throw new EntityIdParsingException( '$idSerialization must be a string; got ' . gettype( $idSerialization ) );
64+
throw new EntityIdParsingException( '$idSerialization must be a string' );
5965
}
6066
}
6167

@@ -69,21 +75,10 @@ private function assertIdIsString( $idSerialization ) {
6975
private function buildId( $idBuilder, $idSerialization ) {
7076
try {
7177
return call_user_func( $idBuilder, $idSerialization );
78+
} catch ( InvalidArgumentException $ex ) {
79+
// Should not happen, but if it does, re-throw the original message
80+
throw new EntityIdParsingException( $ex->getMessage() );
7281
}
73-
catch ( InvalidArgumentException $ex ) {
74-
throw $this->newInvalidIdException( $idSerialization );
75-
}
76-
}
77-
78-
/**
79-
* @param string $idSerialization
80-
*
81-
* @return EntityIdParsingException
82-
*/
83-
private function newInvalidIdException( $idSerialization ) {
84-
return new EntityIdParsingException(
85-
'The provided id serialization "' . $idSerialization . '" is not valid'
86-
);
8782
}
8883

8984
}

src/Entity/EntityIdValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public function serialize() {
4242
* though cannot be removed until we ditch the "numeric id" part
4343
* from the serialization.
4444
*
45-
* @return double Numeric id as a whole number. Can not be int because of 32-bit PHP.
45+
* @return float Numeric id as a whole number. Can not be int because of 32-bit PHP.
4646
*/
4747
protected function getNumericId() {
48-
return doubleval( substr( $this->entityId->getSerialization(), 1 ) );
48+
return floatval( substr( $this->entityId->getSerialization(), 1 ) );
4949
}
5050

5151
/**

src/Entity/Item.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function clear() {
238238
}
239239

240240
/**
241-
* @deprecated since 1.0, use getStatements instead
241+
* @deprecated since 1.0, use getStatements()->addStatement() instead.
242242
*
243243
* @param Claim $statement This needs to be a Statement as of 1.0
244244
*
@@ -273,7 +273,7 @@ public function setStatements( StatementList $statements ) {
273273
}
274274

275275
/**
276-
* @deprecated since 1.0, use getStatements instead
276+
* @deprecated since 1.0, use getStatements()->toArray() instead.
277277
*
278278
* @return Statement[]
279279
*/
@@ -291,7 +291,7 @@ public function setClaims( Claims $claims ) {
291291
}
292292

293293
/**
294-
* @deprecated since 1.0, use getStatements instead
294+
* @deprecated since 1.0, use getStatements()->isEmpty() instead.
295295
*
296296
* @return bool
297297
*/

src/Entity/Property.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function setStatements( StatementList $statements ) {
206206
}
207207

208208
/**
209-
* @deprecated since 1.0, use getStatements instead
209+
* @deprecated since 1.0, use getStatements()->toArray() instead.
210210
*
211211
* @return Statement[]
212212
*/
@@ -224,7 +224,7 @@ public function setClaims( Claims $claims ) {
224224
}
225225

226226
/**
227-
* @deprecated since 1.0, use getStatements instead
227+
* @deprecated since 1.0, use getStatements()->isEmpty() instead.
228228
*
229229
* @return bool
230230
*/
@@ -244,7 +244,7 @@ public function newClaim( Snak $mainSnak ) {
244244
}
245245

246246
/**
247-
* @deprecated since 1.0, use getStatements instead
247+
* @deprecated since 1.0, use getStatements()->addStatement() instead.
248248
*
249249
* @param Claim $statement This needs to be a Statement as of 1.0
250250
*

src/Reference.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public function count() {
6767
return count( $this->snaks );
6868
}
6969

70+
/**
71+
* @since 2.6
72+
*
73+
* @return bool
74+
*/
75+
public function isEmpty() {
76+
return $this->snaks->isEmpty();
77+
}
78+
7079
/**
7180
* @see Hashable::getHash
7281
*

src/ReferenceList.php

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

55
use Hashable;
66
use InvalidArgumentException;
7+
use Traversable;
78
use Wikibase\DataModel\Snak\Snak;
89
use Wikibase\DataModel\Snak\SnakList;
910

@@ -21,9 +22,33 @@
2122
* @licence GNU GPL v2+
2223
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
2324
* @author H. Snater < mediawiki@snater.com >
25+
* @author Thiemo Mättig
2426
*/
2527
class ReferenceList extends HashableObjectStorage {
2628

29+
/**
30+
* @param Reference[]|Traversable|null $references
31+
*
32+
* @throws InvalidArgumentException
33+
*/
34+
public function __construct( $references = null ) {
35+
if ( $references === null ) {
36+
return;
37+
}
38+
39+
if ( !is_array( $references ) && !( $references instanceof Traversable ) ) {
40+
throw new InvalidArgumentException( '$references must be an array or an instance of Traversable' );
41+
}
42+
43+
foreach ( $references as $reference ) {
44+
if ( !( $reference instanceof Reference ) ) {
45+
throw new InvalidArgumentException( 'Every element in $references must be an instance of Reference' );
46+
}
47+
48+
$this->addReference( $reference );
49+
}
50+
}
51+
2752
/**
2853
* Adds the provided reference to the list.
2954
*
@@ -45,6 +70,17 @@ public function addReference( Reference $reference, $index = null ) {
4570
}
4671
}
4772

73+
/**
74+
* @see SplObjectStorage::attach
75+
* @param Reference $reference
76+
* @param mixed $data
77+
*/
78+
public function attach( $reference, $data = null ) {
79+
if ( !$reference->isEmpty() ) {
80+
parent::attach( $reference, $data );
81+
}
82+
}
83+
4884
// @codingStandardsIgnoreStart
4985
/**
5086
* @since 1.1

0 commit comments

Comments
 (0)