Skip to content
This repository
Browse code

Refactored exception codes.

  • Loading branch information...
commit f5c86e049695c433c5ec94230981c030522f7f5b 1 parent 6e6d5d3
Vasil Rangelov authored February 03, 2012
10  src/PEAR2/Net/RouterOS/Communicator.php
@@ -338,7 +338,7 @@ public function sendWordFromStream($prefix, $stream)
338 338
     {
339 339
         if (!self::isSeekableStream($stream)) {
340 340
             throw new InvalidArgumentException(
341  
-                'The stream must be seekable.', 10
  341
+                'The stream must be seekable.', 1100
342 342
             );
343 343
         }
344 344
         if (null !== ($remoteCharset = $this->getCharset(self::CHARSET_REMOTE))
@@ -389,7 +389,7 @@ protected static function verifyLengthSupport($length)
389 389
     {
390 390
         if ($length > 0xFFFFFFF) {
391 391
             throw new LengthException(
392  
-                'Words with length above 0xFFFFFFF are not supported.', 11,
  392
+                'Words with length above 0xFFFFFFF are not supported.', 1200,
393 393
                 null, $length
394 394
             );
395 395
         }
@@ -406,7 +406,7 @@ public static function encodeLength($length)
406 406
     {
407 407
         if ($length < 0) {
408 408
             throw new LengthException(
409  
-                'Length must not be negative.', 12, null, $length
  409
+                'Length must not be negative.', 1300, null, $length
410 410
             );
411 411
         } elseif ($length < 0x80) {
412 412
             return chr($length);
@@ -425,7 +425,7 @@ public static function encodeLength($length)
425 425
                 pack('N', hexdec(substr($length, 2)));
426 426
         }
427 427
         throw new LengthException(
428  
-            'Length must not be above 0x7FFFFFFFF.', 13, null, $length
  428
+            'Length must not be above 0x7FFFFFFFF.', 1301, null, $length
429 429
         );
430 430
     }
431 431
 
@@ -508,7 +508,7 @@ public static function decodeLength(T\Stream $trans)
508 508
                     + (double) sprintf('%u', $rem['~']);
509 509
             }
510 510
             throw new NotSupportedException(
511  
-                'Unknown control byte encountered.', 14, null, $byte
  511
+                'Unknown control byte encountered.', 1600, null, $byte
512 512
             );
513 513
         } else {
514 514
             return $byte;
2  src/PEAR2/Net/RouterOS/Message.php
@@ -78,7 +78,7 @@ public static function sanitizeArgumentName($name)
78 78
             || !preg_match('/[^=\s]/s', $name)
79 79
         ) {
80 80
             throw new InvalidArgumentException(
81  
-                'Invalid name of argument supplied.', 200
  81
+                'Invalid name of argument supplied.', 20100
82 82
             );
83 83
         }
84 84
         return $name;
4  src/PEAR2/Net/RouterOS/Query.php
@@ -92,7 +92,7 @@ protected static function sanitizeAction($action)
92 92
             return $action;
93 93
         default:
94 94
             throw new UnexpectedValueException(
95  
-                'Unknown action specified', 208, null, $action
  95
+                'Unknown action specified', 30100, null, $action
96 96
             );
97 97
         }
98 98
     }
