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