Completed
Push — master ( bfeacc...2d81b2 )
by
unknown
02:37
created
src/ConstraintCheck/Checker/SymmetricChecker.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return CheckResult
82 82
 	 */
83
-	public function checkConstraint( Context $context, Constraint $constraint ) {
84
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
85
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
83
+	public function checkConstraint(Context $context, Constraint $constraint) {
84
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
85
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
86 86
 		}
87 87
 
88 88
 		$parameters = [];
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 		$snak = $context->getSnak();
91 91
 		$propertyId = $context->getSnak()->getPropertyId();
92 92
 
93
-		if ( !$snak instanceof PropertyValueSnak ) {
93
+		if (!$snak instanceof PropertyValueSnak) {
94 94
 			// nothing to check
95
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
95
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
96 96
 		}
97 97
 
98 98
 		$dataValue = $snak->getDataValue();
@@ -101,22 +101,22 @@  discard block
 block discarded – undo
101 101
 		 * error handling:
102 102
 		 *   type of $dataValue for properties with 'Symmetric' constraint has to be 'wikibase-entityid'
103 103
 		 */
104
-		if ( $dataValue->getType() !== 'wikibase-entityid' ) {
105
-			$message = wfMessage( "wbqc-violation-message-value-needed-of-type" )
104
+		if ($dataValue->getType() !== 'wikibase-entityid') {
105
+			$message = wfMessage("wbqc-violation-message-value-needed-of-type")
106 106
 					 ->rawParams(
107
-						 $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ),
107
+						 $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM),
108 108
 						 'wikibase-entityid' // TODO is there a message for this type so we can localize it?
109 109
 					 )
110 110
 					 ->escaped();
111
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
111
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
112 112
 		}
113 113
 		/** @var EntityIdValue $dataValue */
114 114
 
115 115
 		$targetEntityId = $dataValue->getEntityId();
116
-		$targetEntity = $this->entityLookup->getEntity( $targetEntityId );
117
-		if ( $targetEntity === null ) {
118
-			$message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' );
119
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
116
+		$targetEntity = $this->entityLookup->getEntity($targetEntityId);
117
+		if ($targetEntity === null) {
118
+			$message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist');
119
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
120 120
 		}
121 121
 
122 122
 		$symmetricStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue(
@@ -124,23 +124,23 @@  discard block
 block discarded – undo
124 124
 			$propertyId,
125 125
 			$context->getEntity()->getId()
126 126
 		);
127
-		if ( $symmetricStatement !== null ) {
127
+		if ($symmetricStatement !== null) {
128 128
 			$message = null;
129 129
 			$status = CheckResult::STATUS_COMPLIANCE;
130 130
 		} else {
131
-			$message = ( new ViolationMessage( 'wbqc-violation-message-symmetric' ) )
132
-				->withEntityId( $targetEntityId, Role::SUBJECT )
133
-				->withEntityId( $propertyId, Role::PREDICATE )
134
-				->withEntityId( $context->getEntity()->getId(), Role::OBJECT );
131
+			$message = (new ViolationMessage('wbqc-violation-message-symmetric'))
132
+				->withEntityId($targetEntityId, Role::SUBJECT)
133
+				->withEntityId($propertyId, Role::PREDICATE)
134
+				->withEntityId($context->getEntity()->getId(), Role::OBJECT);
135 135
 			$status = CheckResult::STATUS_VIOLATION;
136 136
 		}
137 137
 
138
-		return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) )
139
-			->withMetadata( Metadata::ofDependencyMetadata(
140
-				DependencyMetadata::ofEntityId( $targetEntityId ) ) );
138
+		return (new CheckResult($context, $constraint, $parameters, $status, $message))
139
+			->withMetadata(Metadata::ofDependencyMetadata(
140
+				DependencyMetadata::ofEntityId($targetEntityId) ));
141 141
 	}
142 142
 
