@@ -33,49 +33,49 @@ public function __construct( WikibaseApi $api, Deserializer $entityDeserializer,
33
33
/**
34
34
* @param EditInfo|null $editInfo
35
35
*
36
- * @throws RuntimeException
37
- * @throws InvalidArgumentException
36
+ * @throws RuntimeException if Content is not an EntityDocument
37
+ * @throws InvalidArgumentException if $editInfo is null and the revision does not have an EditInfo
38
38
* @return Item|Property new version of the entity
39
39
*/
40
40
public function save ( Revision $ revision , EditInfo $ editInfo = null ): object {
41
- if ( !$ revision ->getContent ()->getData () instanceof EntityDocument ) {
42
- throw new RuntimeException ( 'Can only save Content of EntityDocuments ' );
41
+ $ content = $ revision ->getContent ();
42
+ $ data = $ content ->getData ();
43
+ if (!$ data instanceof EntityDocument) {
44
+ throw new RuntimeException ('Can only save Content of EntityDocuments ' );
43
45
}
44
46
45
- /** @var Item|Property $entity */
46
- $ entity = $ revision ->getContent ()->getData ();
47
- $ serialized = $ this ->entitySerializer ->serialize ( $ entity );
47
+ $ entity = $ data ;
48
+ $ serialized = $ this ->entitySerializer ->serialize ($ entity );
48
49
49
50
$ params = [
50
- 'data ' => json_encode ( $ serialized )
51
+ 'data ' => json_encode ($ serialized )
51
52
];
52
53
53
54
$ revId = $ revision ->getId ();
54
- if ( $ revId !== null ) {
55
+ if ($ revId !== null ) {
55
56
$ params ['baserevid ' ] = $ revId ;
56
57
}
57
58
58
59
$ entityId = $ entity ->getId ();
59
- if ( $ entityId !== null ) {
60
+ if ($ entityId !== null ) {
60
61
$ params ['id ' ] = $ entityId ->getSerialization ();
61
62
62
63
// If we are provided an empty entity, then set the clear flag
63
- if ( $ entity ->isEmpty () ) {
64
+ if ($ entity ->isEmpty ()) {
64
65
$ params ['clear ' ] = true ;
65
66
}
66
-
67
-
68
67
} else {
69
68
$ params ['new ' ] = $ entity ->getType ();
70
69
}
71
70
72
71
// If no editInfo is explicitly passed call back to the one in the revision?
73
- if ( $ editInfo === null ) {
74
- $ editInfo = $ revision -> getEditInfo ( );
72
+ if ($ editInfo === null && $ revision -> getEditInfo () === null ) {
73
+ throw new InvalidArgumentException ( ' No EditInfo provided and the revision does not have one ' );
75
74
}
76
75
77
- $ result = $ this ->api ->postRequest ( 'wbeditentity ' , $ params , $ editInfo );
78
- return $ this ->entityDeserializer ->deserialize ( $ result ['entity ' ] );
76
+ $ editInfo = $ editInfo ?? $ revision ->getEditInfo ();
77
+ $ result = $ this ->api ->postRequest ('wbeditentity ' , $ params , $ editInfo );
78
+ return $ this ->entityDeserializer ->deserialize ($ result ['entity ' ]);
79
79
}
80
80
81
81
}
0 commit comments