Skip to content

Add type annotations for the parsing exception classes #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Parsing/OutputException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace Sabberworm\CSS\Parsing;

/**
* Thrown if the CSS parsers attempts to print something invalid
* Thrown if the CSS parser attempts to print something invalid.
*/
class OutputException extends SourceException
{
/**
* @param string $sMessage
* @param int $iLineNo
*/
public function __construct($sMessage, $iLineNo = 0)
{
parent::__construct($sMessage, $iLineNo);
Expand Down
10 changes: 10 additions & 0 deletions src/Parsing/SourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

class SourceException extends \Exception
{
/**
* @var int
*/
private $iLineNo;

/**
* @param string $sMessage
* @param int $iLineNo
*/
public function __construct($sMessage, $iLineNo = 0)
{
$this->iLineNo = $iLineNo;
Expand All @@ -15,6 +22,9 @@ public function __construct($sMessage, $iLineNo = 0)
parent::__construct($sMessage);
}

/**
* @return int
*/
public function getLineNo()
{
return $this->iLineNo;
Expand Down
5 changes: 3 additions & 2 deletions src/Parsing/UnexpectedEOFException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Sabberworm\CSS\Parsing;

/**
* Thrown if the CSS parsers encounters end of file it did not expect
* Extends UnexpectedTokenException in order to preserve backwards compatibility
* Thrown if the CSS parser encounters end of file it did not expect.
*
* Extends `UnexpectedTokenException` in order to preserve backwards compatibility.
*/
class UnexpectedEOFException extends UnexpectedTokenException
{
Expand Down
20 changes: 18 additions & 2 deletions src/Parsing/UnexpectedTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@
namespace Sabberworm\CSS\Parsing;

/**
* Thrown if the CSS parsers encounters a token it did not expect
* Thrown if the CSS parser encounters a token it did not expect.
*/
class UnexpectedTokenException extends SourceException
{
/**
* @var string
*/
private $sExpected;

/**
* @var string
*/
private $sFound;

// Possible values: literal, identifier, count, expression, search
/**
* Possible values: literal, identifier, count, expression, search
*
* @var string
*/
private $sMatchType;

/**
* @param string $sExpected
* @param string $sFound
* @param string $sMatchType
* @param int $iLineNo
*/
public function __construct($sExpected, $sFound, $sMatchType = 'literal', $iLineNo = 0)
{
$this->sExpected = $sExpected;
Expand Down