143
-	public function checkConstraintParameters( Constraint $constraint ) {
143
+	public function checkConstraintParameters(Constraint $constraint) {
144 144
 		// no parameters
145 145
 		return [];
146 146
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +30 added lines, -31 removed lines patch added patch discarded remove patch
@@ -95,26 +95,26 @@  discard block
 block discarded – undo
95 95
 	 * @throws ConstraintParameterException
96 96
 	 * @return CheckResult
97 97
 	 */
98
-	public function checkConstraint( Context $context, Constraint $constraint ) {
98
+	public function checkConstraint(Context $context, Constraint $constraint) {
99 99
 		$parameters = [];
100 100
 		$constraintParameters = $constraint->getConstraintParameters();
101 101
 
102
-		$format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
103
-		$parameters['pattern'] = [ $format ];
102
+		$format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
103
+		$parameters['pattern'] = [$format];
104 104
 
105 105
 		$syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter(
106 106
 			$constraintParameters,
107 107
 			WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context?
108 108
 		);
109
-		if ( $syntaxClarification !== null ) {
110
-			$parameters['clarification'] = [ $syntaxClarification ];
109
+		if ($syntaxClarification !== null) {
110
+			$parameters['clarification'] = [$syntaxClarification];
111 111
 		}
112 112
 
113 113
 		$snak = $context->getSnak();
114 114
 
115
-		if ( !$snak instanceof PropertyValueSnak ) {
115
+		if (!$snak instanceof PropertyValueSnak) {
116 116
 			// nothing to check
117
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
117
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
118 118
 		}
119 119
 
120 120
 		$dataValue = $snak->getDataValue();
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		 * error handling:
124 124
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
125 125
 		 */
126
-		switch ( $dataValue->getType() ) {
126
+		switch ($dataValue->getType()) {
127 127
 			case 'string':
128 128
 				$text = $dataValue->getValue();
129 129
 				break;
@@ -132,59 +132,58 @@  discard block
 block discarded – undo
132 132
 				$text = $dataValue->getText();
133 133
 				break;
134 134
 			default:
135
-				$message = wfMessage( "wbqc-violation-message-value-needed-of-types-2" )
135
+				$message = wfMessage("wbqc-violation-message-value-needed-of-types-2")
136 136
 						 ->rawParams(
137
-							 $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ),
138
-							 wfMessage( 'datatypes-type-string' )->escaped(),
139
-							 wfMessage( 'datatypes-type-monolingualtext' )->escaped()
137
+							 $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM),
138
+							 wfMessage('datatypes-type-string')->escaped(),
139
+							 wfMessage('datatypes-type-monolingualtext')->escaped()
140 140
 						 )
141 141
 						 ->escaped();
142
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
142
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
143 143
 		}
144 144
 
145
-		if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
146
-			if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
145
+		if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
146
+			if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
147 147
 				$message = null;
148 148
 				$status = CheckResult::STATUS_COMPLIANCE;
149 149
 			} else {
150 150
 				$message = wfMessage(
151 151
 					$syntaxClarification !== null ?
152
-						'wbqc-violation-message-format-clarification' :
153
-						'wbqc-violation-message-format'
152
+						'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format'
154 153
 				)->rawParams(
155
-					$this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ),
156
-					$this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ),
157
-					$this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE,
158
-						'<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' )
154
+					$this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY),
155
+					$this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT),
156
+					$this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE,
157
+						'<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>')
159 158
 				);
160
-				if ( $syntaxClarification !== null ) {
161
-					$message->params( $syntaxClarification );
159
+				if ($syntaxClarification !== null) {
160
+					$message->params($syntaxClarification);
162 161
 				}
163 162
 				$message = $message->escaped();
164 163
 				$status = CheckResult::STATUS_VIOLATION;
165 164
 			}
166 165
 		} else {
167
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
168
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM );
166
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
167
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM);
169 168
 			$status = CheckResult::STATUS_TODO;
170 169
 		}
171
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
170
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
172 171
 	}
173 172
 