@@ -171,7 +171,7 @@ public function send(Communicator $com)
171 171
     {
172 172
         if (!$com->getTransmitter()->isAcceptingData()) {
173 173
             throw new SocketException(
174  
-                'Transmitter is invalid. Sending aborted.', 209
  174
+                'Transmitter is invalid. Sending aborted.', 30600
175 175
             );
176 176
         }
177 177
         $bytes = 0;
13  src/PEAR2/Net/RouterOS/Request.php
@@ -116,7 +116,7 @@ public function setCommand($command)
116 116
         $command = (string) $command;
117 117
         if (strpos($command, '/') !== 0) {
118 118
             throw new InvalidArgumentException(
119  
-                'Commands must be absolute.', 202
  119
+                'Commands must be absolute.', 40200
120 120
             );
121 121
         }
122 122
         if (substr_count($command, '/') === 1) {
@@ -128,7 +128,7 @@ public function setCommand($command)
128 128
                     $delIndex = count($cmdRes) - 1;
129 129
                     if ($delIndex < 1) {
130 130
                         throw new InvalidArgumentException(
131  
-                            'Unable to resolve command', 203
  131
+                            'Unable to resolve command', 40201
132 132
                         );
133 133
                     }
134 134
                     unset($cmdRes[$delIndex]);
@@ -141,7 +141,7 @@ public function setCommand($command)
141 141
         }
142 142
         if (!preg_match('#^/\S+$#sm', $command)) {
143 143
             throw new InvalidArgumentException(
144  
-                'Invalid command supplied.', 204
  144
+                'Invalid command supplied.', 40202
145 145
             );
146 146
         }
147 147
         $this->_command = $command;
@@ -241,7 +241,7 @@ public function send(Communicator $com)
241 241
     {
242 242
         if (!$com->getTransmitter()->isAcceptingData()) {
243 243
             throw new SocketException(
244  
-                'Transmitter is invalid. Sending aborted.', 205
  244
+                'Transmitter is invalid. Sending aborted.', 40900
245 245
             );
246 246
         }
247 247
         $bytes = 0;
@@ -294,7 +294,8 @@ protected function parseArgumentString($string)
294 294
                     $name = $matches[1];
295 295
                 } else {
296 296
                     throw new InvalidArgumentException(
297  
-                        "Parsing of argument name failed near '{$string}'", 206
  297
+                        "Parsing of argument name failed near '{$string}'",
  298
+                        41000
298 299
                     );
299 300
                 }
300 301
             } elseif (preg_match('/^\s/sm', $string, $matches)) {
@@ -319,7 +320,7 @@ protected function parseArgumentString($string)
319 320
                 $name = null;
320 321
             } else {
321 322
                 throw new InvalidArgumentException(
322  
-                    "Parsing of argument value failed near '{$string}'", 207
  323
+                    "Parsing of argument value failed near '{$string}'", 41001
323 324
                 );
324 325
             }
325 326
         }
4  src/PEAR2/Net/RouterOS/Response.php
@@ -78,7 +78,7 @@ public function __construct(Communicator $com, $asStream = false)
78 78
     {
79 79
         if (!$com->getTransmitter()->isDataAwaiting()) {
80 80
             throw new SocketException(
81  
-                'No data awaiting. Receiving aborted.', 206
  81
+                'No data awaiting. Receiving aborted.', 50000
82 82
             );
83 83
         }
84 84
         $this->setType($com->getNextWord());
@@ -150,7 +150,7 @@ protected function setType($type)
150 150
             return $this;
151 151
         default:
152 152
             throw new UnexpectedValueException(
153  
-                'Unrecognized response type.', 207, null, $type
  153
+                'Unrecognized response type.', 50100, null, $type
154 154
             );
155 155
         }
156 156
     }
6  tests/ConnectionTest.php
@@ -302,7 +302,7 @@ public function testInvalidSocketOnClose()
302 302
             $this->fail('Receiving had to fail.');
303 303
         } catch (SocketException $e) {
304 304
             $this->assertEquals(
305  
-                206, $e->getCode(), 'Improper exception code.'
  305
+                50000, $e->getCode(), 'Improper exception code.'
306 306
             );
307 307
         }
308 308
     }
@@ -345,7 +345,9 @@ public function testInvalidQuerySending()
345 345
             $com->sendWord('');
346 346
             $this->fail('The query had to fail.');
347 347
         } catch (SocketException $e) {
348  
-            $this->assertEquals(209, $e->getCode(), 'Improper exception code.');
  348
+            $this->assertEquals(
  349
+                30600, $e->getCode(), 'Improper exception code.'
  350
+            );
349 351
         }
350 352
     }
351 353
 
30  tests/RequestHandlingTest.php
@@ -19,7 +19,7 @@ public function testNonAbsoluteCommand()
19 19
                 $invalidCommand = new Request($command);
20 20
             } catch (InvalidArgumentException $e) {
21 21
                 $this->assertEquals(
22  
-                    202, $e->getCode(),
  22
+                    40200, $e->getCode(),
23 23
                     "Improper exception thrown for the command '{$command}'."
24 24
                 );
25 25
             }
@@ -37,7 +37,7 @@ public function testUnresolvableCommand()
37 37
                 $invalidCommand = new Request($command);
38 38
             } catch (InvalidArgumentException $e) {
39 39
                 $this->assertEquals(
40  
-                    203, $e->getCode(),
  40
+                    40201, $e->getCode(),
41 41
                     "Improper exception thrown for the command '{$command}'."
42 42
                 );
43 43
             }
@@ -56,7 +56,7 @@ public function testInvalidCommand()
56 56
                 $invalidCommand = new Request($command);
57 57
             } catch (InvalidArgumentException $e) {
58 58
                 $this->assertEquals(
59  
-                    204, $e->getCode(),
  59
+                    40202, $e->getCode(),
60 60
                     "Improper exception thrown for the command '{$command}'."
61 61
                 );
62 62
             }
