Skip to content

Commit a86cdb5

Browse files
committed
Move id and fingerprint to Item and Property
1 parent 5e9a706 commit a86cdb5

3 files changed

Lines changed: 94 additions & 75 deletions

File tree

src/Entity/Entity.php

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@
2222
*/
2323
abstract class Entity implements \Comparable, FingerprintProvider, EntityDocument {
2424

25-
/**
26-
* @var EntityId|null
27-
*/
28-
protected $id;
29-
30-
/**
31-
* @var Fingerprint
32-
*/
33-
protected $fingerprint;
34-
35-
/**
36-
* Returns the id of the entity or null if it does not have one.
37-
*
38-
* @since 0.1 return type changed in 0.3
39-
*
40-
* @return EntityId|null
41-
*/
42-
public function getId() {
43-
return $this->id;
44-
}
45-
4625
/**
4726
* Sets the value for the label in a certain value.
4827
*
@@ -52,7 +31,7 @@ public function getId() {
5231
* @param string $value
5332
*/
5433
public function setLabel( $languageCode, $value ) {
55-
$this->fingerprint->setLabel( $languageCode, $value );
34+
$this->getFingerprint()->setLabel( $languageCode, $value );
5635
}
5736

5837
/**
@@ -64,7 +43,7 @@ public function setLabel( $languageCode, $value ) {
6443
* @param string $value
6544
*/
6645
public function setDescription( $languageCode, $value ) {
67-
$this->fingerprint->setDescription( $languageCode, $value );
46+
$this->getFingerprint()->setDescription( $languageCode, $value );
6847
}
6948

7049
/**
@@ -75,7 +54,7 @@ public function setDescription( $languageCode, $value ) {
7554
* @param string $languageCode
7655
*/
7756
public function removeLabel( $languageCode ) {
78-
$this->fingerprint->removeLabel( $languageCode );
57+
$this->getFingerprint()->removeLabel( $languageCode );
7958
}
8059

8160
/**
@@ -86,7 +65,7 @@ public function removeLabel( $languageCode ) {
8665
* @param string $languageCode
8766
*/
8867
public function removeDescription( $languageCode ) {
89-
$this->fingerprint->removeDescription( $languageCode );
68+
$this->getFingerprint()->removeDescription( $languageCode );
9069
}
9170

9271
/**
@@ -99,7 +78,7 @@ public function removeDescription( $languageCode ) {
9978
* @return string[]
10079
*/
10180
public function getAliases( $languageCode ) {
102-
$aliases = $this->fingerprint->getAliasGroups();
81+
$aliases = $this->getFingerprint()->getAliasGroups();
10382

10483
if ( $aliases->hasGroupForLanguage( $languageCode ) ) {
10584
return $aliases->getByLanguage( $languageCode )->getAliases();
@@ -119,7 +98,7 @@ public function getAliases( $languageCode ) {
11998
* @return array[]
12099
*/
121100
public function getAllAliases( array $languageCodes = null ) {
122-
$aliases = $this->fingerprint->getAliasGroups();
101+
$aliases = $this->getFingerprint()->getAliasGroups();
123102

124103
$textLists = array();
125104

@@ -144,7 +123,7 @@ public function getAllAliases( array $languageCodes = null ) {
144123
* @param string[] $aliases
145124
*/
146125
public function setAliases( $languageCode, array $aliases ) {
147-
$this->fingerprint->setAliasGroup( $languageCode, $aliases );
126+
$this->getFingerprint()->setAliasGroup( $languageCode, $aliases );
148127
}
149128

150129
/**
@@ -222,11 +201,11 @@ public function getLabels( array $languageCodes = null ) {
222201
* @return string|bool
223202
*/
224203
public function getDescription( $languageCode ) {
225-
if ( !$this->fingerprint->hasDescription( $languageCode ) ) {
204+
if ( !$this->getFingerprint()->hasDescription( $languageCode ) ) {
226205
return false;
227206
}
228207

229-
return $this->fingerprint->getDescription( $languageCode )->getText();
208+
return $this->getFingerprint()->getDescription( $languageCode )->getText();
230209
}
231210

232211
/**
@@ -240,11 +219,11 @@ public function getDescription( $languageCode ) {
240219
* @return string|bool
241220
*/
242221
public function getLabel( $languageCode ) {
243-
if ( !$this->fingerprint->hasLabel( $languageCode ) ) {
222+
if ( !$this->getFingerprint()->hasLabel( $languageCode ) ) {
244223
return false;
245224
}
246225

247-
return $this->fingerprint->getLabel( $languageCode )->getText();
226+
return $this->getFingerprint()->getLabel( $languageCode )->getText();
248227
}
249228

250229
/**
@@ -257,9 +236,9 @@ public function getLabel( $languageCode ) {
257236
*/
258237
private function getMultilangTexts( $fieldKey, array $languageCodes = null ) {
259238
if ( $fieldKey === 'label' ) {
260-
$textList = $this->fingerprint->getLabels()->toTextArray();
239+
$textList = $this->getFingerprint()->getLabels()->toTextArray();
261240
} else {
262-
$textList = $this->fingerprint->getDescriptions()->toTextArray();
241+
$textList = $this->getFingerprint()->getDescriptions()->toTextArray();
263242
}
264243

265244
if ( $languageCodes !== null ) {
@@ -280,7 +259,7 @@ private function getMultilangTexts( $fieldKey, array $languageCodes = null ) {
280259
* @param string[] $labels
281260
*/
282261
public function setLabels( array $labels ) {
283-
$this->fingerprint->setLabels( new TermList() );
262+
$this->getFingerprint()->setLabels( new TermList() );
284263

285264
foreach ( $labels as $languageCode => $labelText ) {
286265
$this->setLabel( $languageCode, $labelText );
@@ -298,7 +277,7 @@ public function setLabels( array $labels ) {
298277
* @param string[] $descriptions
299278
*/
300279
public function setDescriptions( array $descriptions ) {
301-
$this->fingerprint->setDescriptions( new TermList() );
280+
$this->getFingerprint()->setDescriptions( new TermList() );
302281

303282
foreach ( $descriptions as $languageCode => $descriptionText ) {
304283
$this->setDescription( $languageCode, $descriptionText );
@@ -317,7 +296,7 @@ public function setDescriptions( array $descriptions ) {
317296
* @param array[] $aliasLists
318297
*/
319298
public function setAllAliases( array $aliasLists ) {
320-
$this->fingerprint->setAliasGroups( new AliasGroupList() );
299+
$this->getFingerprint()->setAliasGroups( new AliasGroupList() );
321300

322301
foreach( $aliasLists as $languageCode => $aliasList ) {
323302
$this->setAliases( $languageCode, $aliasList );
@@ -346,26 +325,6 @@ public function getClaims() {
346325
return array();
347326
}
348327

349-
/**
350-
* @since 0.7.3
351-
* @deprecated since 1.0
352-
*
353-
* @return Fingerprint
354-
*/
355-
public function getFingerprint() {
356-
return $this->fingerprint;
357-
}
358-
359-
/**
360-
* @since 0.7.3
361-
* @deprecated since 1.0
362-
*
363-
* @param Fingerprint $fingerprint
364-
*/
365-
public function setFingerprint( Fingerprint $fingerprint ) {
366-
$this->fingerprint = $fingerprint;
367-
}
368-
369328
/**
370329
* Returns if the Entity has no content.
371330
* Having an id set does not count as having content.

src/Entity/Item.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class Item extends Entity implements StatementListHolder {
2525

2626
const ENTITY_TYPE = 'item';
2727

28+
/**
29+
* @var ItemId|null
30+
*/
31+
private $id;
32+
33+
/**
34+
* @var Fingerprint
35+
*/
36+
private $fingerprint;
37+
2838
/**
2939
* @var SiteLinkList
3040
*/
@@ -55,6 +65,17 @@ public function __construct(
5565
$this->statements = $statements ?: new StatementList();
5666
}
5767

68+
/**
69+
* Returns the id of the entity or null if it does not have one.
70+
*
71+
* @since 5.0
72+
*
73+
* @return ItemId|null
74+
*/
75+
public function getId() {
76+
return $this->id;
77+
}
78+
5879
/**
5980
* Can be integer since 0.1.
6081
* Can be ItemId since 0.5.
@@ -76,6 +97,24 @@ public function setId( $id ) {
7697
}
7798
}
7899

100+
/**
101+
* @since 5.0
102+
*
103+
* @return Fingerprint
104+
*/
105+
public function getFingerprint() {
106+
return $this->fingerprint;
107+
}
108+
109+
/**
110+
* @since 5.0
111+
*
112+
* @param Fingerprint $fingerprint
113+
*/
114+
public function setFingerprint( Fingerprint $fingerprint ) {
115+
$this->fingerprint = $fingerprint;
116+
}
117+
79118
/**
80119
* @param string $languageCode
81120
* @param string $value
@@ -106,15 +145,6 @@ public function setAliases( $languageCode, array $aliases ) {
106145
$this->fingerprint->setAliasGroup( $languageCode, $aliases );
107146
}
108147

109-
/**
110-
* @since 0.1 return type changed in 0.3
111-
*
112-
* @return ItemId|null
113-
*/
114-
public function getId() {
115-
return $this->id;
116-
}
117-
118148
/**
119149
* @since 0.8
120150
*

src/Entity/Property.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class Property extends Entity implements StatementListHolder {
2222

2323
const ENTITY_TYPE = 'property';
2424

25+
/**
26+
* @var PropertyId|null
27+
*/
28+
private $id;
29+
30+
/**
31+
* @var Fingerprint
32+
*/
33+
private $fingerprint;
34+
2535
/**
2636
* @var string
2737
*/
@@ -52,6 +62,17 @@ public function __construct(
5262
$this->statements = $statements ?: new StatementList();
5363
}
5464

65+
/**
66+
* Returns the id of the entity or null if it does not have one.
67+
*
68+
* @since 5.0
69+
*
70+
* @return PropertyId|null
71+
*/
72+
public function getId() {
73+
return $this->id;
74+
}
75+
5576
/**
5677
* Can be integer since 0.1.
5778
* Can be PropertyId since 0.5.
@@ -73,6 +94,24 @@ public function setId( $id ) {
7394
}
7495
}
7596

97+
/**
98+
* @since 5.0
99+
*
100+
* @return Fingerprint
101+
*/
102+
public function getFingerprint() {
103+
return $this->fingerprint;
104+
}
105+
106+
/**
107+
* @since 5.0
108+
*
109+
* @param Fingerprint $fingerprint
110+
*/
111+
public function setFingerprint( Fingerprint $fingerprint ) {
112+
$this->fingerprint = $fingerprint;
113+
}
114+
76115
/**
77116
* @param string $languageCode
78117
* @param string $value
@@ -103,15 +142,6 @@ public function setAliases( $languageCode, array $aliases ) {
103142
$this->fingerprint->setAliasGroup( $languageCode, $aliases );
104143
}
105144

106-
/**
107-
* @since 0.1 return type changed in 0.3
108-
*
109-
* @return PropertyId|null
110-
*/
111-
public function getId() {
112-
return $this->id;
113-
}
114-
115145
/**
116146
* @since 0.4
117147
*

0 commit comments

Comments
 (0)