Skip to content

Commit 6052ca8

Browse files
authored
Merge pull request #235 from HanashiDev/phpstan
PHPStan Level 6
2 parents 7bb76f6 + 8ab2f03 commit 6052ca8

19 files changed

+102
-41
lines changed

files/lib/acp/form/FaqQuestionAddForm.class.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
use Laminas\Diactoros\Response\RedirectResponse;
66
use Override;
7+
use wcf\data\faq\category\FaqCategory;
8+
use wcf\data\faq\category\FaqCategoryNode;
79
use wcf\data\faq\category\FaqCategoryNodeTree;
810
use wcf\data\faq\Question;
911
use wcf\data\faq\QuestionAction;
1012
use wcf\data\faq\QuestionEditor;
1113
use wcf\data\IStorableObject;
1214
use wcf\data\language\item\LanguageItemList;
15+
use wcf\data\language\Language;
1316
use wcf\form\AbstractFormBuilderForm;
1417
use wcf\system\form\builder\container\FormContainer;
1518
use wcf\system\form\builder\container\TabFormContainer;
@@ -23,10 +26,12 @@
2326
use wcf\system\form\builder\IFormDocument;
2427
use wcf\system\html\input\HtmlInputProcessor;
2528
use wcf\system\language\LanguageFactory;
26-
use wcf\system\request\IRouteController;
2729
use wcf\system\request\LinkHandler;
2830
use wcf\system\WCF;
2931

32+
/**
33+
* @extends AbstractFormBuilderForm<Question>
34+
*/
3035
class FaqQuestionAddForm extends AbstractFormBuilderForm
3136
{
3237
/**
@@ -57,8 +62,14 @@ class FaqQuestionAddForm extends AbstractFormBuilderForm
5762

5863
protected int $isMultilingual = 0;
5964

65+
/**
66+
* @var array<int, string>
67+
*/
6068
protected array $multiLingualAnswers = [];
6169

70+
/**
71+
* @var array<int, FaqCategoryNode|FaqCategory>
72+
*/
6273
protected array $categories;
6374

6475
#[Override]
@@ -205,13 +216,7 @@ protected function setFormAction()
205216
'isMultilingual' => $this->isMultilingual,
206217
];
207218
if ($this->formObject !== null) {
208-
if ($this->formObject instanceof IRouteController) {
209-
$parameters['object'] = $this->formObject;
210-
} else {
211-
$object = $this->formObject;
212-
213-
$parameters['id'] = $object->{$object::getDatabaseTableIndexName()};
214-
}
219+
$parameters['object'] = $this->formObject;
215220
}
216221

217222
$this->form->action(LinkHandler::getInstance()->getControllerLink(static::class, $parameters));
@@ -227,6 +232,9 @@ public function assignVariables()
227232
]);
228233
}
229234

