Skip to content

Commit f908f75

Browse files
committed
cleanup
1 parent 37bb2a2 commit f908f75

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/Schema.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private function process($data, $import = true, $path = '#')
124124
}
125125
}
126126
if (!$enumOk) {
127-
throw new EnumException('Enum failed ' . $path);
127+
$this->fail(new EnumException('Enum failed'), $path);
128128
}
129129
}
130130

@@ -135,7 +135,7 @@ private function process($data, $import = true, $path = '#')
135135
} catch (InvalidValue $exception) {
136136
}
137137
if ($exception === false) {
138-
throw new LogicException('Failed due to logical constraint: not ' . $path);
138+
$this->fail(new LogicException('Failed due to logical constraint: not'), $path);
139139
}
140140
}
141141

@@ -152,7 +152,7 @@ private function process($data, $import = true, $path = '#')
152152
}
153153
}
154154
if ($successes !== 1) {
155-
throw new LogicException('Failed due to logical constraint: oneOf ' . $path);
155+
$this->fail(new LogicException('Failed due to logical constraint: oneOf'), $path);
156156
}
157157
}
158158

@@ -169,7 +169,7 @@ private function process($data, $import = true, $path = '#')
169169
}
170170
}
171171
if (!$successes) {
172-
throw new LogicException('Failed due to logical constraint: anyOf ' . $path);
172+
$this->fail(new LogicException('Failed due to logical constraint: anyOf'), $path);
173173
}
174174
}
175175

@@ -183,18 +183,18 @@ private function process($data, $import = true, $path = '#')
183183
if (is_string($data)) {
184184
if ($this->minLength !== null) {
185185
if (mb_strlen($data) < $this->minLength) {
186-
throw new StringException('String is too short ' . $path, StringException::TOO_SHORT);
186+
$this->fail(new StringException('String is too short', StringException::TOO_SHORT), $path);
187187
}
188188
}
189189
if ($this->maxLength !== null) {
190190
if (mb_strlen($data) > $this->maxLength) {
191-
throw new StringException('String is too long ' . $path, StringException::TOO_LONG);
191+
$this->fail(new StringException('String is too long', StringException::TOO_LONG), $path);
192192
}
193193
}
194194
if ($this->pattern !== null) {
195195
if (0 === preg_match($this->pattern, $data)) {
196-
throw new StringException('Does not match to ' . $this->pattern . ' ' . $path,
197-
StringException::PATTERN_MISMATCH);
196+
$this->fail(new StringException('Does not match to '
197+
. $this->pattern, StringException::PATTERN_MISMATCH), $path);
198198
}
199199
}
200200
}
@@ -203,31 +203,30 @@ private function process($data, $import = true, $path = '#')
203203
if ($this->multipleOf !== null) {
204204
$div = $data / $this->multipleOf;
205205
if ($div != (int)$div) {
206-
throw new NumericException($data . ' is not multiple of ' . $this->multipleOf . ' ' . $path,
207-
NumericException::MULTIPLE_OF);
206+
$this->fail(new NumericException($data . ' is not multiple of ' . $this->multipleOf, NumericException::MULTIPLE_OF), $path);
208207
}
209208
}
210209

211210
if ($this->maximum !== null) {
212211
if ($this->exclusiveMaximum === true) {
213212
if ($data >= $this->maximum) {
214-
throw new NumericException('Maximum value exceeded ' . $path, NumericException::MAXIMUM);
213+
$this->fail(new NumericException('Maximum value exceeded', NumericException::MAXIMUM), $path);
215214
}
216215
} else {
217216
if ($data > $this->maximum) {
218-
throw new NumericException('Maximum value exceeded ' . $path, NumericException::MAXIMUM);
217+
$this->fail(new NumericException('Maximum value exceeded', NumericException::MAXIMUM), $path);
219218
}
220219
}
221220
}
222221

223222
if ($this->minimum !== null) {
224223
if ($this->exclusiveMinimum === true) {
225224
if ($data <= $this->minimum) {
226-
throw new NumericException('Minimum value exceeded ' . $path, NumericException::MINIMUM);
225+
$this->fail(new NumericException('Minimum value exceeded', NumericException::MINIMUM), $path);
227226
}
228227
} else {
229228
if ($data < $this->minimum) {
230-
throw new NumericException('Minimum value exceeded ' . $path, NumericException::MINIMUM);
229+
$this->fail(new NumericException('Minimum value exceeded', NumericException::MINIMUM), $path);
231230
}
232231
}
233232
}
@@ -239,8 +238,7 @@ private function process($data, $import = true, $path = '#')
239238
if ($this->required !== null) {
240239
foreach ($this->required as $item) {
241240
if (!property_exists($data, $item)) {
242-
throw new ObjectException('Required property missing: ' . $item . ' ' . $path,
243-
ObjectException::REQUIRED);
241+
$this->fail(new ObjectException('Required property missing: ' . $item, ObjectException::REQUIRED), $path);
244242
}
245243
}
246244
}
@@ -256,10 +254,10 @@ private function process($data, $import = true, $path = '#')
256254

257255
$array = (array)$data;
258256
if ($this->minProperties !== null && count($array) < $this->minProperties) {
259-
throw new ObjectException("Not enough properties " . $path, ObjectException::TOO_FEW);
257+
$this->fail(new ObjectException("Not enough properties", ObjectException::TOO_FEW), $path);
260258
}
261259
if ($this->maxProperties !== null && count($array) > $this->maxProperties) {
262-
throw new ObjectException("Too many properties " . $path, ObjectException::TOO_MANY);
260+
$this->fail(new ObjectException("Too many properties", ObjectException::TOO_MANY), $path);
263261
}
264262
foreach ($array as $key => $value) {
265263
$found = false;
@@ -270,8 +268,7 @@ private function process($data, $import = true, $path = '#')
270268
} else {
271269
foreach ($dependencies as $item) {
272270
if (!property_exists($data, $item)) {
273-
throw new ObjectException('Dependency property missing: ' . $item . ' ' . $path,
274-
ObjectException::DEPENDENCY_MISSING);
271+
$this->fail(new ObjectException('Dependency property missing: ' . $item, ObjectException::DEPENDENCY_MISSING), $path);
275272
}
276273
}
277274
}

0 commit comments

Comments
 (0)