Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored exception codes.

  • Loading branch information...
commit f5c86e049695c433c5ec94230981c030522f7f5b 1 parent 6e6d5d3
@boenrobot boenrobot authored
View
10 src/PEAR2/Net/RouterOS/Communicator.php
@@ -338,7 +338,7 @@ public function sendWordFromStream($prefix, $stream)
{
if (!self::isSeekableStream($stream)) {
throw new InvalidArgumentException(
- 'The stream must be seekable.', 10
+ 'The stream must be seekable.', 1100
);
}
if (null !== ($remoteCharset = $this->getCharset(self::CHARSET_REMOTE))
@@ -389,7 +389,7 @@ protected static function verifyLengthSupport($length)
{
if ($length > 0xFFFFFFF) {
throw new LengthException(
- 'Words with length above 0xFFFFFFF are not supported.', 11,
+ 'Words with length above 0xFFFFFFF are not supported.', 1200,
null, $length
);
}
@@ -406,7 +406,7 @@ public static function encodeLength($length)
{
if ($length < 0) {
throw new LengthException(
- 'Length must not be negative.', 12, null, $length
+ 'Length must not be negative.', 1300, null, $length
);
} elseif ($length < 0x80) {
return chr($length);
@@ -425,7 +425,7 @@ public static function encodeLength($length)
pack('N', hexdec(substr($length, 2)));
}
throw new LengthException(
- 'Length must not be above 0x7FFFFFFFF.', 13, null, $length
+ 'Length must not be above 0x7FFFFFFFF.', 1301, null, $length
);
}
@@ -508,7 +508,7 @@ public static function decodeLength(T\Stream $trans)
+ (double) sprintf('%u', $rem['~']);
}
throw new NotSupportedException(
- 'Unknown control byte encountered.', 14, null, $byte
+ 'Unknown control byte encountered.', 1600, null, $byte
);
} else {
return $byte;
View
2  src/PEAR2/Net/RouterOS/Message.php
@@ -78,7 +78,7 @@ public static function sanitizeArgumentName($name)
|| !preg_match('/[^=\s]/s', $name)
) {
throw new InvalidArgumentException(
- 'Invalid name of argument supplied.', 200
+ 'Invalid name of argument supplied.', 20100
);
}
return $name;
View
4 src/PEAR2/Net/RouterOS/Query.php
@@ -92,7 +92,7 @@ protected static function sanitizeAction($action)
return $action;
default:
throw new UnexpectedValueException(
- 'Unknown action specified', 208, null, $action
+ 'Unknown action specified', 30100, null, $action
);
}
}
@@ -171,7 +171,7 @@ public function send(Communicator $com)
{
if (!$com->getTransmitter()->isAcceptingData()) {
throw new SocketException(
- 'Transmitter is invalid. Sending aborted.', 209
+ 'Transmitter is invalid. Sending aborted.', 30600
);
}
$bytes = 0;
View
13 src/PEAR2/Net/RouterOS/Request.php
@@ -116,7 +116,7 @@ public function setCommand($command)
$command = (string) $command;
if (strpos($command, '/') !== 0) {
throw new InvalidArgumentException(
- 'Commands must be absolute.', 202
+ 'Commands must be absolute.', 40200
);
}
if (substr_count($command, '/') === 1) {
@@ -128,7 +128,7 @@ public function setCommand($command)
$delIndex = count($cmdRes) - 1;
if ($delIndex < 1) {
throw new InvalidArgumentException(
- 'Unable to resolve command', 203
+ 'Unable to resolve command', 40201
);
}
unset($cmdRes[$delIndex]);
@@ -141,7 +141,7 @@ public function setCommand($command)
}
if (!preg_match('#^/\S+$#sm', $command)) {
throw new InvalidArgumentException(
- 'Invalid command supplied.', 204
+ 'Invalid command supplied.', 40202
);
}
$this->_command = $command;
@@ -241,7 +241,7 @@ public function send(Communicator $com)
{
if (!$com->getTransmitter()->isAcceptingData()) {
throw new SocketException(
- 'Transmitter is invalid. Sending aborted.', 205
+ 'Transmitter is invalid. Sending aborted.', 40900
);
}
$bytes = 0;
@@ -294,7 +294,8 @@ protected function parseArgumentString($string)
$name = $matches[1];
} else {
throw new InvalidArgumentException(
- "Parsing of argument name failed near '{$string}'", 206
+ "Parsing of argument name failed near '{$string}'",
+ 41000
);
}
} elseif (preg_match('/^\s/sm', $string, $matches)) {
@@ -319,7 +320,7 @@ protected function parseArgumentString($string)
$name = null;
} else {
throw new InvalidArgumentException(
- "Parsing of argument value failed near '{$string}'", 207
+ "Parsing of argument value failed near '{$string}'", 41001
);
}
}
View
4 src/PEAR2/Net/RouterOS/Response.php
@@ -78,7 +78,7 @@ public function __construct(Communicator $com, $asStream = false)
{
if (!$com->getTransmitter()->isDataAwaiting()) {
throw new SocketException(
- 'No data awaiting. Receiving aborted.', 206
+ 'No data awaiting. Receiving aborted.', 50000
);
}
$this->setType($com->getNextWord());
@@ -150,7 +150,7 @@ protected function setType($type)
return $this;
default:
throw new UnexpectedValueException(
- 'Unrecognized response type.', 207, null, $type
+ 'Unrecognized response type.', 50100, null, $type
);
}
}
View
6 tests/ConnectionTest.php
@@ -302,7 +302,7 @@ public function testInvalidSocketOnClose()
$this->fail('Receiving had to fail.');
} catch (SocketException $e) {
$this->assertEquals(
- 206, $e->getCode(), 'Improper exception code.'
+ 50000, $e->getCode(), 'Improper exception code.'
);
}
}
@@ -345,7 +345,9 @@ public function testInvalidQuerySending()
$com->sendWord('');
$this->fail('The query had to fail.');
} catch (SocketException $e) {
- $this->assertEquals(209, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(
+ 30600, $e->getCode(), 'Improper exception code.'
+ );
}
}
View
30 tests/RequestHandlingTest.php
@@ -19,7 +19,7 @@ public function testNonAbsoluteCommand()
$invalidCommand = new Request($command);
} catch (InvalidArgumentException $e) {
$this->assertEquals(
- 202, $e->getCode(),
+ 40200, $e->getCode(),
"Improper exception thrown for the command '{$command}'."
);
}
@@ -37,7 +37,7 @@ public function testUnresolvableCommand()
$invalidCommand = new Request($command);
} catch (InvalidArgumentException $e) {
$this->assertEquals(
- 203, $e->getCode(),
+ 40201, $e->getCode(),
"Improper exception thrown for the command '{$command}'."
);
}
@@ -56,7 +56,7 @@ public function testInvalidCommand()
$invalidCommand = new Request($command);
} catch (InvalidArgumentException $e) {
$this->assertEquals(
- 204, $e->getCode(),
+ 40202, $e->getCode(),
"Improper exception thrown for the command '{$command}'."
);
}
@@ -343,13 +343,17 @@ public function testCommandArgumentParsingExceptions()
$request = new Request('/ip arp add comment="""');
$this->fail('Command had to fail.');
}catch(InvalidArgumentException $e) {
- $this->assertEquals(206, $e->getCode(), 'Improper exception code');
+ $this->assertEquals(
+ 41000, $e->getCode(), 'Improper exception code'
+ );
}
try {
$request = new Request('/ip arp add comment= address=192.168.0.1');
$this->fail('Command had to fail.');
}catch(InvalidArgumentException $e) {
- $this->assertEquals(207, $e->getCode(), 'Improper exception code');
+ $this->assertEquals(
+ 41001, $e->getCode(), 'Improper exception code'
+ );
}
}
@@ -371,7 +375,7 @@ public function testInvalidArgumentName()
$request->setArgument($name);
} catch (InvalidArgumentException $e) {
$this->assertEquals(
- 200, $e->getCode(),
+ 20100, $e->getCode(),
"Improper exception thrown for the name '{$name}'."
);
}
@@ -406,7 +410,7 @@ public function testInvalidQueryArgumentName()
$query = Query::where($name);
} catch (InvalidArgumentException $e) {
$this->assertEquals(
- 200, $e->getCode(),
+ 20100, $e->getCode(),
"Improper exception thrown for the name '{$name}'."
);
}
@@ -432,7 +436,7 @@ public function testInvalidQueryArgumentAction()
$query = Query::where('address', null, $action);
} catch (UnexpectedValueException $e) {
$this->assertEquals(
- 208, $e->getCode(),
+ 30100, $e->getCode(),
"Improper exception thrown for the action '{$action}'."
);
$this->assertEquals($action, $e->getValue());
@@ -449,7 +453,9 @@ public function testNonSeekableCommunicatorWord()
$com->sendWordFromStream('', $value);
$this->fail('Call had to fail.');
}catch(InvalidArgumentException $e) {
- $this->assertEquals(10, $e->getCode(), 'Improper exception code.');
+ $this->assertEquals(
+ 1100, $e->getCode(), 'Improper exception code.'
+ );
}
}
@@ -538,7 +544,7 @@ public function testLengthEncodingExceptions()
Communicator::encodeLength($smallLength);
} catch (LengthException $e) {
$this->assertEquals(
- 12, $e->getCode(),
+ 1300, $e->getCode(),
"Length '{$smallLength}' must not be encodable."
);
$this->assertEquals(
@@ -550,7 +556,7 @@ public function testLengthEncodingExceptions()
Communicator::encodeLength($largeLength);
} catch (LengthException $e) {
$this->assertEquals(
- 13, $e->getCode(),
+ 1301, $e->getCode(),
"Length '{$largeLength}' must not be encodable."
);
$this->assertEquals(
@@ -586,7 +592,7 @@ public function testControlByteException()
Communicator::decodeLength($trans);
} catch (NotSupportedException $e) {
$this->assertEquals(
- 14, $e->getCode(), 'Improper exception code.'
+ 1600, $e->getCode(), 'Improper exception code.'
);
$this->assertEquals(
$controlByte, $e->getValue(), 'Improper exception value.'
View
2  tests/StateAlteringFeaturesTest.php
@@ -259,7 +259,7 @@ public function testSendSyncReturningResponseLargeDataException()
$this->fail('Lengths above 0xFFFFFFF should not be supported.');
} catch (LengthException $e) {
$this->assertEquals(
- 11, $e->getCode(), 'Improper exception thrown.'
+ 1200, $e->getCode(), 'Improper exception thrown.'
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.