235+
/**
236+
* @return array<int, FaqCategoryNode|FaqCategory>
237+
*/
230238
protected function getCategories(): array
231239
{
232240
if (!isset($this->categories)) {
@@ -235,9 +243,15 @@ protected function getCategories(): array
235243
$categoryList = $categoryTree->getIterator();
236244

237245
$this->categories = [];
246+
/**
247+
* @var FaqCategoryNode $category
248+
*/
238249
foreach ($categoryList as $category) {
239250
$this->categories[$category->categoryID] = $category;
240251

252+
/**
253+
* @var FaqCategory[]
254+
*/
241255
$childCategories = $category->getAllChildCategories();
242256
if (!\count($childCategories)) {
243257
continue;

files/lib/acp/page/FaqQuestionListPage.class.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use Override;
66
use wcf\page\AbstractGridViewPage;
7-
use wcf\system\gridView\AbstractGridView;
87
use wcf\system\gridView\admin\FaqQuestionGridView;
98
use wcf\system\WCF;
109

10+
/**
11+
* @extends AbstractGridViewPage<FaqQuestionGridView>
12+
*/
1113
final class FaqQuestionListPage extends AbstractGridViewPage
1214
{
1315
/**
@@ -33,7 +35,7 @@ public function readParameters()
3335
}
3436

3537
#[Override]
36-
protected function createGridView(): AbstractGridView
38+
protected function createGridView(): FaqQuestionGridView
3739
{
3840
return new FaqQuestionGridView();
3941
}

files/lib/data/faq/Question.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function isAccessible(?User $user = null): bool
8585
return false;
8686
}
8787

88-
if ($this->getCategory()) {
88+
if ($this->getCategory()->categoryID) {
8989
return $this->getCategory()->isAccessible($user);
9090
}
9191

files/lib/data/faq/QuestionAction.class.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
use wcf\system\WCF;
1717

1818
/**
19-
* @method QuestionEditor[] getObjects()
20-
* @method QuestionEditor getSingleObject()
19+
* @extends AbstractDatabaseObjectAction<Question, QuestionEditor>
2120
*/
2221
final class QuestionAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction
2322
{
@@ -139,7 +138,7 @@ public function update()
139138
$this->updateSearchIndex($object);
140139

141140
//update show order
142-
if (isset($this->parameters['data']['showOrder']) && $this->parameters['data']['showOrder'] !== null) {
141+
if (isset($this->parameters['data']['showOrder'])) {
143142
if ($object->showOrder < $this->parameters['data']['showOrder']) {
144143
$sql = "UPDATE wcf1_faq_questions
145144
SET showOrder = showOrder - 1
@@ -188,7 +187,7 @@ public function update()
188187
}
189188
}
190189

191-
private function updateSearchIndex($object)
190+
private function updateSearchIndex(Question|QuestionEditor $object): void
192191
{
193192
if (isset($this->parameters['answer_i18n'])) {
194193
foreach ($this->parameters['answer_i18n'] as $languageID => $answer) {

files/lib/data/faq/QuestionEditor.class.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use wcf\system\WCF;
1010

1111
/**
12-
* @method static Question create(array $parameters = [])
13-
* @method Question getDecoratedObject()
1412
* @mixin Question
13+
* @extends DatabaseObjectEditor<Question>
14+
* @implements IEditableCachedObject<Question>
1515
*/
1616
final class QuestionEditor extends DatabaseObjectEditor implements IEditableCachedObject
1717
{
@@ -31,10 +31,6 @@ public static function resetCache()
3131
*/
3232
public function updateShowOrder(int $showOrder): int
3333
{
34-
if ($showOrder === null) {
35-
$showOrder = \PHP_INT_MAX;
36-
}
37-
3834
//check showOrder
3935
if ($showOrder < $this->showOrder) {
4036
$sql = "UPDATE wcf1_faq_questions

files/lib/data/faq/QuestionList.class.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
use wcf\data\DatabaseObjectList;
66

77
/**
8-
* @method Question current()
9-
* @method Question[] getObjects()
10-
* @method Question|null getSingleObject()
11-
* @method Question|null search($objectID)
12-
* @property Question[] $objects
8+
* @extends DatabaseObjectList<Question>
139
*/
1410
final class QuestionList extends DatabaseObjectList
1511
{

files/lib/data/faq/category/FaqCategory.class.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
/**
1919
* @method FaqCategory[] getChildCategories()
2020
* @method FaqCategory[] getAllChildCategories()
21-
* @method FaqCategory getParentCategory()
21+
* @method ?FaqCategory getParentCategory()
2222
* @method FaqCategory[] getParentCategories()
2323
* @method static FaqCategory|null getCategory($categoryID)
2424
*/
2525
final class FaqCategory extends AbstractDecoratedCategory implements IAccessibleObject, ITitledLinkObject
2626
{
2727
public const OBJECT_TYPE_NAME = 'dev.tkirch.wsc.faq.category';
2828

29+
/**
30+
* @var array<int, array<string, bool>>
31+
*/
2932
private array $userPermissions = [];
3033

3134
private bool $prefix = false;
@@ -40,7 +43,7 @@ public function isAccessible(?User $user = null)
4043
return $this->getPermission('canViewFAQ', $user);
4144
}
4245

43-
public function getPermission($permission, ?User $user = null, $isMod = false)
46+
public function getPermission(string $permission, ?User $user = null, bool $isMod = false): bool
4447
{
4548
if ($user === null) {
4649
$user = WCF::getUser();
@@ -74,7 +77,7 @@ public function getTitle(): string
7477
return ($this->prefix ? '&nbsp;&nbsp;' : '') . WCF::getLanguage()->get($this->title);
7578
}
7679

77-
public function setPrefix($prefix = true)
80+
public function setPrefix(bool $prefix = true): void
7881
{
7982
$this->prefix = $prefix;
8083
}

files/lib/data/faq/category/FaqCategoryCache.class.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace wcf\data\faq\category;
44

5+
use wcf\data\category\Category;
56
use wcf\system\category\CategoryHandler;
67
use wcf\system\SingletonFactory;
78
use wcf\system\WCF;
@@ -14,7 +15,7 @@ final class FaqCategoryCache extends SingletonFactory
1415
*/
1516
private array $questions;
1617

17-
private function initQuestions()
18+
private function initQuestions(): void
1819
{
1920
$this->questions = [];
2021

@@ -38,7 +39,13 @@ private function initQuestions()
3839
$this->countQuestions($categoryToParent, $contacts, 0);
3940
}
4041

41-
private function countQuestions(array $categoryToParent, array &$contacts, $categoryID)
42+
/**
43+
*
44+
* @param array<int, int[]> $categoryToParent
45+
* @param array<int, int> &$contacts
46+
* @param int $categoryID
47+
*/
48+
private function countQuestions(array $categoryToParent, array &$contacts, int $categoryID): int
4249
{
4350
$count = (isset($contacts[$categoryID])) ? $contacts[$categoryID] : 0;
4451
if (isset($categoryToParent[$categoryID])) {
@@ -54,7 +61,7 @@ private function countQuestions(array $categoryToParent, array &$contacts, $cate
5461
return $count;
5562
}
5663

57-
public function getQuestions($categoryID)
64+
public function getQuestions(int $categoryID): int
5865
{
5966
if (!isset($this->questions)) {
6067
$this->initQuestions();

files/lib/page/FaqQuestionListPage.class.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class FaqQuestionListPage extends AbstractPage
2020
*/
2121
public $neededPermissions = ['user.faq.canViewFAQ'];
2222

23+
/**
24+
* @var array<int, object>
25+
*/
2326
protected array $faqs = [];
2427

2528
protected int $showFaqAddDialog = 0;
@@ -67,8 +70,7 @@ public function readData()
6770
}
6871
if (
6972
isset($this->category)
70-
&& $this->category !== null
71-
&& $this->category->categoryID != $category->categoryID
73+
&& $this->category->categoryID !== $category->categoryID
7274
) {
7375
continue;
7476
}
@@ -115,6 +117,10 @@ public function assignVariables()
115117
]);
116118
}
117119

120+
/**
121+
* @param int[] $questionIDs
122+
* @return array<void>|GroupedAttachmentList
123+
*/
118124
protected function getAttachmentList(array $questionIDs): array|GroupedAttachmentList
119125
{
120126
if ($questionIDs === []) {

files/lib/system/attachment/FaqQuestionAttachmentObjectType.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
namespace wcf\system\attachment;
44

55
use Override;
6+
use wcf\data\faq\Question;
67
use wcf\system\WCF;
78

9+
/**
10+
* @extends AbstractAttachmentObjectType<Question>
11+
*/
812
final class FaqQuestionAttachmentObjectType extends AbstractAttachmentObjectType
913
{
1014
#[Override]

0 commit comments

Comments
 (0)