Skip to content

Commit 7132bed

Browse files
committed
Minor fixes and tweaks
1 parent 2f06322 commit 7132bed

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class Parser {
3737
private $aSizeUnits;
3838
private $iLineNo;
3939

40+
/**
41+
* Parser constructor.
42+
* Note that that iLineNo starts from 1 and not 0
43+
*
44+
* @param $sText
45+
* @param Settings|null $oParserSettings
46+
* @param int $iLineNo
47+
*/
4048
public function __construct($sText, Settings $oParserSettings = null, $iLineNo = 1) {
4149
$this->sText = $sText;
4250
$this->iCurrentPosition = 0;

lib/Sabberworm/CSS/Parsing/SourceException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class SourceException extends \Exception {
66
private $iLineNo;
77
public function __construct($sMessage, $iLineNo = 0) {
8-
$this->$iLineNo = $iLineNo;
8+
$this->iLineNo = $iLineNo;
99
if (!empty($iLineNo)) {
1010
$sMessage .= " [line no: $iLineNo]";
1111
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Sabberworm\CSS\RuleSet\DeclarationBlock;
99
use Sabberworm\CSS\Property\AtRule;
1010
use Sabberworm\CSS\Value\URL;
11-
use Sabberworm\CSS\Value\Color;
11+
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1212

1313
class ParserTest extends \PHPUnit_Framework_TestCase {
1414

@@ -481,7 +481,7 @@ function testLineNumbersParsing() {
481481
$aRules = $oDeclBlock->getRules();
482482
// Choose the 2nd one
483483
$oColor = $aRules[1]->getValue();
484-
$this->assertEquals($aRules[1]->getLineNo(), 27);
484+
$this->assertEquals(27, $aRules[1]->getLineNo());
485485

486486
foreach ($oColor->getColor() as $oSize) {
487487
$aActualColorLines[] = $oSize->getLineNo();
@@ -493,14 +493,15 @@ function testLineNumbersParsing() {
493493
}
494494

495495
/**
496-
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
496+
* @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException
497+
* Credit: This test by @sabberworm (from https://github.com/sabberworm/PHP-CSS-Parser/pull/105#issuecomment-229643910 )
497498
*/
498-
public function testUnexpectedTokenExceptionLineNo() {
499+
function testUnexpectedTokenExceptionLineNo() {
499500
$oParser = new Parser("\ntest: 1;", Settings::create()->beStrict());
500501
try {
501502
$oParser->parse();
502503
} catch (UnexpectedTokenException $e) {
503-
$this->assertSame($e->getLineNo(), 2);
504+
$this->assertSame(2, $e->getLineNo());
504505
throw $e;
505506
}
506507
}

0 commit comments

Comments
 (0)