Skip to content

Commit 8931328

Browse files
committed
Improve typing of the remaining system classes
1 parent e6dfe3b commit 8931328

File tree

65 files changed

+455
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+455
-293
lines changed

wcfsetup/install/files/lib/data/IDatabaseObjectProcessor.class.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111
*/
1212
interface IDatabaseObjectProcessor
1313
{
14-
/**
15-
* Creates a new instance of a database object processor.
16-
*
17-
* @param DatabaseObject $object
18-
*/
1914
public function __construct(DatabaseObject $object);
2015

2116
/**
2217
* Delegates accesses to inaccessible object properties the processed object.
2318
*
2419
* @param string $name
25-
* @return mixed
20+
* @return mixed
2621
*/
2722
public function __get($name);
2823

@@ -31,16 +26,16 @@ public function __get($name);
3126
* object.
3227
*
3328
* @param string $name
34-
* @return bool
29+
* @return bool
3530
*/
3631
public function __isset($name);
3732

3833
/**
3934
* Delegates inaccessible method calls to the processed database object.
4035
*
4136
* @param string $name
42-
* @param array $arguments
43-
* @return mixed
37+
* @param mixed[] $arguments
38+
* @return mixed
4439
*/
4540
public function __call($name, $arguments);
4641
}

wcfsetup/install/files/lib/data/bbcode/BBCode.class.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BBCode extends ProcessibleDatabaseObject implements IRouteController
3232
{
3333
/**
3434
* list of attributes
35-
* @var BBCodeAttribute[]
35+
* @var list<BBCodeAttribute>
3636
*/
3737
protected $attributes;
3838

@@ -54,7 +54,7 @@ class BBCode extends ProcessibleDatabaseObject implements IRouteController
5454
/**
5555
* Returns the attributes of this bbcode.
5656
*
57-
* @return BBCodeAttribute[]
57+
* @return list<BBCodeAttribute>
5858
*/
5959
public function getAttributes()
6060
{
@@ -68,7 +68,8 @@ public function getAttributes()
6868
/**
6969
* Sets the attributes of this bbcode.
7070
*
71-
* @param BBCodeAttribute[] $attributes list of attributes
71+
* @param list<BBCodeAttribute> $attributes list of attributes
72+
* @return void
7273
*/
7374
public function setAttributes(array $attributes)
7475
{
@@ -86,8 +87,8 @@ public function getTitle(): string
8687
/**
8788
* Returns the button label in the active user's language.
8889
*
89-
* @return string
90-
* @since 5.2
90+
* @return string
91+
* @since 5.2
9192
*/
9293
public function getButtonLabel()
9394
{
@@ -98,7 +99,7 @@ public function getButtonLabel()
9899
* Returns BBCode object with the given tag.
99100
*
100101
* @param string $tag
101-
* @return BBCode
102+
* @return BBCode
102103
*/
103104
public static function getBBCodeByTag($tag)
104105
{
@@ -122,7 +123,7 @@ public static function getBBCodeByTag($tag)
122123
*
123124
* @param string $bbcodeTag
124125
* @param string[] $allowedBBCodeTags
125-
* @return bool
126+
* @return bool
126127
*/
127128
public static function isAllowedBBCode($bbcodeTag, array $allowedBBCodeTags)
128129
{
@@ -147,7 +148,7 @@ public static function isAllowedBBCode($bbcodeTag, array $allowedBBCodeTags)
147148
/**
148149
* Returns true if this BBCode can be deleted.
149150
*
150-
* @return bool
151+
* @return bool
151152
*/
152153
public function canDelete()
153154
{

wcfsetup/install/files/lib/data/bbcode/BBCodeCache.class.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BBCodeCache extends SingletonFactory
1717
{
1818
/**
1919
* cached bbcodes
20-
* @var BBCode[]
20+
* @var array<string, BBCode>
2121
*/
2222
protected $cachedBBCodes = [];
2323

@@ -26,14 +26,13 @@ class BBCodeCache extends SingletonFactory
2626
*/
2727
protected function init()
2828
{
29-
// get bbcode cache
3029
$this->cachedBBCodes = BBCodeCacheBuilder::getInstance()->getData([], 'bbcodes');
3130
}
3231

3332
/**
3433
* Returns all bbcodes.
3534
*
36-
* @return BBCode[]
35+
* @return array<string, BBCode>
3736
*/
3837
public function getBBCodes()
3938
{
@@ -44,7 +43,7 @@ public function getBBCodes()
4443
* Returns the BBCode with the given tag or `null` if no such BBCode exists.
4544
*
4645
* @param string $tag
47-
* @return BBCode|null
46+
* @return ?BBCode
4847
*/
4948
public function getBBCodeByTag($tag)
5049
{
@@ -55,7 +54,7 @@ public function getBBCodeByTag($tag)
5554
* Returns all attributes of a bbcode.
5655
*
5756
* @param string $tag
58-
* @return BBCodeAttribute[]
57+
* @return list<BBCodeAttribute>
5958
*/
6059
public function getBBCodeAttributes($tag)
6160
{

wcfsetup/install/files/lib/system/CLIWCF.class.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ public static function destruct(): void
9696
}
9797
}
9898

99-
/**
100-
* @inheritDoc
101-
*/
102-
final public static function handleCLIException($e): never
99+
final public static function handleCLIException(\Throwable $e): never
103100
{
104101
exit($e->getMessage() . "\n" . $e->getTraceAsString());
105102
}

wcfsetup/install/files/lib/system/MetaTagHandler.class.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@
1010
* @author Alexander Ebert
1111
* @copyright 2001-2019 WoltLab GmbH
1212
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
*
14+
* @implements \Iterator<string, string>
1315
*/
1416
final class MetaTagHandler extends SingletonFactory implements \Countable, \Iterator
1517
{
1618
/**
1719
* current iterator index
1820
*/
19-
protected int $index = 0;
21+
private int $index = 0;
2022

2123
/**
2224
* list of index to object relation
23-
* @var int[]
25+
* @var list<string>
2426
*/
25-
protected $indexToObject = [];
27+
private array $indexToObject = [];
2628

2729
/**
2830
* list of meta tags
29-
* @var array
31+
* @var array<string, array{isProperty: bool, name: string, value: string}>
3032
*/
31-
protected $objects = [];
33+
private array $objects = [];
3234

3335
/**
3436
* @inheritDoc
@@ -112,7 +114,7 @@ public function current(): string
112114
*
113115
* @see \Iterator::key()
114116
*/
115-
public function key(): int
117+
public function key(): string
116118
{
117119
return $this->indexToObject[$this->index];
118120
}

wcfsetup/install/files/lib/system/Regex.class.php

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,16 @@ final class Regex
111111

112112
/**
113113
* compiled regex
114-
* @var string
115114
*/
116-
private $regex = '';
115+
private string $regex = '';
117116

118117
/**
119118
* last matches
120-
* @var array
119+
* @var array<string|int, mixed|mixed[]>|array{}
121120
*/
122-
private $matches = [];
121+
private array $matches = [];
123122

124-
/**
125-
* Creates a regex.
126-
*
127-
* @param string $regex
128-
* @param int $modifier
129-
*/
130-
public function __construct($regex, $modifier = self::MODIFIER_NONE)
123+
public function __construct(string $regex, int $modifier = self::MODIFIER_NONE)
131124
{
132125
// escape delimiter
133126
$regex = \str_replace(self::REGEX_DELIMITER, '\\' . self::REGEX_DELIMITER, $regex);
@@ -159,28 +152,20 @@ public function __construct($regex, $modifier = self::MODIFIER_NONE)
159152
}
160153
}
161154

162-
/**
163-
* @inheritDoc
164-
*/
165-
public static function compile($regex, $modifier = self::MODIFIER_NONE)
155+
public static function compile(string $regex, int $modifier = self::MODIFIER_NONE): self
166156
{
167157
return new self($regex, $modifier);
168158
}
169159

170-
/**
171-
* @inheritDoc
172-
*/
173-
public function __invoke($string)
160+
public function __invoke(string $string): int
174161
{
175162
return $this->match($string);
176163
}
177164

178165
/**
179166
* Checks whether the regex is syntactically correct.
180-
*
181-
* @return bool
182167
*/
183-
public function isValid()
168+
public function isValid(): bool
184169
{
185170
try {
186171
$this->match(''); // we don't care about the result, we only care about the exception
@@ -192,17 +177,15 @@ public function isValid()
192177
}
193178
}
194179

195-
// @codingStandardsIgnoreStart
196-
197180
/**
198181
* Checks whether the regex matches the given string.
199182
*
200183
* @param string $string string to match
201184
* @param bool $all indicates if all matches are collected
202185
* @param int $flags match flags
203-
* @return int return value of preg_match(_all)
186+
* @return int return value of preg_match(_all)
204187
*/
205-
public function match($string, $all = false, $flags = self::FLAGS_DEFAULT)
188+
public function match(string $string, bool $all = false, int $flags = self::FLAGS_DEFAULT): int
206189
{
207190
$matchFlags = 0;
208191
if ($flags & self::CAPTURE_OFFSET) {
@@ -229,11 +212,9 @@ public function match($string, $all = false, $flags = self::FLAGS_DEFAULT)
229212
/**
230213
* Replaces part of the string with the regex.
231214
*
232-
* @param string $string
233215
* @param mixed $replacement replacement-string or closure
234-
* @return string
235216
*/
236-
public function replace($string, $replacement)
217+
public function replace(string $string, mixed $replacement): string
237218
{
238219
if ($replacement instanceof Callback || $replacement instanceof \Closure) {
239220
return $this->checkResult(\preg_replace_callback($this->regex, $replacement, $string), 'replace');
@@ -245,11 +226,9 @@ public function replace($string, $replacement)
245226
/**
246227
* Splits the string with the regex.
247228
*
248-
* @param string $string
249-
* @param int $flags
250-
* @return string[]
229+
* @return string[]
251230
*/
252-
public function split($string, $flags = self::FLAGS_DEFAULT)
231+
public function split(string $string, int $flags = self::FLAGS_DEFAULT): array
253232
{
254233
$splitFlags = 0;
255234
if ($flags & self::CAPTURE_OFFSET) {
@@ -265,17 +244,12 @@ public function split($string, $flags = self::FLAGS_DEFAULT)
265244
return $this->checkResult(\preg_split($this->regex, $string, -1, $splitFlags), 'split');
266245
}
267246

268-
// @codingStandardsIgnoreEnd
269-
270247
/**
271248
* Checks whether there was success.
272249
*
273-
* @param mixed $result
274-
* @param string $method
275-
* @return mixed
276-
* @throws SystemException
250+
* @throws SystemException
277251
*/
278-
private function checkResult($result, $method = '')
252+
private function checkResult(mixed $result, string $method = ''): mixed
279253
{
280254
if ($result === false || $result === null) {
281255
switch (\preg_last_error()) {
@@ -309,19 +283,17 @@ private function checkResult($result, $method = '')
309283
/**
310284
* Returns the matches of the last string.
311285
*
312-
* @return array
286+
* @return array<string|int, mixed|mixed[]>
313287
*/
314-
public function getMatches()
288+
public function getMatches(): array
315289
{
316290
return $this->matches;
317291
}
318292

319293
/**
320294
* Returns the compiled regex.
321-
*
322-
* @return string
323295
*/
324-
public function getRegex()
296+
public function getRegex(): string
325297
{
326298
return $this->regex;
327299
}

wcfsetup/install/files/lib/system/TemplateScriptingCore.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function __construct(WCF $wcf)
3434
* and the template object.
3535
*
3636
* @param string $name called method
37-
* @param array $arguments method parameters
38-
* @return mixed
37+
* @param mixed[] $arguments method parameters
38+
* @return mixed
3939
*/
4040
public function __call($name, array $arguments)
4141
{

0 commit comments

Comments
 (0)