Skip to content

Commit 1218187

Browse files
authored
Merge pull request #304 from oliverklee/task/types/document
Add type annotations for `Document`
2 parents 8712c13 + 753e275 commit 1218187

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

src/CSSList/CSSBlockList.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Sabberworm\CSS\RuleSet\DeclarationBlock;
88
use Sabberworm\CSS\RuleSet\RuleSet;
99
use Sabberworm\CSS\Value\CSSFunction;
10-
use Sabberworm\CSS\Value\CSSString;
1110
use Sabberworm\CSS\Value\Value;
1211
use Sabberworm\CSS\Value\ValueList;
1312

@@ -61,7 +60,7 @@ protected function allRuleSets(array &$aResult)
6160

6261
/**
6362
* @param CSSList|Rule|RuleSet|Value $oElement
64-
* @param array<int, Value|CSSString> $aResult
63+
* @param array<int, Value> $aResult
6564
* @param string|null $sSearchString
6665
* @param bool $bSearchInFunctionArguments
6766
*
@@ -86,13 +85,13 @@ protected function allValues($oElement, array &$aResult, $sSearchString = null,
8685
}
8786
}
8887
} else {
89-
// Non-List Value or CSSString (CSS identifier)
88+
// Non-List `Value` or `CSSString` (CSS identifier)
9089
$aResult[] = $oElement;
9190
}
9291
}
9392

9493
/**
95-
* @param array<int, Selector|string> $aResult
94+
* @param array<int, Selector> $aResult
9695
* @param string|null $sSpecificitySearch
9796
*
9897
* @return void

src/CSSList/Document.php

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
use Sabberworm\CSS\OutputFormat;
66
use Sabberworm\CSS\Parsing\ParserState;
77
use Sabberworm\CSS\Parsing\SourceException;
8-
use Sabberworm\CSS\Value\CSSString;
8+
use Sabberworm\CSS\Property\Selector;
9+
use Sabberworm\CSS\RuleSet\DeclarationBlock;
10+
use Sabberworm\CSS\RuleSet\RuleSet;
911
use Sabberworm\CSS\Value\Value;
1012

1113
/**
12-
* The root CSSList of a parsed file. Contains all top-level css contents, mostly declaration blocks,
14+
* The root `CSSList` of a parsed file. Contains all top-level CSS contents, mostly declaration blocks,
1315
* but also any at-rules encountered.
1416
*/
1517
class Document extends CSSBlockList
1618
{
1719
/**
18-
* Document constructor.
19-
*
2020
* @param int $iLineNo
2121
*/
2222
public function __construct($iLineNo = 0)
@@ -25,8 +25,6 @@ public function __construct($iLineNo = 0)
2525
}
2626

2727
/**
28-
* @param ParserState $oParserState
29-
*
3028
* @return Document
3129
*
3230
* @throws SourceException
@@ -39,16 +37,23 @@ public static function parse(ParserState $oParserState)
3937
}
4038

4139
/**
42-
* Gets all DeclarationBlock objects recursively.
40+
* Gets all `DeclarationBlock` objects recursively.
41+
*
42+
* @return array<int, DeclarationBlock>
4343
*/
4444
public function getAllDeclarationBlocks()
4545
{
46+
/** @var array<int, DeclarationBlock> $aResult */
4647
$aResult = [];
4748
$this->allDeclarationBlocks($aResult);
4849
return $aResult;
4950
}
5051

5152
/**
53+
* Gets all `DeclarationBlock` objects recursively.
54+
*
55+
* @return array<int, DeclarationBlock>
56+
*
5257
* @deprecated will be removed in version 9.0; use `getAllDeclarationBlocks()` instead
5358
*/
5459
public function getAllSelectors()
@@ -57,23 +62,28 @@ public function getAllSelectors()
5762
}
5863

5964
/**
60-
* Returns all RuleSet objects found recursively in the tree.
65+
* Returns all `RuleSet` objects found recursively in the tree.
66+
*
67+
* @return array<int, RuleSet>
6168
*/
6269
public function getAllRuleSets()
6370
{
71+
/** @var array<int, RuleSet> $aResult */
6472
$aResult = [];
6573
$this->allRuleSets($aResult);
6674
return $aResult;
6775
}
6876

6977
/**
70-
* Returns all Value objects found recursively in the tree.
78+
* Returns all `Value` objects found recursively in the tree.
7179
*
72-
* @param object|string $mElement
73-
* the CSSList or RuleSet to start the search from (defaults to the whole document).
80+
* @param CSSList|RuleSet|string $mElement
81+
* the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
7482
* If a string is given, it is used as rule name filter.
7583
* @param bool $bSearchInFunctionArguments whether to also return Value objects used as Function arguments.
7684
*
85+
* @return array<int, Value>
86+
*
7787
* @see RuleSet->getRules()
7888
*/
7989
public function getAllValues($mElement = null, $bSearchInFunctionArguments = false)
@@ -85,32 +95,38 @@ public function getAllValues($mElement = null, $bSearchInFunctionArguments = fal
8595
$sSearchString = $mElement;
8696
$mElement = $this;
8797
}
88-
/** @var array<int, Value|CSSString> $aResult */
98+
/** @var array<int, Value> $aResult */
8999
$aResult = [];
90100
$this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments);
91101
return $aResult;
92102
}
93103

94104
/**
95-
* Returns all Selector objects found recursively in the tree.
96-
* Note that this does not yield the full DeclarationBlock that the selector belongs to
105+
* Returns all `Selector` objects found recursively in the tree.
106+
*
107+
* Note that this does not yield the full `DeclarationBlock` that the selector belongs to
97108
* (and, currently, there is no way to get to that).
98109
*
99-
* @param string $sSpecificitySearch
110+
* @param string|null $sSpecificitySearch
100111
* An optional filter by specificity.
101112
* May contain a comparison operator and a number or just a number (defaults to "==").
102113
*
103-
* @example getSelectorsBySpecificity('>= 100')
114+
* @return array<int, Selector>
115+
* @example `getSelectorsBySpecificity('>= 100')`
116+
*
104117
*/
105118
public function getSelectorsBySpecificity($sSpecificitySearch = null)
106119
{
120+
/** @var array<int, Selector> $aResult */
107121
$aResult = [];
108122
$this->allSelectors($aResult, $sSpecificitySearch);
109123
return $aResult;
110124
}
111125

112126
/**
113-
* Expands all shorthand properties to their long value
127+
* Expands all shorthand properties to their long value.
128+
*
129+
* @return void
114130
*/
115131
public function expandShorthands()
116132
{
@@ -120,7 +136,9 @@ public function expandShorthands()
120136
}
121137

122138
/**
123-
* Create shorthands properties whenever possible
139+
* Create shorthands properties whenever possible.
140+
*
141+
* @return void
124142
*/
125143
public function createShorthands()
126144
{
@@ -130,7 +148,7 @@ public function createShorthands()
130148
}
131149

132150
/**
133-
* Override `render()` to make format argument optional
151+
* Overrides `render()` to make format argument optional.
134152
*
135153
* @param OutputFormat|null $oOutputFormat
136154
*
@@ -144,6 +162,9 @@ public function render(OutputFormat $oOutputFormat = null)
144162
return parent::render($oOutputFormat);
145163
}
146164

165+
/**
166+
* @return bool
167+
*/
147168
public function isRootList()
148169
{
149170
return true;

0 commit comments

Comments
 (0)