Skip to content

Commit a010f9a

Browse files
authored
Merge pull request #206 from oliverklee/cleanup/type-annotations
Add some PHPDoc type annotations
2 parents 4ae4fd8 + a817a29 commit a010f9a

22 files changed

+271
-28
lines changed

lib/Sabberworm/CSS/CSSList/AtRuleBlockList.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,37 @@
88
* A BlockList constructed by an unknown @-rule. @media rules are rendered into AtRuleBlockList objects.
99
*/
1010
class AtRuleBlockList extends CSSBlockList implements AtRule {
11-
11+
/**
12+
* @var string
13+
*/
1214
private $sType;
15+
16+
/**
17+
* @var string
18+
*/
1319
private $sArgs;
1420

21+
/**
22+
* @param string $sType
23+
* @param string $sArgs
24+
* @param int $iLineNo
25+
*/
1526
public function __construct($sType, $sArgs = '', $iLineNo = 0) {
1627
parent::__construct($iLineNo);
1728
$this->sType = $sType;
1829
$this->sArgs = $sArgs;
1930
}
2031

32+
/**
33+
* @return string
34+
*/
2135
public function atRuleName() {
2236
return $this->sType;
2337
}
2438

39+
/**
40+
* @return string
41+
*/
2542
public function atRuleArgs() {
2643
return $this->sArgs;
2744
}
@@ -30,6 +47,9 @@ public function __toString() {
3047
return $this->render(new \Sabberworm\CSS\OutputFormat());
3148
}
3249

50+
/**
51+
* @return string
52+
*/
3353
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
3454
$sArgs = $this->sArgs;
3555
if($sArgs) {

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@
2525
* Also, it may contain Import and Charset objects stemming from @-rules.
2626
*/
2727
abstract class CSSList implements Renderable, Commentable {
28-
28+
/**
29+
* @var array
30+
*/
2931
protected $aComments;
32+
33+
/**
34+
* @var array<int, RuleSet|Import|Charset|CSSList>
35+
*/
3036
protected $aContents;
37+
38+
/**
39+
* @var int
40+
*/
3141
protected $iLineNo;
3242

43+
/**
44+
* @param int $iLineNo
45+
*/
3346
public function __construct($iLineNo = 0) {
3447
$this->aComments = array();
3548
$this->aContents = array();
@@ -195,7 +208,7 @@ public function getLineNo() {
195208
/**
196209
* Prepend item to list of contents.
197210
*
198-
* @param object $oItem Item.
211+
* @param RuleSet|Import|Charset|CSSList $oItem Item.
199212
*/
200213
public function prepend($oItem) {
201214
array_unshift($this->aContents, $oItem);
@@ -204,7 +217,7 @@ public function prepend($oItem) {
204217
/**
205218
* Append item to list of contents.
206219
*
207-
* @param object $oItem Item.
220+
* @param RuleSet|Import|Charset|CSSList $oItem Item.
208221
*/
209222
public function append($oItem) {
210223
$this->aContents[] = $oItem;
@@ -237,6 +250,7 @@ public function remove($oItemToRemove) {
237250

238251
/**
239252
* Replaces an item from the CSS list.
253+
*
240254
* @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
241255
*/
242256
public function replace($oOldItem, $mNewItem) {
@@ -254,7 +268,7 @@ public function replace($oOldItem, $mNewItem) {
254268

255269
/**
256270
* Set the contents.
257-
* @param array $aContents Objects to set as content.
271+
* @param array<int, RuleSet|Import|Charset|CSSList> $aContents Objects to set as content.
258272
*/
259273
public function setContents(array $aContents) {
260274
$this->aContents = array();
@@ -300,6 +314,9 @@ public function __toString() {
300314
return $this->render(new \Sabberworm\CSS\OutputFormat());
301315
}
302316

317+
/**
318+
* @return string
319+
*/
303320
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
304321
$sResult = '';
305322
$bIsFirst = true;
@@ -330,12 +347,15 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
330347

331348
return $sResult;
332349
}
333-
350+
334351
/**
335352
* Return true if the list can not be further outdented. Only important when rendering.
336353
*/
337354
public abstract function isRootList();
338355

356+
/**
357+
* @return array<int, RuleSet|Import|Charset|CSSList>
358+
*/
339359
public function getContents() {
340360
return $this->aContents;
341361
}

lib/Sabberworm/CSS/CSSList/Document.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ public function __construct($iLineNo = 0) {
1616
parent::__construct($iLineNo);
1717
}
1818

19+
/**
20+
* @param ParserState $oParserState
21+
*
22+
* @return Document
23+
*
24+
* @throws \Sabberworm\CSS\Parsing\SourceException
25+
*/
1926
public static function parse(ParserState $oParserState) {
2027
$oDocument = new Document($oParserState->currentLine());
2128
CSSList::parseList($oParserState, $oDocument);
@@ -95,7 +102,14 @@ public function createShorthands() {
95102
}
96103
}
97104

98-
// Override render() to make format argument optional
105+
106+
/**
107+
* Override render() to make format argument optional
108+
*
109+
* @param \Sabberworm\CSS\OutputFormat|null $oOutputFormat
110+
*
111+
* @return string
112+
*/
99113
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat = null) {
100114
if($oOutputFormat === null) {
101115
$oOutputFormat = new \Sabberworm\CSS\OutputFormat();

lib/Sabberworm/CSS/CSSList/KeyFrame.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
use Sabberworm\CSS\Property\AtRule;
66

77
class KeyFrame extends CSSList implements AtRule {
8-
8+
/**
9+
* @var string|null
10+
*/
911
private $vendorKeyFrame;
12+
13+
/**
14+
* @var string|null
15+
*/
1016
private $animationName;
1117

1218
public function __construct($iLineNo = 0) {
@@ -35,6 +41,11 @@ public function __toString() {
3541
return $this->render(new \Sabberworm\CSS\OutputFormat());
3642
}
3743

44+
/**
45+
* @param \Sabberworm\CSS\OutputFormat $oOutputFormat
46+
*
47+
* @return string
48+
*/
3849
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
3950
$sResult = "@{$this->vendorKeyFrame} {$this->animationName}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
4051
$sResult .= parent::render($oOutputFormat);
@@ -46,10 +57,16 @@ public function isRootList() {
4657
return false;
4758
}
4859

60+
/**
61+
* @return string|null
62+
*/
4963
public function atRuleName() {
5064
return $this->vendorKeyFrame;
5165
}
5266

67+
/**
68+
* @return string|null
69+
*/
5370
public function atRuleArgs() {
5471
return $this->animationName;
5572
}

lib/Sabberworm/CSS/Parser.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* Parser class parses CSS from text into a data structure.
1010
*/
1111
class Parser {
12+
/**
13+
* @var ParserState
14+
*/
1215
private $oParserState;
1316

1417
/**
@@ -34,8 +37,12 @@ public function getCharset() {
3437
$this->oParserState->getCharset();
3538
}
3639

40+
/**
41+
* @return Document
42+
*
43+
* @throws Parsing\SourceException
44+
*/
3745
public function parse() {
3846
return Document::parse($this->oParserState);
3947
}
40-
4148
}

lib/Sabberworm/CSS/Property/AtRule.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ interface AtRule extends Renderable, Commentable {
1010
const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values';
1111
// …and more font-specific ones (to be used inside font-feature-values)
1212
const SET_RULES = 'font-face/counter-style/page/swash/styleset/annotation';
13-
13+
14+
/**
15+
* @return string|null
16+
*/
1417
public function atRuleName();
18+
19+
/**
20+
* @return string|null
21+
*/
1522
public function atRuleArgs();
1623
}

lib/Sabberworm/CSS/Property/CSSNamespace.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CSSNamespace implements AtRule {
1010
private $sPrefix;
1111
private $iLineNo;
1212
protected $aComments;
13-
13+
1414
public function __construct($mUrl, $sPrefix = null, $iLineNo = 0) {
1515
$this->mUrl = $mUrl;
1616
$this->sPrefix = $sPrefix;
@@ -29,10 +29,15 @@ public function __toString() {
2929
return $this->render(new \Sabberworm\CSS\OutputFormat());
3030
}
3131

32+
/**
33+
* @param \Sabberworm\CSS\OutputFormat $oOutputFormat
34+
*
35+
* @return string
36+
*/
3237
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
3338
return '@namespace '.($this->sPrefix === null ? '' : $this->sPrefix.' ').$this->mUrl->render($oOutputFormat).';';
3439
}
35-
40+
3641
public function getUrl() {
3742
return $this->mUrl;
3843
}
@@ -49,10 +54,16 @@ public function setPrefix($sPrefix) {
4954
$this->sPrefix = $sPrefix;
5055
}
5156

57+
/**
58+
* @return string
59+
*/
5260
public function atRuleName() {
5361
return 'namespace';
5462
}
5563

64+
/**
65+
* @return array<int, string>
66+
*/
5667
public function atRuleArgs() {
5768
$aResult = array($this->mUrl);
5869
if($this->sPrefix) {

lib/Sabberworm/CSS/Property/Charset.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@
1010
* • Must not appear more than once.
1111
*/
1212
class Charset implements AtRule {
13-
13+
/**
14+
* @var string
15+
*/
1416
private $sCharset;
17+
18+
/**
19+
* @var int
20+
*/
1521
protected $iLineNo;
22+
23+
/**
24+
* @var array
25+
*/
1626
protected $aComment;
1727

28+
/**
29+
* @param string $sCharset
30+
* @param int $iLineNo
31+
*/
1832
public function __construct($sCharset, $iLineNo = 0) {
1933
$this->sCharset = $sCharset;
2034
$this->iLineNo = $iLineNo;
@@ -40,14 +54,25 @@ public function __toString() {
4054
return $this->render(new \Sabberworm\CSS\OutputFormat());
4155
}
4256

57+
/**
58+
* @param \Sabberworm\CSS\OutputFormat $oOutputFormat
59+
*
60+
* @return string
61+
*/
4362
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
4463
return "@charset {$this->sCharset->render($oOutputFormat)};";
4564
}
4665

66+
/**
67+
* @return string
68+
*/
4769
public function atRuleName() {
4870
return 'charset';
4971
}
5072

73+
/**
74+
* @return string
75+
*/
5176
public function atRuleArgs() {
5277
return $this->sCharset;
5378
}
@@ -63,4 +88,4 @@ public function getComments() {
6388
public function setComments(array $aComments) {
6489
$this->aComments = $aComments;
6590
}
66-
}
91+
}

0 commit comments

Comments
 (0)