@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | $this->dataValueFactory = $dataValueFactory; |
40 | 40 | } |
41 | 41 | |
42 | - public function unabbreviateViolationMessageKey( $messageKeySuffix ) { |
|
43 | - return ViolationMessage::MESSAGE_KEY_PREFIX . $messageKeySuffix; |
|
42 | + public function unabbreviateViolationMessageKey($messageKeySuffix) { |
|
43 | + return ViolationMessage::MESSAGE_KEY_PREFIX.$messageKeySuffix; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param array $serialization |
48 | 48 | * @return ViolationMessage |
49 | 49 | */ |
50 | - public function deserialize( $serialization ) { |
|
51 | - Assert::parameterType( 'array', $serialization, '$serialization' ); |
|
50 | + public function deserialize($serialization) { |
|
51 | + Assert::parameterType('array', $serialization, '$serialization'); |
|
52 | 52 | |
53 | 53 | $message = new ViolationMessage( |
54 | - $this->unabbreviateViolationMessageKey( $serialization['k'] ) |
|
54 | + $this->unabbreviateViolationMessageKey($serialization['k']) |
|
55 | 55 | ); |
56 | 56 | |
57 | - foreach ( $serialization['a'] as $serializedArgument ) { |
|
58 | - $message = $this->deserializeArgument( $message, $serializedArgument ); |
|
57 | + foreach ($serialization['a'] as $serializedArgument) { |
|
58 | + $message = $this->deserializeArgument($message, $serializedArgument); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return $message; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param array $serializedArgument [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
67 | 67 | * @return ViolationMessage $message with the deserialized argument appended |
68 | 68 | */ |
69 | - private function deserializeArgument( ViolationMessage $message, array $serializedArgument ) { |
|
69 | + private function deserializeArgument(ViolationMessage $message, array $serializedArgument) { |
|
70 | 70 | $methods = [ |
71 | 71 | ViolationMessage::TYPE_ENTITY_ID => 'deserializeEntityId', |
72 | 72 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'deserializeEntityIdList', |
@@ -87,23 +87,23 @@ discard block |
||
87 | 87 | $serializedValue = $serializedArgument['v']; |
88 | 88 | $role = $serializedArgument['r']; |
89 | 89 | |
90 | - if ( array_key_exists( $type, $methods ) ) { |
|
90 | + if (array_key_exists($type, $methods)) { |
|
91 | 91 | $method = $methods[$type]; |
92 | - $value = $this->$method( $serializedValue ); |
|
92 | + $value = $this->$method($serializedValue); |
|
93 | 93 | } else { |
94 | 94 | throw new InvalidArgumentException( |
95 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
95 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
96 | 96 | ); |
97 | 97 | } |
98 | 98 | |
99 | - return $message->withArgument( $type, $role, $value ); |
|
99 | + return $message->withArgument($type, $role, $value); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param string $string any value that shall simply be deserialized into itself |
104 | 104 | * @return string that same value, unchanged |
105 | 105 | */ |
106 | - private function deserializeStringByIdentity( $string ) { |
|
106 | + private function deserializeStringByIdentity($string) { |
|
107 | 107 | return $string; |
108 | 108 | } |
109 | 109 | |
@@ -111,30 +111,30 @@ discard block |
||
111 | 111 | * @param string $entityIdSerialization entity ID serialization |
112 | 112 | * @return EntityId |
113 | 113 | */ |
114 | - private function deserializeEntityId( $entityIdSerialization ) { |
|
115 | - return $this->entityIdParser->parse( $entityIdSerialization ); |
|
114 | + private function deserializeEntityId($entityIdSerialization) { |
|
115 | + return $this->entityIdParser->parse($entityIdSerialization); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | 119 | * @param string[] $entityIdSerializations entity ID serializations |
120 | 120 | * @return EntityId[] |
121 | 121 | */ |
122 | - private function deserializeEntityIdList( array $entityIdSerializations ) { |
|
123 | - return array_map( [ $this, 'deserializeEntityId' ], $entityIdSerializations ); |
|
122 | + private function deserializeEntityIdList(array $entityIdSerializations) { |
|
123 | + return array_map([$this, 'deserializeEntityId'], $entityIdSerializations); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | 127 | * @param string $valueSerialization entity ID serialization, '::somevalue' or '::novalue' |
128 | 128 | * @return ItemIdSnakValue |
129 | 129 | */ |
130 | - private function deserializeItemIdSnakValue( $valueSerialization ) { |
|
131 | - switch ( $valueSerialization ) { |
|
130 | + private function deserializeItemIdSnakValue($valueSerialization) { |
|
131 | + switch ($valueSerialization) { |
|
132 | 132 | case '::somevalue': |
133 | 133 | return ItemIdSnakValue::someValue(); |
134 | 134 | case '::novalue': |
135 | 135 | return ItemIdSnakValue::noValue(); |
136 | 136 | default: |
137 | - return ItemIdSnakValue::fromItemId( $this->deserializeEntityId( $valueSerialization ) ); |
|
137 | + return ItemIdSnakValue::fromItemId($this->deserializeEntityId($valueSerialization)); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -142,24 +142,24 @@ discard block |
||
142 | 142 | * @param string[] $valueSerializations entity ID serializations, '::somevalue's or '::novalue's |
143 | 143 | * @return ItemIdSnakValue[] |
144 | 144 | */ |
145 | - private function deserializeItemIdSnakValueList( $valueSerializations ) { |
|
146 | - return array_map( [ $this, 'deserializeItemIdSnakValue' ], $valueSerializations ); |
|
145 | + private function deserializeItemIdSnakValueList($valueSerializations) { |
|
146 | + return array_map([$this, 'deserializeItemIdSnakValue'], $valueSerializations); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | 150 | * @param array $dataValueSerialization the data value in array form |
151 | 151 | * @return DataValue |
152 | 152 | */ |
153 | - private function deserializeDataValue( array $dataValueSerialization ) { |
|
154 | - return $this->dataValueFactory->newFromArray( $dataValueSerialization ); |
|
153 | + private function deserializeDataValue(array $dataValueSerialization) { |
|
154 | + return $this->dataValueFactory->newFromArray($dataValueSerialization); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * @param string $contextTypeAbbreviation |
159 | 159 | * @return string one of the Context::TYPE_* constants |
160 | 160 | */ |
161 | - private function deserializeContextType( $contextTypeAbbreviation ) { |
|
162 | - switch ( $contextTypeAbbreviation ) { |
|
161 | + private function deserializeContextType($contextTypeAbbreviation) { |
|
162 | + switch ($contextTypeAbbreviation) { |
|
163 | 163 | case 's': |
164 | 164 | return Context::TYPE_STATEMENT; |
165 | 165 | case 'q': |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | default: |
170 | 170 | // @codeCoverageIgnoreStart |
171 | 171 | throw new LogicException( |
172 | - 'Unknown context type abbreviation ' . $contextTypeAbbreviation |
|
172 | + 'Unknown context type abbreviation '.$contextTypeAbbreviation |
|
173 | 173 | ); |
174 | 174 | // @codeCoverageIgnoreEnd |
175 | 175 | } |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | * @param string[] $contextTypeAbbreviations |
180 | 180 | * @return string[] Context::TYPE_* constants |
181 | 181 | */ |
182 | - private function deserializeContextTypeList( array $contextTypeAbbreviations ) { |
|
183 | - return array_map( [ $this, 'deserializeContextType' ], $contextTypeAbbreviations ); |
|
182 | + private function deserializeContextTypeList(array $contextTypeAbbreviations) { |
|
183 | + return array_map([$this, 'deserializeContextType'], $contextTypeAbbreviations); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | 187 | * @param mixed $textSerialization {@see MultilingualTextValue::getArrayValue} |
188 | 188 | * @return MultilingualTextValue |
189 | 189 | */ |
190 | - private function deserializeMultilingualText( $textSerialization ) { |
|
191 | - return MultilingualTextValue::newFromArray( $textSerialization ); |
|
190 | + private function deserializeMultilingualText($textSerialization) { |
|
191 | + return MultilingualTextValue::newFromArray($textSerialization); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | } |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class ViolationMessageSerializer implements Serializer { |
21 | 21 | |
22 | - private function abbreviateViolationMessageKey( $fullMessageKey ) { |
|
23 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
22 | + private function abbreviateViolationMessageKey($fullMessageKey) { |
|
23 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param ViolationMessage $object |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - public function serialize( $object ) { |
|
30 | + public function serialize($object) { |
|
31 | 31 | /** @var ViolationMessage $object */ |
32 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
32 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
33 | 33 | |
34 | 34 | $arguments = $object->getArguments(); |
35 | 35 | $serializedArguments = []; |
36 | - foreach ( $arguments as $argument ) { |
|
37 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
36 | + foreach ($arguments as $argument) { |
|
37 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return [ |
41 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
41 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
42 | 42 | 'a' => $serializedArguments, |
43 | 43 | ]; |
44 | 44 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param array $argument element of ViolationMessage::getArguments() |
48 | 48 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
49 | 49 | */ |
50 | - private function serializeArgument( array $argument ) { |
|
50 | + private function serializeArgument(array $argument) { |
|
51 | 51 | $methods = [ |
52 | 52 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
53 | 53 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'serializeEntityIdList', |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | $value = $argument['value']; |
69 | 69 | $role = $argument['role']; |
70 | 70 | |
71 | - if ( array_key_exists( $type, $methods ) ) { |
|
71 | + if (array_key_exists($type, $methods)) { |
|
72 | 72 | $method = $methods[$type]; |
73 | - $serializedValue = $this->$method( $value ); |
|
73 | + $serializedValue = $this->$method($value); |
|
74 | 74 | } else { |
75 | 75 | throw new InvalidArgumentException( |
76 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
76 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * @param string $string any value that shall simply be serialized to itself |
91 | 91 | * @return string that same value, unchanged |
92 | 92 | */ |
93 | - private function serializeStringByIdentity( $string ) { |
|
94 | - Assert::parameterType( 'string', $string, '$string' ); |
|
93 | + private function serializeStringByIdentity($string) { |
|
94 | + Assert::parameterType('string', $string, '$string'); |
|
95 | 95 | return $string; |
96 | 96 | } |
97 | 97 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param EntityId $entityId |
100 | 100 | * @return string entity ID serialization |
101 | 101 | */ |
102 | - private function serializeEntityId( EntityId $entityId ) { |
|
102 | + private function serializeEntityId(EntityId $entityId) { |
|
103 | 103 | return $entityId->getSerialization(); |
104 | 104 | } |
105 | 105 | |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | * @param EntityId[] $entityIdList |
108 | 108 | * @return string[] entity ID serializations |
109 | 109 | */ |
110 | - private function serializeEntityIdList( array $entityIdList ) { |
|
111 | - return array_map( [ $this, 'serializeEntityId' ], $entityIdList ); |
|
110 | + private function serializeEntityIdList(array $entityIdList) { |
|
111 | + return array_map([$this, 'serializeEntityId'], $entityIdList); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | * @return string entity ID serialization, '::somevalue', or '::novalue' |
117 | 117 | * (according to EntityId::PATTERN, entity ID serializations can never begin with two colons) |
118 | 118 | */ |
119 | - private function serializeItemIdSnakValue( ItemIdSnakValue $value ) { |
|
120 | - switch ( true ) { |
|
119 | + private function serializeItemIdSnakValue(ItemIdSnakValue $value) { |
|
120 | + switch (true) { |
|
121 | 121 | case $value->isValue(): |
122 | - return $this->serializeEntityId( $value->getItemId() ); |
|
122 | + return $this->serializeEntityId($value->getItemId()); |
|
123 | 123 | case $value->isSomeValue(): |
124 | 124 | return '::somevalue'; |
125 | 125 | case $value->isNoValue(): |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | * @param ItemIdSnakValue[] $valueList |
138 | 138 | * @return string[] array of entity ID serializations, '::somevalue's or '::novalue's |
139 | 139 | */ |
140 | - private function serializeItemIdSnakValueList( array $valueList ) { |
|
141 | - return array_map( [ $this, 'serializeItemIdSnakValue' ], $valueList ); |
|
140 | + private function serializeItemIdSnakValueList(array $valueList) { |
|
141 | + return array_map([$this, 'serializeItemIdSnakValue'], $valueList); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * @param DataValue $dataValue |
146 | 146 | * @return array the data value in array form |
147 | 147 | */ |
148 | - private function serializeDataValue( DataValue $dataValue ) { |
|
148 | + private function serializeDataValue(DataValue $dataValue) { |
|
149 | 149 | return $dataValue->toArray(); |
150 | 150 | } |
151 | 151 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param string $contextType one of the Context::TYPE_* constants |
154 | 154 | * @return string the abbreviated context type |
155 | 155 | */ |
156 | - private function serializeContextType( $contextType ) { |
|
157 | - switch ( $contextType ) { |
|
156 | + private function serializeContextType($contextType) { |
|
157 | + switch ($contextType) { |
|
158 | 158 | case Context::TYPE_STATEMENT: |
159 | 159 | return 's'; |
160 | 160 | case Context::TYPE_QUALIFIER: |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | default: |
165 | 165 | // @codeCoverageIgnoreStart |
166 | 166 | throw new LogicException( |
167 | - 'Unknown context type ' . $contextType |
|
167 | + 'Unknown context type '.$contextType |
|
168 | 168 | ); |
169 | 169 | // @codeCoverageIgnoreEnd |
170 | 170 | } |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | * @param string[] $contextTypeList Context::TYPE_* constants |
175 | 175 | * @return string[] abbreviated context types |
176 | 176 | */ |
177 | - private function serializeContextTypeList( array $contextTypeList ) { |
|
178 | - return array_map( [ $this, 'serializeContextType' ], $contextTypeList ); |
|
177 | + private function serializeContextTypeList(array $contextTypeList) { |
|
178 | + return array_map([$this, 'serializeContextType'], $contextTypeList); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | 182 | * @param MultilingualTextValue $text |
183 | 183 | * @return mixed {@see MultilingualTextValue::getArrayValue} |
184 | 184 | */ |
185 | - private function serializeMultilingualText( MultilingualTextValue $text ) { |
|
185 | + private function serializeMultilingualText(MultilingualTextValue $text) { |
|
186 | 186 | return $text->getArrayValue(); |
187 | 187 | } |
188 | 188 |