Skip to content

Commit 944cdd0

Browse files
committed
[REFACTOR] Add Types
1 parent 65226ac commit 944cdd0

File tree

14 files changed

+79
-79
lines changed

14 files changed

+79
-79
lines changed

src/PhpCss.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@
1414
abstract class PhpCss {
1515

1616
/**
17-
* Parses a css selector and compiles it into an css selector again
18-
*
19-
* @param string $cssSelector
20-
* @return string
21-
*/
22-
public static function reformat($cssSelector) {
17+
* Parses a css selector and compiles it into an css selector again
18+
*
19+
* @param string $cssSelector
20+
* @return string
21+
* @throws ParserException
22+
*/
23+
public static function reformat(string $cssSelector): string {
2324
$ast = self::getAst($cssSelector);
2425
$visitor = new PhpCss\Ast\Visitor\Css();
2526
$ast->accept($visitor);
2627
return (string)$visitor;
2728
}
2829

2930
/**
30-
* Parses a css selector and transforms it into an xpath expression
31-
*
32-
* @param string $cssSelector
33-
* @param int $options
34-
* @return string
35-
*/
36-
public static function toXpath($cssSelector, $options = 0) {
31+
* Parses a css selector and transforms it into an xpath expression
32+
*
33+
* @param string $cssSelector
34+
* @param int $options
35+
* @return string
36+
* @throws ParserException
37+
*/
38+
public static function toXpath(string $cssSelector, int $options = 0): string {
3739
$ast = self::getAst($cssSelector);
3840
$visitor = new PhpCss\Ast\Visitor\Xpath($options);
3941
$ast->accept($visitor);

src/PhpCss/Ast/Selector/Group.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
namespace PhpCss\Ast\Selector {
1010

11+
use ArrayAccess;
12+
use ArrayIterator;
13+
use Countable;
1114
use InvalidArgumentException;
15+
use IteratorAggregate;
1216
use PhpCss\Ast;
1317

1418
/**
@@ -25,7 +29,7 @@
2529
*/
2630
class Group
2731
extends Ast\Selector
28-
implements \ArrayAccess, \Countable, \IteratorAggregate {
32+
implements ArrayAccess, Countable, IteratorAggregate {
2933

3034
private $_sequences = [];
3135

@@ -113,11 +117,11 @@ public function count(): int {
113117
/**
114118
* Return an iterator for the sequences
115119
*
116-
* @return \Traversable
120+
* @return ArrayIterator
117121
* @see IteratorAggregate::getIterator()
118122
*/
119-
public function getIterator() {
120-
return new \ArrayIterator($this->_sequences);
123+
public function getIterator(): ArrayIterator {
124+
return new ArrayIterator($this->_sequences);
121125
}
122126

123127
/**

src/PhpCss/Ast/Selector/Sequence.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
class Sequence extends Ast\Selector {
88

99
/**
10-
* @var array(Simple)
10+
* @var Simple[]
1111
*/
1212
public $simples = [];
13-
public $combinator = NULL;
13+
public $combinator;
1414

1515
/**
1616
* @param Simple[] $simples
@@ -30,9 +30,6 @@ public function __construct(array $simples = [], Combinator $combinator = NULL)
3030
public function accept(Ast\Visitor $visitor): void {
3131
if ($visitor->visitEnter($this)) {
3232
foreach ($this->simples as $simple) {
33-
/**
34-
* @var Simple $simple
35-
*/
3633
$simple->accept($visitor);
3734
}
3835
if (isset($this->combinator)) {

src/PhpCss/Ast/Selector/Simple/PseudoClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class PseudoClass extends Ast\Selector\Simple {
88

99
public $name = '';
10-
public $parameter = NULL;
10+
public $parameter;
1111

1212
public function __construct(string $name, Ast\Node $parameter = NULL) {
1313
$this->name = $name;

src/PhpCss/Ast/Visitor/Explain.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
use DOMDocument;
1313
use DOMElement;
14-
use DOMNode;
15-
use LogicException;
1614
use PhpCss\Ast;
1715

1816
/**
@@ -25,12 +23,12 @@ class Explain extends Overload {
2523
/**
2624
* @var DOMDocument
2725
*/
28-
private $_document = NULL;
26+
private $_document;
2927

3028
/**
31-
* @var DOMElement
29+
* @var DOMElement|DOMDocument
3230
*/
33-
private $_current = NULL;
31+
private $_current;
3432

3533
public function __construct() {
3634
$this->clear();
@@ -51,15 +49,16 @@ public function __toString() {
5149
}
5250

5351
/**
54-
* @param $name
52+
* @param string $name
5553
* @param string $content
5654
* @param array $attributes
57-
* @return DOMNode
55+
* @param string $contentType
56+
* @return DOMElement
5857
*/
5958
private function appendElement(
60-
$name, $content = '', array $attributes = [], $contentType = 'text'
61-
): DOMNode {
62-
$result = $this->_document->createElementNs($this->_xmlns, $name);
59+
string $name, string $content = '', array $attributes = [], string $contentType = 'text'
60+
): DOMElement {
61+
$result = $this->_document->createElementNS($this->_xmlns, $name);
6362
if (!empty($content)) {
6463
$text = $result->appendChild(
6564
$this->_document->createElementNs($this->_xmlns, $contentType)
@@ -82,10 +81,9 @@ private function appendElement(
8281
}
8382

8483
/**
85-
* @param $content
86-
* @return DOMNode
84+
* @param string $content
8785
*/
88-
private function appendText($content): DOMNode {
86+
private function appendText(string $content): void {
8987
$text = $this->_current->appendChild(
9088
$this->_document->createElementNs($this->_xmlns, 'text')
9189
);
@@ -98,7 +96,6 @@ private function appendText($content): DOMNode {
9896
$this->_document->createTextNode($content)
9997
);
10098
}
101-
return $text;
10299
}
103100

104101
/**
@@ -128,7 +125,6 @@ private function end(): bool {
128125
* If the buffer already contains data, throw an exception.
129126
*
130127
* @return boolean
131-
* @throws LogicException
132128
*/
133129
public function visitEnterSelectorGroup(): bool {
134130
$this->start($this->appendElement('selector-group'));

src/PhpCss/Exception/InvalidCharacterException.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@
1111
namespace PhpCss\Exception {
1212

1313
use PhpCss;
14+
use PhpCss\Scanner\Status;
15+
use UnexpectedValueException;
1416

1517
/**
1618
* Exception thrown if a scanner status finds does not
1719
* find a valid character.
1820
*/
1921
class InvalidCharacterException
20-
extends \UnexpectedValueException
22+
extends UnexpectedValueException
2123
implements PhpCssException {
2224

2325
/** @var int $offset byte offset */
24-
private $_offset = 0;
26+
private $_offset;
2527
/** @var string $buffer string buffer */
26-
private $_buffer = '';
27-
/** @var PhpCss\Scanner\Status $status scanner status */
28-
private $_status = '';
28+
private $_buffer;
29+
/** @var Status $status scanner status */
30+
private $_status;
2931

3032
/**
3133
* @param string $buffer
3234
* @param int $offset
33-
* @param \PhpCss\Scanner\Status $status
35+
* @param Status $status
3436
*/
35-
public function __construct($buffer, $offset, $status) {
37+
public function __construct(string $buffer, int $offset, Status $status) {
3638
$this->_buffer = $buffer;
3739
$this->_offset = $offset;
3840
$this->_status = $status;
@@ -52,22 +54,22 @@ public function __construct($buffer, $offset, $status) {
5254
*
5355
* @return string
5456
*/
55-
public function getChar() {
57+
public function getChar(): string {
5658
if (preg_match('(.)suS', $this->_buffer, $match, 0, $this->_offset)) {
5759
return $match[0];
5860
}
5961
return '';
6062
}
6163

62-
public function getOffset() {
64+
public function getOffset(): int {
6365
return $this->_offset;
6466
}
6567

66-
public function getBuffer() {
68+
public function getBuffer(): string {
6769
return $this->_buffer;
6870
}
6971

70-
public function getStatus() {
72+
public function getStatus(): Status {
7173
return $this->_status;
7274
}
7375
}

src/PhpCss/Exception/NotConvertibleException.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88

99
namespace PhpCss\Exception {
1010

11+
use Exception;
1112
use PhpCss;
1213

1314
/**
1415
* Exception thrown if a visitor finds something that it can not use.
1516
*/
1617
class NotConvertibleException
17-
extends \Exception
18+
extends Exception
1819
implements PhpCssException {
1920

20-
public function __construct($token, $target) {
21+
public function __construct(string $source, string $target) {
2122
parent::__construct(
2223
sprintf(
23-
'Can not convert %s to %s.', (string)$token, (string)$target
24+
'Can not convert %s to %s.', $source, $target
2425
)
2526
);
2627
}

src/PhpCss/Exception/ParserException.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
<?php
22
/**
3-
* Exception thrown if a parse error occurs
4-
*
5-
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
6-
* @copyright Copyright 2010-2014 PhpCss Team
7-
*/
3+
* Exception thrown if a parse error occurs
4+
*
5+
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
6+
* @copyright Copyright 2010-2014 PhpCss Team
7+
*/
88

99
namespace PhpCss\Exception {
1010

11+
use Exception;
1112
use PhpCss;
1213

1314
/**
14-
* Exception thrown if a parse error occurs
15-
*
16-
* A parse error occurs if certain tokens are expected for further parsing, but
17-
* none of them are found on the token stream
18-
*/
19-
abstract class ParserException extends \Exception implements PhpCssException {
15+
* Exception thrown if a parse error occurs
16+
*
17+
* A parse error occurs if certain tokens are expected for further parsing, but
18+
* none of them are found on the token stream
19+
*/
20+
abstract class ParserException extends Exception implements PhpCssException {
2021

2122
/**
22-
* An array of tokens which would have been expected to be found.
23-
*
24-
* @var array(PhpCss\Scanner\Token)
25-
*/
26-
protected $_expectedTokens = array();
23+
* An array of tokens which would have been expected to be found.
24+
*
25+
* @var array(PhpCss\Scanner\Token)
26+
*/
27+
protected $_expectedTokens = [];
2728

28-
public function getExpected() {
29+
public function getExpected(): array {
2930
return $this->_expectedTokens;
3031
}
3132
}

src/PhpCss/Exception/TokenException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class TokenException extends ParserException {
2828
*/
2929
protected $_encounteredToken;
3030

31-
public function __construct(PhpCss\Scanner\Token $token, $message) {
31+
public function __construct(PhpCss\Scanner\Token $token, string $message) {
3232
$this->_encounteredToken = $token;
3333
parent::__construct($message);
3434
}
@@ -38,7 +38,7 @@ public function __construct(PhpCss\Scanner\Token $token, $message) {
3838
*
3939
* @return PhpCss\Scanner\Token
4040
*/
41-
public function getToken() {
41+
public function getToken(): PhpCss\Scanner\Token {
4242
return $this->_encounteredToken;
4343
}
4444
}

src/PhpCss/Exception/TokenMismatchException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(PhpCss\Scanner\Token $encounteredToken, array $expec
2929

3030
parent::__construct(
3131
$encounteredToken,
32-
'Parse error: Found '.(string)$encounteredToken .
32+
'Parse error: Found '. $encounteredToken .
3333
' while one of '.implode(", ", $expectedTokenStrings).' was expected.'
3434
);
3535
}

0 commit comments

Comments
 (0)