Skip to content

Commit 1c572eb

Browse files
committed
Add new class SourceException that is the parent exception class for all custom exceptions
1 parent 82dcd54 commit 1c572eb

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

lib/Sabberworm/CSS/Parsing/OutputException.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@
55
/**
66
* Thrown if the CSS parsers attempts to print something invalid
77
*/
8-
class OutputException extends \Exception {
9-
private $iLineNo;
8+
class OutputException extends SourceException {
109
public function __construct($sMessage, $iLineNo = 0) {
11-
$this->$iLineNo = $iLineNo;
12-
if (!empty($iLineNo)) {
13-
$sMessage .= " [line no: $iLineNo]";
14-
}
15-
parent::__construct($sMessage);
16-
}
17-
18-
public function getLineNo() {
19-
return $this->iLineNo;
10+
parent::__construct($sMessage, $iLineNo);
2011
}
2112
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\Parsing;
4+
5+
class SourceException extends \Exception {
6+
private $iLineNo;
7+
public function __construct($sMessage, $iLineNo = 0) {
8+
$this->$iLineNo = $iLineNo;
9+
if (!empty($iLineNo)) {
10+
$sMessage .= " [line no: $iLineNo]";
11+
}
12+
parent::__construct($sMessage);
13+
}
14+
15+
public function getLineNo() {
16+
return $this->iLineNo;
17+
}
18+
}

lib/Sabberworm/CSS/Parsing/UnexpectedTokenException.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Thrown if the CSS parsers encounters a token it did not expect
77
*/
8-
class UnexpectedTokenException extends \Exception {
8+
class UnexpectedTokenException extends SourceException {
99
private $sExpected;
1010
private $sFound;
1111
// Possible values: literal, identifier, count, expression, search
@@ -28,11 +28,7 @@ public function __construct($sExpected, $sFound, $sMatchType = 'literal', $iLine
2828
$sMessage = trim("$sExpected $sFound");
2929
}
3030

31-
if (!empty($iLineNo)) {
32-
$sMessage .= " [line no: $iLineNo]";
33-
}
34-
35-
parent::__construct($sMessage);
31+
parent::__construct($sMessage, $iLineNo);
3632
}
3733

3834
public function getLineNo() {

0 commit comments

Comments
 (0)