@@ -343,13 +343,17 @@ public function testCommandArgumentParsingExceptions()
343 343
             $request = new Request('/ip arp add comment="""');
344 344
             $this->fail('Command had to fail.');
345 345
         }catch(InvalidArgumentException $e) {
346  
-            $this->assertEquals(206, $e->getCode(), 'Improper exception code');
  346
+            $this->assertEquals(
  347
+                41000, $e->getCode(), 'Improper exception code'
  348
+            );
347 349
         }
348 350
         try {
349 351
             $request = new Request('/ip arp add comment= address=192.168.0.1');
350 352
             $this->fail('Command had to fail.');
351 353
         }catch(InvalidArgumentException $e) {
352  
-            $this->assertEquals(207, $e->getCode(), 'Improper exception code');
  354
+            $this->assertEquals(
  355
+                41001, $e->getCode(), 'Improper exception code'
  356
+            );
353 357
         }
354 358
     }
355 359
 
@@ -371,7 +375,7 @@ public function testInvalidArgumentName()
371 375
                 $request->setArgument($name);
372 376
             } catch (InvalidArgumentException $e) {
373 377
                 $this->assertEquals(
374  
-                    200, $e->getCode(),
  378
+                    20100, $e->getCode(),
375 379
                     "Improper exception thrown for the name '{$name}'."
376 380
                 );
377 381
             }
@@ -406,7 +410,7 @@ public function testInvalidQueryArgumentName()
406 410
                 $query = Query::where($name);
407 411
             } catch (InvalidArgumentException $e) {
408 412
                 $this->assertEquals(
409  
-                    200, $e->getCode(),
  413
+                    20100, $e->getCode(),
410 414
                     "Improper exception thrown for the name '{$name}'."
411 415
                 );
412 416
             }
@@ -432,7 +436,7 @@ public function testInvalidQueryArgumentAction()
432 436
                 $query = Query::where('address', null, $action);
433 437
             } catch (UnexpectedValueException $e) {
434 438
                 $this->assertEquals(
435  
-                    208, $e->getCode(),
  439
+                    30100, $e->getCode(),
436 440
                     "Improper exception thrown for the action '{$action}'."
437 441
                 );
438 442
                 $this->assertEquals($action, $e->getValue());
@@ -449,7 +453,9 @@ public function testNonSeekableCommunicatorWord()
449 453
             $com->sendWordFromStream('', $value);
450 454
             $this->fail('Call had to fail.');
451 455
         }catch(InvalidArgumentException $e) {
452  
-            $this->assertEquals(10, $e->getCode(), 'Improper exception code.');
  456
+            $this->assertEquals(
  457
+                1100, $e->getCode(), 'Improper exception code.'
  458
+            );
453 459
         }
454 460
     }
455 461
 
@@ -538,7 +544,7 @@ public function testLengthEncodingExceptions()
538 544
             Communicator::encodeLength($smallLength);
539 545
         } catch (LengthException $e) {
540 546
             $this->assertEquals(
541  
-                12, $e->getCode(),
  547
+                1300, $e->getCode(),
542 548
                 "Length '{$smallLength}' must not be encodable."
543 549
             );
544 550
             $this->assertEquals(
@@ -550,7 +556,7 @@ public function testLengthEncodingExceptions()
550 556
             Communicator::encodeLength($largeLength);
551 557
         } catch (LengthException $e) {
552 558
             $this->assertEquals(
553  
-                13, $e->getCode(),
  559
+                1301, $e->getCode(),
554 560
                 "Length '{$largeLength}' must not be encodable."
555 561
             );
556 562
             $this->assertEquals(
@@ -586,7 +592,7 @@ public function testControlByteException()
586 592
                 Communicator::decodeLength($trans);
587 593
             } catch (NotSupportedException $e) {
588 594
                 $this->assertEquals(
589  
-                    14, $e->getCode(), 'Improper exception code.'
  595
+                    1600, $e->getCode(), 'Improper exception code.'
590 596
                 );
591 597
                 $this->assertEquals(
592 598
                     $controlByte, $e->getValue(), 'Improper exception value.'
2  tests/StateAlteringFeaturesTest.php
@@ -259,7 +259,7 @@ public function testSendSyncReturningResponseLargeDataException()
259 259
             $this->fail('Lengths above 0xFFFFFFF should not be supported.');
260 260
         } catch (LengthException $e) {
261 261
             $this->assertEquals(
262  
-                11, $e->getCode(), 'Improper exception thrown.'
  262
+                1200, $e->getCode(), 'Improper exception thrown.'
263 263
             );
264 264
         }
265 265
 

0 notes on commit f5c86e0

Please sign in to comment.
Something went wrong with that request. Please try again.