@@ -36,6 +36,6 @@ |
||
36 | 36 | * @return EntityId|null Returns null in case none of the target entities are referenced. |
37 | 37 | * @throws ReferencedEntityIdLookupException |
38 | 38 | */ |
39 | - public function getReferencedEntityId( EntityId $fromId, PropertyId $propertyId, array $toIds ); |
|
39 | + public function getReferencedEntityId(EntityId $fromId, PropertyId $propertyId, array $toIds); |
|
40 | 40 | |
41 | 41 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param string|null $message |
25 | 25 | * @param Exception|null $previous |
26 | 26 | */ |
27 | - public function __construct( PropertyId $propertyId, $message = null, ?Exception $previous = null ) { |
|
27 | + public function __construct(PropertyId $propertyId, $message = null, ?Exception $previous = null) { |
|
28 | 28 | $this->propertyId = $propertyId; |
29 | 29 | |
30 | 30 | parent::__construct( |
@@ -22,6 +22,6 @@ |
||
22 | 22 | * @return string |
23 | 23 | * @throws PropertyDataTypeLookupException |
24 | 24 | */ |
25 | - public function getDataTypeIdForProperty( PropertyId $propertyId ); |
|
25 | + public function getDataTypeIdForProperty(PropertyId $propertyId); |
|
26 | 26 | |
27 | 27 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | $message = $message ?: 'Referenced entity id lookup failed: Maximum number of entity visits (' . |
42 | 42 | $maxEntityVisits . ') exhausted.'; |
43 | 43 | |
44 | - parent::__construct( $fromId, $propertyId, $toIds, $message, $previous ); |
|
44 | + parent::__construct($fromId, $propertyId, $toIds, $message, $previous); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @throws InvalidArgumentException |
30 | 30 | */ |
31 | - public function __construct( $propertyIdProviders ) { |
|
32 | - $this->assertArePropertyIdProviders( $propertyIdProviders ); |
|
33 | - $this->indexPropertyIdProviders( $propertyIdProviders ); |
|
31 | + public function __construct($propertyIdProviders) { |
|
32 | + $this->assertArePropertyIdProviders($propertyIdProviders); |
|
33 | + $this->indexPropertyIdProviders($propertyIdProviders); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param PropertyIdProvider[]|Traversable $propertyIdProviders |
38 | 38 | */ |
39 | - private function assertArePropertyIdProviders( $propertyIdProviders ) { |
|
40 | - if ( !is_iterable( $propertyIdProviders ) ) { |
|
41 | - throw new InvalidArgumentException( '$propertyIdProviders must be an array or an instance of Traversable' ); |
|
39 | + private function assertArePropertyIdProviders($propertyIdProviders) { |
|
40 | + if (!is_iterable($propertyIdProviders)) { |
|
41 | + throw new InvalidArgumentException('$propertyIdProviders must be an array or an instance of Traversable'); |
|
42 | 42 | } |
43 | 43 | |
44 | - foreach ( $propertyIdProviders as $propertyIdProvider ) { |
|
45 | - if ( !( $propertyIdProvider instanceof PropertyIdProvider ) ) { |
|
44 | + foreach ($propertyIdProviders as $propertyIdProvider) { |
|
45 | + if (!($propertyIdProvider instanceof PropertyIdProvider)) { |
|
46 | 46 | throw new InvalidArgumentException( |
47 | 47 | 'Every element in $propertyIdProviders must be an instance of PropertyIdProvider' |
48 | 48 | ); |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @param PropertyIdProvider[]|Traversable $propertyIdProviders |
55 | 55 | */ |
56 | - private function indexPropertyIdProviders( $propertyIdProviders ) { |
|
57 | - foreach ( $propertyIdProviders as $propertyIdProvider ) { |
|
58 | - $this->addPropertyIdProvider( $propertyIdProvider ); |
|
56 | + private function indexPropertyIdProviders($propertyIdProviders) { |
|
57 | + foreach ($propertyIdProviders as $propertyIdProvider) { |
|
58 | + $this->addPropertyIdProvider($propertyIdProvider); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - private function addPropertyIdProvider( PropertyIdProvider $propertyIdProvider ) { |
|
62 | + private function addPropertyIdProvider(PropertyIdProvider $propertyIdProvider) { |
|
63 | 63 | $idSerialization = $propertyIdProvider->getPropertyId()->getSerialization(); |
64 | 64 | $this->byPropertyId[$idSerialization][] = $propertyIdProvider; |
65 | 65 | } |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function getPropertyIds() { |
75 | 75 | return array_map( |
76 | - static function( $propertyId ) { |
|
77 | - return new NumericPropertyId( $propertyId ); |
|
76 | + static function($propertyId) { |
|
77 | + return new NumericPropertyId($propertyId); |
|
78 | 78 | }, |
79 | - array_keys( $this->byPropertyId ) |
|
79 | + array_keys($this->byPropertyId) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | * @throws OutOfBoundsException |
91 | 91 | * @return PropertyIdProvider[] |
92 | 92 | */ |
93 | - public function getByPropertyId( NumericPropertyId $propertyId ) { |
|
93 | + public function getByPropertyId(NumericPropertyId $propertyId) { |
|
94 | 94 | $idSerialization = $propertyId->getSerialization(); |
95 | 95 | |
96 | - if ( !isset( $this->byPropertyId[$idSerialization] ) ) { |
|
97 | - throw new OutOfBoundsException( 'PropertyIdProvider with propertyId "' . $idSerialization . '" not found' ); |
|
96 | + if (!isset($this->byPropertyId[$idSerialization])) { |
|
97 | + throw new OutOfBoundsException('PropertyIdProvider with propertyId "' . $idSerialization . '" not found'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | return $this->byPropertyId[$idSerialization]; |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return bool |
111 | 111 | */ |
112 | - public function hasPropertyId( NumericPropertyId $propertyId ) { |
|
113 | - return isset( $this->byPropertyId[$propertyId->getSerialization()] ); |
|
112 | + public function hasPropertyId(NumericPropertyId $propertyId) { |
|
113 | + return isset($this->byPropertyId[$propertyId->getSerialization()]); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | private $patcher; |
25 | 25 | |
26 | 26 | public function __construct() { |
27 | - $this->patcher = new MapPatcher( false, new ListPatcher() ); |
|
27 | + $this->patcher = new MapPatcher(false, new ListPatcher()); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,18 +34,18 @@ discard block |
||
34 | 34 | * @return SiteLinkList |
35 | 35 | * @throws InvalidArgumentException |
36 | 36 | */ |
37 | - public function getPatchedSiteLinkList( SiteLinkList $siteLinks, Diff $patch ) { |
|
38 | - $baseData = $this->getSiteLinksInDiffFormat( $siteLinks ); |
|
39 | - $patchedData = $this->patcher->patch( $baseData, $patch ); |
|
37 | + public function getPatchedSiteLinkList(SiteLinkList $siteLinks, Diff $patch) { |
|
38 | + $baseData = $this->getSiteLinksInDiffFormat($siteLinks); |
|
39 | + $patchedData = $this->patcher->patch($baseData, $patch); |
|
40 | 40 | |
41 | 41 | $patchedSiteLinks = new SiteLinkList(); |
42 | 42 | |
43 | - foreach ( $patchedData as $siteId => $siteLinkData ) { |
|
44 | - if ( array_key_exists( 'name', $siteLinkData ) ) { |
|
43 | + foreach ($patchedData as $siteId => $siteLinkData) { |
|
44 | + if (array_key_exists('name', $siteLinkData)) { |
|
45 | 45 | $patchedSiteLinks->addNewSiteLink( |
46 | 46 | $siteId, |
47 | 47 | $siteLinkData['name'], |
48 | - $this->getBadgesFromSiteLinkData( $siteLinkData ) |
|
48 | + $this->getBadgesFromSiteLinkData($siteLinkData) |
|
49 | 49 | ); |
50 | 50 | } |
51 | 51 | } |
@@ -58,27 +58,27 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return ItemId[]|null |
60 | 60 | */ |
61 | - private function getBadgesFromSiteLinkData( array $siteLinkData ) { |
|
62 | - if ( !array_key_exists( 'badges', $siteLinkData ) || !is_array( $siteLinkData['badges'] ) ) { |
|
61 | + private function getBadgesFromSiteLinkData(array $siteLinkData) { |
|
62 | + if (!array_key_exists('badges', $siteLinkData) || !is_array($siteLinkData['badges'])) { |
|
63 | 63 | return null; |
64 | 64 | } |
65 | 65 | |
66 | 66 | return array_map( |
67 | - static function( $idSerialization ) { |
|
68 | - return new ItemId( $idSerialization ); |
|
67 | + static function($idSerialization) { |
|
68 | + return new ItemId($idSerialization); |
|
69 | 69 | }, |
70 | 70 | $siteLinkData['badges'] |
71 | 71 | ); |
72 | 72 | } |
73 | 73 | |
74 | - private function getSiteLinksInDiffFormat( SiteLinkList $siteLinks ): array { |
|
74 | + private function getSiteLinksInDiffFormat(SiteLinkList $siteLinks): array { |
|
75 | 75 | $linksInDiffFormat = []; |
76 | 76 | |
77 | - foreach ( $siteLinks->toArray() as $siteLink ) { |
|
77 | + foreach ($siteLinks->toArray() as $siteLink) { |
|
78 | 78 | $linksInDiffFormat[$siteLink->getSiteId()] = [ |
79 | 79 | 'name' => $siteLink->getPageName(), |
80 | 80 | 'badges' => array_map( |
81 | - static function( ItemId $id ) { |
|
81 | + static function(ItemId $id) { |
|
82 | 82 | return $id->getSerialization(); |
83 | 83 | }, |
84 | 84 | $siteLink->getBadges() |
@@ -41,7 +41,7 @@ |
||
41 | 41 | * |
42 | 42 | * @throws PatcherException |
43 | 43 | */ |
44 | - public function patchFingerprint( Fingerprint $fingerprint, EntityDiff $patch ) { |
|
44 | + public function patchFingerprint(Fingerprint $fingerprint, EntityDiff $patch) { |
|
45 | 45 | $this->termListPatcher->patchTermList( |
46 | 46 | $fingerprint->getLabels(), |
47 | 47 | $patch->getLabelsDiff() |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @throws PatcherException |
31 | 31 | */ |
32 | - public function patchAliasGroupList( AliasGroupList $groups, Diff $patch ) { |
|
33 | - foreach ( $patch as $lang => $diffOp ) { |
|
34 | - $this->patchAliasGroup( $groups, $lang, $diffOp ); |
|
32 | + public function patchAliasGroupList(AliasGroupList $groups, Diff $patch) { |
|
33 | + foreach ($patch as $lang => $diffOp) { |
|
34 | + $this->patchAliasGroup($groups, $lang, $diffOp); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -44,34 +44,34 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @throws PatcherException |
46 | 46 | */ |
47 | - private function patchAliasGroup( AliasGroupList $groups, $lang, DiffOp $diffOp ) { |
|
48 | - $hasLang = $groups->hasGroupForLanguage( $lang ); |
|
47 | + private function patchAliasGroup(AliasGroupList $groups, $lang, DiffOp $diffOp) { |
|
48 | + $hasLang = $groups->hasGroupForLanguage($lang); |
|
49 | 49 | |
50 | - switch ( true ) { |
|
50 | + switch (true) { |
|
51 | 51 | case $diffOp instanceof DiffOpAdd: |
52 | - if ( !$hasLang ) { |
|
53 | - $groups->setAliasesForLanguage( $lang, $diffOp->getNewValue() ); |
|
52 | + if (!$hasLang) { |
|
53 | + $groups->setAliasesForLanguage($lang, $diffOp->getNewValue()); |
|
54 | 54 | } |
55 | 55 | break; |
56 | 56 | |
57 | 57 | case $diffOp instanceof DiffOpChange: |
58 | - $this->applyAliasGroupChange( $groups, $lang, $diffOp ); |
|
58 | + $this->applyAliasGroupChange($groups, $lang, $diffOp); |
|
59 | 59 | break; |
60 | 60 | |
61 | 61 | case $diffOp instanceof DiffOpRemove: |
62 | - if ( $hasLang |
|
63 | - && $groups->getByLanguage( $lang )->getAliases() === $diffOp->getOldValue() |
|
62 | + if ($hasLang |
|
63 | + && $groups->getByLanguage($lang)->getAliases() === $diffOp->getOldValue() |
|
64 | 64 | ) { |
65 | - $groups->removeByLanguage( $lang ); |
|
65 | + $groups->removeByLanguage($lang); |
|
66 | 66 | } |
67 | 67 | break; |
68 | 68 | |
69 | 69 | case $diffOp instanceof Diff: |
70 | - $this->applyAliasGroupDiff( $groups, $lang, $diffOp ); |
|
70 | + $this->applyAliasGroupDiff($groups, $lang, $diffOp); |
|
71 | 71 | break; |
72 | 72 | |
73 | 73 | default: |
74 | - throw new PatcherException( 'Invalid aliases diff' ); |
|
74 | + throw new PatcherException('Invalid aliases diff'); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @param string $lang |
81 | 81 | * @param DiffOpChange $patch |
82 | 82 | */ |
83 | - private function applyAliasGroupChange( AliasGroupList $groups, $lang, DiffOpChange $patch ) { |
|
84 | - if ( $groups->hasGroupForLanguage( $lang ) |
|
85 | - && $groups->getByLanguage( $lang )->getAliases() === $patch->getOldValue() |
|
83 | + private function applyAliasGroupChange(AliasGroupList $groups, $lang, DiffOpChange $patch) { |
|
84 | + if ($groups->hasGroupForLanguage($lang) |
|
85 | + && $groups->getByLanguage($lang)->getAliases() === $patch->getOldValue() |
|
86 | 86 | ) { |
87 | - $groups->setAliasesForLanguage( $lang, $patch->getNewValue() ); |
|
87 | + $groups->setAliasesForLanguage($lang, $patch->getNewValue()); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | * @param string $lang |
94 | 94 | * @param Diff $patch |
95 | 95 | */ |
96 | - private function applyAliasGroupDiff( AliasGroupList $groups, $lang, Diff $patch ) { |
|
97 | - $hasLang = $groups->hasGroupForLanguage( $lang ); |
|
96 | + private function applyAliasGroupDiff(AliasGroupList $groups, $lang, Diff $patch) { |
|
97 | + $hasLang = $groups->hasGroupForLanguage($lang); |
|
98 | 98 | |
99 | - if ( $hasLang || !$this->containsOperationsOnOldValues( $patch ) ) { |
|
100 | - $aliases = $hasLang ? $groups->getByLanguage( $lang )->getAliases() : []; |
|
101 | - $aliases = $this->getPatchedAliases( $aliases, $patch ); |
|
102 | - $groups->setAliasesForLanguage( $lang, $aliases ); |
|
99 | + if ($hasLang || !$this->containsOperationsOnOldValues($patch)) { |
|
100 | + $aliases = $hasLang ? $groups->getByLanguage($lang)->getAliases() : []; |
|
101 | + $aliases = $this->getPatchedAliases($aliases, $patch); |
|
102 | + $groups->setAliasesForLanguage($lang, $aliases); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return bool |
110 | 110 | */ |
111 | - private function containsOperationsOnOldValues( Diff $diff ) { |
|
111 | + private function containsOperationsOnOldValues(Diff $diff) { |
|
112 | 112 | return $diff->getChanges() !== [] |
113 | 113 | || $diff->getRemovals() !== []; |
114 | 114 | } |
@@ -122,30 +122,30 @@ discard block |
||
122 | 122 | * @throws PatcherException |
123 | 123 | * @return string[] |
124 | 124 | */ |
125 | - private function getPatchedAliases( array $aliases, Diff $patch ) { |
|
126 | - foreach ( $patch as $diffOp ) { |
|
127 | - switch ( true ) { |
|
125 | + private function getPatchedAliases(array $aliases, Diff $patch) { |
|
126 | + foreach ($patch as $diffOp) { |
|
127 | + switch (true) { |
|
128 | 128 | case $diffOp instanceof DiffOpAdd: |
129 | 129 | $aliases[] = $diffOp->getNewValue(); |
130 | 130 | break; |
131 | 131 | |
132 | 132 | case $diffOp instanceof DiffOpChange: |
133 | - $key = array_search( $diffOp->getOldValue(), $aliases, true ); |
|
134 | - if ( $key !== false ) { |
|
135 | - unset( $aliases[$key] ); |
|
133 | + $key = array_search($diffOp->getOldValue(), $aliases, true); |
|
134 | + if ($key !== false) { |
|
135 | + unset($aliases[$key]); |
|
136 | 136 | $aliases[] = $diffOp->getNewValue(); |
137 | 137 | } |
138 | 138 | break; |
139 | 139 | |
140 | 140 | case $diffOp instanceof DiffOpRemove: |
141 | - $key = array_search( $diffOp->getOldValue(), $aliases, true ); |
|
142 | - if ( $key !== false ) { |
|
143 | - unset( $aliases[$key] ); |
|
141 | + $key = array_search($diffOp->getOldValue(), $aliases, true); |
|
142 | + if ($key !== false) { |
|
143 | + unset($aliases[$key]); |
|
144 | 144 | } |
145 | 145 | break; |
146 | 146 | |
147 | 147 | default: |
148 | - throw new PatcherException( 'Invalid aliases diff' ); |
|
148 | + throw new PatcherException('Invalid aliases diff'); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 |
@@ -26,29 +26,29 @@ |
||
26 | 26 | * @return Diff |
27 | 27 | * @throws UnexpectedValueException |
28 | 28 | */ |
29 | - public function getDiff( StatementList $fromStatements, StatementList $toStatements ) { |
|
29 | + public function getDiff(StatementList $fromStatements, StatementList $toStatements) { |
|
30 | 30 | return new Diff( |
31 | 31 | $this->newDiffer()->doDiff( |
32 | - $this->toDiffArray( $fromStatements ), |
|
33 | - $this->toDiffArray( $toStatements ) |
|
32 | + $this->toDiffArray($fromStatements), |
|
33 | + $this->toDiffArray($toStatements) |
|
34 | 34 | ), |
35 | 35 | true |
36 | 36 | ); |
37 | 37 | } |
38 | 38 | |
39 | 39 | private function newDiffer(): MapDiffer { |
40 | - return new MapDiffer( false, null, new ComparableComparer() ); |
|
40 | + return new MapDiffer(false, null, new ComparableComparer()); |
|
41 | 41 | } |
42 | 42 | |
43 | - private function toDiffArray( StatementList $statementList ): array { |
|
43 | + private function toDiffArray(StatementList $statementList): array { |
|
44 | 44 | $statementArray = []; |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var Statement $statement |
48 | 48 | */ |
49 | - foreach ( $statementList as $statement ) { |
|
49 | + foreach ($statementList as $statement) { |
|
50 | 50 | $guid = $statement->getGuid(); |
51 | - if ( $guid === null ) { |
|
51 | + if ($guid === null) { |
|
52 | 52 | $statementArray[] = $statement; |
53 | 53 | } else { |
54 | 54 | $statementArray[$guid] = $statement; |