Completed
Push — master ( 82a3c0...fec4dc )
by
unknown
04:07
created
src/ConstraintCheck/Checker/AllowedUnitsChecker.php 1 patch
Spacing   +31 added lines, -32 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @throws ConstraintParameterException
76 76
 	 * @return CheckResult
77 77
 	 */
78
-	public function checkConstraint( Context $context, Constraint $constraint ) {
78
+	public function checkConstraint(Context $context, Constraint $constraint) {
79 79
 		$parameters = [];
80 80
 		$constraintParameters = $constraint->getConstraintParameters();
81 81
 		$unitsParameter = $this->constraintParameterParser
@@ -85,45 +85,44 @@  discard block
 block discarded – undo
85 85
 			);
86 86
 
87 87
 		$snak = $context->getSnak();
88
-		if ( !$snak instanceof PropertyValueSnak ) {
88
+		if (!$snak instanceof PropertyValueSnak) {
89 89
 			// nothing to check
90
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
90
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
91 91
 		}
92 92
 
93 93
 		$dataValue = $snak->getDataValue();
94
-		if ( !$dataValue instanceof UnboundedQuantityValue ) {
95
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
96
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
97
-				->withDataValueType( 'quantity' );
98
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
94
+		if (!$dataValue instanceof UnboundedQuantityValue) {
95
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
96
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
97
+				->withDataValueType('quantity');
98
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
99 99
 		}
100 100
 
101
-		if ( $dataValue->getUnit() === '1' ) {
102
-			return $this->checkUnitless( $context, $constraint, $unitsParameter, $snak );
101
+		if ($dataValue->getUnit() === '1') {
102
+			return $this->checkUnitless($context, $constraint, $unitsParameter, $snak);
103 103
 		}
104 104
 
105 105
 		$status = CheckResult::STATUS_VIOLATION;
106
-		$actualUnit = $this->standardize( $dataValue )->getUnit();
107
-		foreach ( $unitsParameter->getUnitQuantities() as $unitQuantity ) {
108
-			$allowedUnit = $this->standardize( $unitQuantity )->getUnit();
109
-			if ( $actualUnit === $allowedUnit ) {
106
+		$actualUnit = $this->standardize($dataValue)->getUnit();
107
+		foreach ($unitsParameter->getUnitQuantities() as $unitQuantity) {
108
+			$allowedUnit = $this->standardize($unitQuantity)->getUnit();
109
+			if ($actualUnit === $allowedUnit) {
110 110
 				$status = CheckResult::STATUS_COMPLIANCE;
111 111
 				break;
112 112
 			}
113 113
 		}
114 114
 
115
-		if ( $status === CheckResult::STATUS_VIOLATION ) {
115
+		if ($status === CheckResult::STATUS_VIOLATION) {
116 116
 			$messageKey = $unitsParameter->getUnitlessAllowed() ?
117
-				'wbqc-violation-message-units-or-none' :
118
-				'wbqc-violation-message-units';
119
-			$message = ( new ViolationMessage( $messageKey ) )
120
-				->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY )
121
-				->withEntityIdList( $unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE );
117
+				'wbqc-violation-message-units-or-none' : 'wbqc-violation-message-units';
118
+			$message = (new ViolationMessage($messageKey))
119
+				->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY)
120
+				->withEntityIdList($unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE);
122 121
 		} else {
123 122
 			$message = null;
124 123
 		}
125 124
 
126
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
125
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
127 126
 	}
128 127
 
129 128
 	/**
@@ -139,17 +138,17 @@  discard block
 block discarded – undo
139 138
 		UnitsParameter $unitsParameter,
140 139
 		PropertyValueSnak $snak
141 140
 	) {
142
-		if ( $unitsParameter->getUnitlessAllowed() ) {
141
+		if ($unitsParameter->getUnitlessAllowed()) {
143 142
 			$message = null;
144 143
 			$status = CheckResult::STATUS_COMPLIANCE;
145 144
 		} else {
146
-			$message = ( new ViolationMessage( 'wbqc-violation-message-units' ) )
147
-				->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY )
148
-				->withEntityIdList( $unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE );
145
+			$message = (new ViolationMessage('wbqc-violation-message-units'))
146
+				->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY)
147
+				->withEntityIdList($unitsParameter->getUnitItemIds(), Role::CONSTRAINT_PARAMETER_VALUE);
149 148
 			$status = CheckResult::STATUS_VIOLATION;
150 149
 		}
151 150
 
152
-		return new CheckResult( $context, $constraint, [], $status, $message );
151
+		return new CheckResult($context, $constraint, [], $status, $message);
153 152
 	}
154 153
 
155 154
 	/**
@@ -158,20 +157,20 @@  discard block
 block discarded – undo
158 157
 	 * @param UnboundedQuantityValue $value
159 158
 	 * @return UnboundedQuantityValue
160 159
 	 */
161
-	private function standardize( UnboundedQuantityValue $value ) {
162
-		if ( $this->unitConverter === null ) {
160
+	private function standardize(UnboundedQuantityValue $value) {
161
+		if ($this->unitConverter === null) {
163 162
 			return $value;
164 163
 		}
165 164
 
166
-		$standard = $this->unitConverter->toStandardUnits( $value );
167
-		if ( $standard !== null ) {
165
+		$standard = $this->unitConverter->toStandardUnits($value);
166
+		if ($standard !== null) {
168 167
 			return $standard;
169 168
 		} else {
170 169
 			return $value;
171 170
 		}
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 {
@@ -180,7 +179,7 @@  discard block
 block discarded – undo
180 179
 				$constraint->getConstraintTypeItemId(),
181 180
 				true
182 181
 			);
183
-		} catch ( ConstraintParameterException $e ) {
182
+		} catch (ConstraintParameterException $e) {
184 183
 			$exceptions[] = $e;
185 184
 		}
186 185
 		return $exceptions;
Please login to merge, or discard this patch.