Completed
Push — master ( 17657a...f01a3a )
by
unknown
08:59
created
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +30 added lines, -31 removed lines patch added patch discarded remove patch
@@ -93,26 +93,26 @@  discard block
 block discarded – undo
93 93
 	 * @throws ConstraintParameterException
94 94
 	 * @return CheckResult
95 95
 	 */
96
-	public function checkConstraint( Context $context, Constraint $constraint ) {
96
+	public function checkConstraint(Context $context, Constraint $constraint) {
97 97
 		$parameters = [];
98 98
 		$constraintParameters = $constraint->getConstraintParameters();
99 99
 
100
-		$format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
101
-		$parameters['pattern'] = [ $format ];
100
+		$format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
101
+		$parameters['pattern'] = [$format];
102 102
 
103 103
 		$syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter(
104 104
 			$constraintParameters,
105 105
 			WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context?
106 106
 		);
107
-		if ( $syntaxClarification !== null ) {
108
-			$parameters['clarification'] = [ $syntaxClarification ];
107
+		if ($syntaxClarification !== null) {
108
+			$parameters['clarification'] = [$syntaxClarification];
109 109
 		}
110 110
 
111 111
 		$snak = $context->getSnak();
112 112
 
113
-		if ( !$snak instanceof PropertyValueSnak ) {
113
+		if (!$snak instanceof PropertyValueSnak) {
114 114
 			// nothing to check
115
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
115
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
116 116
 		}
117 117
 
118 118
 		$dataValue = $snak->getDataValue();
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		 * error handling:
122 122
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
123 123
 		 */
124
-		switch ( $dataValue->getType() ) {
124
+		switch ($dataValue->getType()) {
125 125
 			case 'string':
126 126
 				$text = $dataValue->getValue();
127 127
 				break;
@@ -130,60 +130,59 @@  discard block
 block discarded – undo
130 130
 				$text = $dataValue->getText();
131 131
 				break;
132 132
 			default:
133
-				$message = wfMessage( "wbqc-violation-message-value-needed-of-types-2" )
133
+				$message = wfMessage("wbqc-violation-message-value-needed-of-types-2")
134 134
 						 ->rawParams(
135
-							 $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ),
136
-							 wfMessage( 'datatypes-type-string' )->escaped(),
137
-							 wfMessage( 'datatypes-type-monolingualtext' )->escaped()
135
+							 $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM),
136
+							 wfMessage('datatypes-type-string')->escaped(),
137
+							 wfMessage('datatypes-type-monolingualtext')->escaped()
138 138
 						 )
139 139
 						 ->escaped();
140
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
140
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
141 141
 		}
142 142
 
143
-		if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
144
-			if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
143
+		if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
144
+			if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
145 145
 				$message = null;
146 146
 				$status = CheckResult::STATUS_COMPLIANCE;
147 147
 			} else {
148 148
 				$message = wfMessage(
149 149
 					$syntaxClarification !== null ?
150
-						'wbqc-violation-message-format-clarification' :
151
-						'wbqc-violation-message-format'
150
+						'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format'
152 151
 				)->rawParams(
153
-					$this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ),
154
-					$this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ),
155
-					$this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE,
156
-						'<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' )
152
+					$this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY),
153
+					$this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT),
154
+					$this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE,
155
+						'<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>')
157 156
 				);
158
-				if ( $syntaxClarification !== null ) {
159
-					$message->params( $syntaxClarification );
157
+				if ($syntaxClarification !== null) {
158
+					$message->params($syntaxClarification);
160 159
 				}
161 160
 				$message = $message->escaped();
162 161
 				$status = CheckResult::STATUS_VIOLATION;
163 162
 			}
164 163
 		} else {
165
-			$message = wfMessage( "wbqc-violation-message-security-reason" )
166
-					 ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) )
164
+			$message = wfMessage("wbqc-violation-message-security-reason")
165
+					 ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM))
167 166
 					 ->escaped();
168 167
 			$status = CheckResult::STATUS_TODO;
169 168
 		}
170
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
169
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
171 170
 	}
172 171
 
173
-	public function checkConstraintParameters( Constraint $constraint ) {
172
+	public function checkConstraintParameters(Constraint $constraint) {
174 173
 		$constraintParameters = $constraint->getConstraintParameters();
175 174
 		$exceptions = [];
176 175
 		try {
177
-			$this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
178
-		} catch ( ConstraintParameterException $e ) {
176
+			$this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
177
+		} catch (ConstraintParameterException $e) {
179 178
 			$exceptions[] = $e;
180 179
 		}
181 180
 		try {
182 181
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
183 182
 				$constraintParameters,
184
-				Language::factory( 'en' ) // errors are reported independent of language requested
183
+				Language::factory('en') // errors are reported independent of language requested
185 184
 			);
186
-		} catch ( ConstraintParameterException $e ) {
185
+		} catch (ConstraintParameterException $e) {
187 186
 			$exceptions[] = $e;
188 187
 		}
189 188
 		return $exceptions;
Please login to merge, or discard this patch.