174
-	public function checkConstraintParameters( Constraint $constraint ) {
173
+	public function checkConstraintParameters(Constraint $constraint) {
175 174
 		$constraintParameters = $constraint->getConstraintParameters();
176 175
 		$exceptions = [];
177 176
 		try {
178
-			$this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() );
179
-		} catch ( ConstraintParameterException $e ) {
177
+			$this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId());
178
+		} catch (ConstraintParameterException $e) {
180 179
 			$exceptions[] = $e;
181 180
 		}
182 181
 		try {
183 182
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
184 183
 				$constraintParameters,
185
-				Language::factory( 'en' ) // errors are reported independent of language requested
184
+				Language::factory('en') // errors are reported independent of language requested
186 185
 			);
187
-		} catch ( ConstraintParameterException $e ) {
186
+		} catch (ConstraintParameterException $e) {
188 187
 			$exceptions[] = $e;
189 188
 		}
190 189
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessageRenderer.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -44,84 +44,84 @@
 block discarded – undo
44 44
 		$language = null,
45 45
 		$format = Message::FORMAT_ESCAPED
46 46
 	) {
47
-		if ( is_string( $violationMessage ) ) {
47
+		if (is_string($violationMessage)) {
48 48
 			// TODO remove this once all checkers produce ViolationMessage objects
49 49
 			return $violationMessage;
50 50
 		}
51
-		$message = new Message( $violationMessage->getMessageKey(), [], $language );
52
-		foreach ( $violationMessage->getArguments() as $argument ) {
53
-			$this->renderArgument( $argument, $message );
51
+		$message = new Message($violationMessage->getMessageKey(), [], $language);
52
+		foreach ($violationMessage->getArguments() as $argument) {
53
+			$this->renderArgument($argument, $message);
54 54
 		}
55
-		return $message->toString( $format );
55
+		return $message->toString($format);
56 56
 	}
57 57
 
58
-	private function addRole( $value, $role ) {
59
-		if ( $role === null ) {
58
+	private function addRole($value, $role) {
59
+		if ($role === null) {
60 60
 			return $value;
61 61
 		}
62 62
 
63
-		return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' .
64
-			$value .
63
+		return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'.
64
+			$value.
65 65
 			'</span>';
66 66
 	}
67 67
 
68
-	private function renderArgument( array $argument, Message $message ) {
69
-		switch ( $argument['type'] ) {
68
+	private function renderArgument(array $argument, Message $message) {
69
+		switch ($argument['type']) {
70 70
 			case ViolationMessage::TYPE_ENTITY_ID:
71
-				$params = $this->renderEntityId( $argument['value'], $argument['role'] );
71
+				$params = $this->renderEntityId($argument['value'], $argument['role']);
72 72
 				break;
73 73
 			case ViolationMessage::TYPE_ENTITY_ID_LIST:
74
-				$params = $this->renderEntityIdList( $argument['value'], $argument['role'] );
74
+				$params = $this->renderEntityIdList($argument['value'], $argument['role']);
75 75
 				break;
76 76
 			default:
77 77
 				throw new InvalidArgumentException(
78
-					'Unknown ViolationMessage argument type ' . $argument['type'] . '!'
78
+					'Unknown ViolationMessage argument type '.$argument['type'].'!'
79 79
 				);
80 80
 		}
81
-		$message->params( $params );
81
+		$message->params($params);
82 82
 	}
83 83
 
84
-	private function renderEntityId( EntityId $entityId, $role ) {
85
-		return Message::rawParam( $this->addRole(
86
-			$this->entityIdFormatter->formatEntityId( $entityId ),
84
+	private function renderEntityId(EntityId $entityId, $role) {
85
+		return Message::rawParam($this->addRole(
86
+			$this->entityIdFormatter->formatEntityId($entityId),
87 87
 			$role
88
-		) );
88
+		));
89 89
 	}
90 90
 
91
-	private function renderEntityIdList( array $entityIdList, $role ) {
92
-		if ( $entityIdList === [] ) {
91
+	private function renderEntityIdList(array $entityIdList, $role) {
92
+		if ($entityIdList === []) {
93 93
 			return [
94
-				Message::numParam( 0 ),
95
-				Message::rawParam( '<ul></ul>' ),
94
+				Message::numParam(0),
95
+				Message::rawParam('<ul></ul>'),
96 96
 			];
97 97
 		}
98 98
 
99
-		if ( count( $entityIdList ) > $this->maxListLength ) {
100
-			$entityIdList = array_slice( $entityIdList, 0, $this->maxListLength );
99
+		if (count($entityIdList) > $this->maxListLength) {
100
+			$entityIdList = array_slice($entityIdList, 0, $this->maxListLength);
101 101
 			$truncated = true;
102 102
 		}
103 103
 
104 104
 		$renderedParams = array_map(
105
-			[ $this, 'renderEntityId' ],
105
+			[$this, 'renderEntityId'],
106 106
 			$entityIdList,
107
-			array_fill( 0, count( $entityIdList ), $role )
107
+			array_fill(0, count($entityIdList), $role)
108 108
 		);
109 109
 		$renderedElements = array_map(
110
-			function ( $param ) {
110
+			function($param) {
111 111
 				return $param['raw'];
112 112
 			},
113 113
 			$renderedParams
114 114
 		);
115
-		if ( isset( $truncated ) ) {
116
-			$renderedElements[] = wfMessage( 'ellipsis' )->escaped();
115
+		if (isset($truncated)) {
116
+			$renderedElements[] = wfMessage('ellipsis')->escaped();
117 117
 		}
118 118
 
119 119
 		return array_merge(
120 120
 			[
121
-				Message::numParam( count( $entityIdList ) ),
121
+				Message::numParam(count($entityIdList)),
122 122
 				Message::rawParam(
123
-					'<ul><li>' .
124
-					implode( '</li><li>', $renderedElements ) .
123
+					'<ul><li>'.
124
+					implode('</li><li>', $renderedElements).
125 125
 					'</li></ul>'
126 126
 				),
127 127
 			],
Please login to merge, or discard this patch.
src/ConstraintCheck/Message/ViolationMessage.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -52,17 +52,17 @@  discard block
 block discarded – undo
52 52
 	public function __construct(
53 53
 		$messageKey
54 54
 	) {
55
-		if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) {
55
+		if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) {
56 56
 			throw new InvalidArgumentException(
57
-				'ViolationMessage key ⧼' .
58
-				$messageKey .
59
-				'⧽ should start with "' .
60
-				self::MESSAGE_KEY_PREFIX .
57
+				'ViolationMessage key ⧼'.
58
+				$messageKey.
59
+				'⧽ should start with "'.
60
+				self::MESSAGE_KEY_PREFIX.
61 61
 				'".'
62 62
 			);
63 63
 		}
64 64
 
65
-		$this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) );
65
+		$this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX));
66 66
 		$this->arguments = [];
67 67
 	}
68 68
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * @return string
72 72
 	 */
73 73
 	public function getMessageKey() {
74
-		return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix;
74
+		return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix;
75 75
 	}
76 76
 
77 77
 	/**
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 	 * @param mixed $value the value, which should match the $type
90 90
 	 * @return ViolationMessage
91 91
 	 */
92
-	private function withArgument( $type, $role, $value ) {
92
+	private function withArgument($type, $role, $value) {
93 93
 		$ret = clone $this;
94
-		$ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ];
94
+		$ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value];
95 95
 		return $ret;
96 96
 	}
97 97
 
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	 * @param string|null $role one of the Role::* constants
104 104
 	 * @return ViolationMessage
105 105
 	 */
106
-	public function withEntityId( EntityId $entityId, $role = null ) {
107
-		return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId );
106
+	public function withEntityId(EntityId $entityId, $role = null) {
107
+		return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId);
108 108
 	}
109 109
 
110 110
 	/**
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
 	 * @param string|null $role one of the Role::* constants
122 122
 	 * @return ViolationMessage
123 123
 	 */
124
-	public function withEntityIdList( array $entityIdList, $role = null ) {
125
-		return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList );
124
+	public function withEntityIdList(array $entityIdList, $role = null) {
125
+		return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList);
126 126
 	}
127 127
 
128 128
 }
Please login to merge, or discard this patch.