Skip to content

Commit 912e965

Browse files
committed
Fix errors reported by PHPStan
1 parent 784b8e6 commit 912e965

File tree

44 files changed

+170
-298
lines changed

Some content is hidden

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

44 files changed

+170
-298
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ parameters:
2424
count: 1
2525
path: wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php
2626

27-
-
28-
message: '#^Parameter \#1 \$children of method wcf\\system\\form\\builder\\IFormParentNode\:\:appendChildren\(\) expects array\<wcf\\system\\form\\builder\\IFormChildNode\>, array\<int, wcf\\system\\form\\builder\\field\\PasswordFormField\|wcf\\system\\form\\builder\\field\\TextFormField\|wcf\\system\\form\\builder\\IObjectTypeFormNode\> given\.$#'
29-
identifier: argument.type
30-
count: 1
31-
path: wcfsetup/install/files/lib/acp/form/LoginForm.class.php
32-
3327
-
3428
message: '#^Property wcf\\acp\\page\\DevtoolsNotificationTestPage\:\:\$events \(array\<array\<wcf\\system\\user\\notification\\event\\ITestableUserNotificationEvent\>\>\) does not accept array\<array\<wcf\\system\\user\\notification\\event\\IUserNotificationEvent\>\>\.$#'
3529
identifier: assign.propertyType
@@ -48,12 +42,6 @@ parameters:
4842
count: 1
4943
path: wcfsetup/install/files/lib/acp/page/TemplateDiffPage.class.php
5044

51-
-
52-
message: '#^Parameter \#1 \$children of method wcf\\system\\form\\builder\\FormDocument\:\:appendChildren\(\) expects array\<wcf\\system\\form\\builder\\IFormChildNode\>, array\<int, wcf\\system\\form\\builder\\field\\user\\UsernameFormField\|wcf\\system\\form\\builder\\IObjectTypeFormNode\> given\.$#'
53-
identifier: argument.type
54-
count: 1
55-
path: wcfsetup/install/files/lib/action/GuestTokenDialogAction.class.php
56-
5745
-
5846
message: '#^Method wcf\\data\\article\\ArticleAction\:\:delete\(\) should return int but returns array\<string, array\<int\>\|string\>\.$#'
5947
identifier: return.type
@@ -90,12 +78,6 @@ parameters:
9078
count: 1
9179
path: wcfsetup/install/files/lib/data/user/notification/event/UserNotificationEventAction.class.php
9280

93-
-
94-
message: '#^Parameter \#1 \$children of method wcf\\system\\form\\builder\\container\\FormContainer\:\:appendChildren\(\) expects array\<wcf\\system\\form\\builder\\IFormChildNode\>, array\<int, wcf\\system\\form\\builder\\field\\TextFormField\|wcf\\system\\form\\builder\\IObjectTypeFormNode\> given\.$#'
95-
identifier: argument.type
96-
count: 1
97-
path: wcfsetup/install/files/lib/form/LostPasswordForm.class.php
98-
9981
-
10082
message: '#^Instanceof between wcf\\data\\search\\ISearchResultObject and wcf\\data\\search\\ISearchResultObject will always evaluate to true\.$#'
10183
identifier: instanceof.alwaysTrue
@@ -786,120 +768,36 @@ parameters:
786768
count: 2
787769
path: wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php
788770

789-
-
790-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
791-
identifier: function.alreadyNarrowedType
792-
count: 2
793-
path: wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php
794-
795-
-
796-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\AbstractNumericFormField\)\> and string will always evaluate to true\.$#'
797-
identifier: function.alreadyNarrowedType
798-
count: 1
799-
path: wcfsetup/install/files/lib/system/form/builder/field/AbstractNumericFormField.class.php
800-
801-
-
802-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\BooleanFormField\)\> and string will always evaluate to true\.$#'
803-
identifier: function.alreadyNarrowedType
804-
count: 1
805-
path: wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php
806-
807-
-
808-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\ButtonFormField\)\> and string will always evaluate to true\.$#'
809-
identifier: function.alreadyNarrowedType
810-
count: 1
811-
path: wcfsetup/install/files/lib/system/form/builder/field/ButtonFormField.class.php
812-
813-
-
814-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\DateFormField\)\> and string will always evaluate to true\.$#'
815-
identifier: function.alreadyNarrowedType
816-
count: 1
817-
path: wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php
818-
819-
-
820-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\DateRangeFormField\)\> and string will always evaluate to true\.$#'
821-
identifier: function.alreadyNarrowedType
822-
count: 1
823-
path: wcfsetup/install/files/lib/system/form/builder/field/DateRangeFormField.class.php
824-
825771
-
826772
message: '#^Call to function is_numeric\(\) with array\<string\> will always evaluate to false\.$#'
827773
identifier: function.impossibleType
828774
count: 2
829775
path: wcfsetup/install/files/lib/system/form/builder/field/EmailFormField.class.php
830776

831-
-
832-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
833-
identifier: function.alreadyNarrowedType
834-
count: 1
835-
path: wcfsetup/install/files/lib/system/form/builder/field/EmailFormField.class.php
836-
837-
-
838-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\EmailFormField\)\> and string will always evaluate to true\.$#'
839-
identifier: function.alreadyNarrowedType
840-
count: 1
841-
path: wcfsetup/install/files/lib/system/form/builder/field/EmailFormField.class.php
842-
843-
-
844-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\ItemListFormField\)\> and string will always evaluate to true\.$#'
845-
identifier: function.alreadyNarrowedType
846-
count: 1
847-
path: wcfsetup/install/files/lib/system/form/builder/field/ItemListFormField.class.php
848-
849777
-
850778
message: '#^Call to function is_callable\(\) with callable\(\)\: mixed will always evaluate to true\.$#'
851779
identifier: function.alreadyNarrowedType
852780
count: 2
853781
path: wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php
854782

855-
-
856-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\MultipleSelectionFormField\)\> and string will always evaluate to true\.$#'
857-
identifier: function.alreadyNarrowedType
858-
count: 1
859-
path: wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php
860-
861783
-
862784
message: '#^Result of && is always false\.$#'
863785
identifier: booleanAnd.alwaysFalse
864786
count: 2
865787
path: wcfsetup/install/files/lib/system/form/builder/field/MultipleSelectionFormField.class.php
866788

867-
-
868-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\NumericRangeFormField\)\> and string will always evaluate to true\.$#'
869-
identifier: function.alreadyNarrowedType
870-
count: 1
871-
path: wcfsetup/install/files/lib/system/form/builder/field/NumericRangeFormField.class.php
872-
873789
-
874790
message: '#^Call to function is_int\(\) with int will always evaluate to true\.$#'
875791
identifier: function.alreadyNarrowedType
876792
count: 2
877793
path: wcfsetup/install/files/lib/system/form/builder/field/PasswordFormField.class.php
878794

879-
-
880-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
881-
identifier: function.alreadyNarrowedType
882-
count: 1
883-
path: wcfsetup/install/files/lib/system/form/builder/field/PasswordFormField.class.php
884-
885-
-
886-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\PasswordFormField\)\> and string will always evaluate to true\.$#'
887-
identifier: function.alreadyNarrowedType
888-
count: 1
889-
path: wcfsetup/install/files/lib/system/form/builder/field/PasswordFormField.class.php
890-
891795
-
892796
message: '#^Call to function is_callable\(\) with callable\(\)\: mixed will always evaluate to true\.$#'
893797
identifier: function.alreadyNarrowedType
894798
count: 2
895799
path: wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php
896800

897-
-
898-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\RadioButtonFormField\)\> and string will always evaluate to true\.$#'
899-
identifier: function.alreadyNarrowedType
900-
count: 1
901-
path: wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php
902-
903801
-
904802
message: '#^Result of && is always false\.$#'
905803
identifier: booleanAnd.alwaysFalse
@@ -942,12 +840,6 @@ parameters:
942840
count: 2
943841
path: wcfsetup/install/files/lib/system/form/builder/field/SourceCodeFormField.class.php
944842

945-
-
946-
message: '#^Call to function is_subclass_of\(\) with ''wcf\\\\system\\\\form\\\\builder\\\\field\\\\SourceCodeFormField'' and string will always evaluate to true\.$#'
947-
identifier: function.alreadyNarrowedType
948-
count: 1
949-
path: wcfsetup/install/files/lib/system/form/builder/field/SourceCodeFormField.class.php
950-
951843
-
952844
message: '#^Call to function is_int\(\) with int will always evaluate to true\.$#'
953845
identifier: function.alreadyNarrowedType
@@ -960,18 +852,6 @@ parameters:
960852
count: 2
961853
path: wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php
962854

963-
-
964-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
965-
identifier: function.alreadyNarrowedType
966-
count: 1
967-
path: wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php
968-
969-
-
970-
message: '#^Call to function is_subclass_of\(\) with class\-string\<static\(wcf\\system\\form\\builder\\field\\TextFormField\)\> and string will always evaluate to true\.$#'
971-
identifier: function.alreadyNarrowedType
972-
count: 1
973-
path: wcfsetup/install/files/lib/system/form/builder/field/TextFormField.class.php
974-
975855
-
976856
message: '#^Call to function is_array\(\) with array\<wcf\\system\\file\\upload\\UploadFile\> will always evaluate to true\.$#'
977857
identifier: function.alreadyNarrowedType
@@ -1020,42 +900,12 @@ parameters:
1020900
count: 1
1021901
path: wcfsetup/install/files/lib/system/form/builder/field/dependency/ValueFormFieldDependency.class.php
1022902

1023-
-
1024-
message: '#^Call to function is_subclass_of\(\) with ''wcf\\\\system\\\\form\\\\builder\\\\field\\\\tag\\\\TagFormField'' and string will always evaluate to true\.$#'
1025-
identifier: function.alreadyNarrowedType
1026-
count: 1
1027-
path: wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php
1028-
1029-
-
1030-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
1031-
identifier: function.alreadyNarrowedType
1032-
count: 1
1033-
path: wcfsetup/install/files/lib/system/form/builder/field/user/UserPasswordField.class.php
1034-
1035-
-
1036-
message: '#^Call to function is_subclass_of\(\) with ''wcf\\\\system\\\\form\\\\builder\\\\field\\\\user\\\\UserPasswordField'' and string will always evaluate to true\.$#'
1037-
identifier: function.alreadyNarrowedType
1038-
count: 1
1039-
path: wcfsetup/install/files/lib/system/form/builder/field/user/UserPasswordField.class.php
1040-
1041903
-
1042904
message: '#^Call to function is_int\(\) with int will always evaluate to true\.$#'
1043905
identifier: function.alreadyNarrowedType
1044906
count: 2
1045907
path: wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php
1046908

1047-
-
1048-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
1049-
identifier: function.alreadyNarrowedType
1050-
count: 1
1051-
path: wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php
1052-
1053-
-
1054-
message: '#^Call to function is_subclass_of\(\) with ''wcf\\\\system\\\\form\\\\builder\\\\field\\\\user\\\\UsernameFormField'' and string will always evaluate to true\.$#'
1055-
identifier: function.alreadyNarrowedType
1056-
count: 1
1057-
path: wcfsetup/install/files/lib/system/form/builder/field/user/UsernameFormField.class.php
1058-
1059909
-
1060910
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
1061911
identifier: function.alreadyNarrowedType
@@ -1068,12 +918,6 @@ parameters:
1068918
count: 2
1069919
path: wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php
1070920

1071-
-
1072-
message: '#^Call to function is_subclass_of\(\) with ''wcf\\\\system\\\\form\\\\builder\\\\field\\\\wysiwyg\\\\WysiwygFormField'' and string will always evaluate to true\.$#'
1073-
identifier: function.alreadyNarrowedType
1074-
count: 1
1075-
path: wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php
1076-
1077921
-
1078922
message: '#^Call to function is_bool\(\) with string will always evaluate to false\.$#'
1079923
identifier: function.impossibleType

wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_contactOptions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
default => $contactOption->optionType,
2424
};
2525

26+
// @phpstan-ignore property.notFound
2627
if ($contactOption->required) {
2728
$configuration['required'] = 1;
2829
}
30+
// @phpstan-ignore property.notFound
2931
if ($contactOption->defaultValue && $contactOption->optionType == 'text') {
3032
$configuration['defaultValue'] = $contactOption->defaultValue;
3133
}
34+
// @phpstan-ignore property.notFound
3235
if ($contactOption->selectOptions) {
3336
$configuration['required'] = convertSelectOptions($contactOption->selectOptions);
3437
}

wcfsetup/install/files/lib/acp/form/AbstractFormOptionAddForm.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use wcf\form\AbstractFormBuilderForm;
88
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
99
use wcf\system\form\builder\field\dependency\ValueFormFieldDependency;
10+
use wcf\system\form\builder\field\IFormField;
1011
use wcf\system\form\builder\field\SelectFormField;
1112
use wcf\system\form\builder\IFormDocument;
1213
use wcf\system\form\option\FormOptionHandler;
@@ -53,6 +54,7 @@ function (IFormDocument $document, array $parameters) {
5354
function (IFormDocument $document, array $data, IStorableObject $object) {
5455
\assert($object instanceof DatabaseObject);
5556

57+
// @phpstan-ignore property.notFound
5658
if ($object->configuration) {
5759
$data = \array_merge($data, JSON::decode($object->configuration));
5860
}
@@ -80,7 +82,7 @@ protected function getConfigurationFormFieldIds(): array
8082
}
8183

8284
/**
83-
* @return IFormField[]
85+
* @return list<IFormField>
8486
*/
8587
protected function getSharedConfigurationFormFields(): array
8688
{
@@ -101,6 +103,7 @@ protected function getSharedConfigurationFormFields(): array
101103

102104
foreach ($matrix as $formFieldId => $dependencies) {
103105
$formField = $sharedConfigurationFormFields->getFormField($formFieldId);
106+
\assert($formField !== null);
104107
$formField->addDependency(
105108
ValueFormFieldDependency::create($formFieldId . 'OptionTypeDependency')
106109
->fieldId('optionType')

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ protected function createCollection(): void
246246

247247
$collection = new ($firstObject->getCollectionClassName())($this->objects);
248248
foreach ($this->objects as $object) {
249+
\assert($object instanceof CollectionDatabaseObject);
249250
$object->setCollection($collection);
250251
}
251252
}

wcfsetup/install/files/lib/data/article/content/ViewableArticleContent.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function setTeaserImage(ViewableMedia $image)
132132
* Returns a specific article content decorated as viewable article content.
133133
*
134134
* @param int $articleContentID
135-
* @return ViewableArticleContent
135+
* @return ?ViewableArticleContent
136136
*/
137137
public static function getArticleContent($articleContentID)
138138
{

wcfsetup/install/files/lib/data/article/content/ViewableArticleContentList.class.php

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

33
namespace wcf\data\article\content;
44

5+
use wcf\data\article\ViewableArticle;
56
use wcf\data\article\ViewableArticleList;
67
use wcf\data\media\ViewableMediaList;
78
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
@@ -63,7 +64,7 @@ public function readObjects()
6364
}
6465

6566
// cache images
66-
if (!empty($imageIDs)) {
67+
if ($imageIDs !== []) {
6768
$mediaList = new ViewableMediaList($contentLanguageID);
6869
$mediaList->setObjectIDs($imageIDs);
6970
$mediaList->readObjects();
@@ -79,12 +80,16 @@ public function readObjects()
7980
);
8081
}
8182

82-
if ($this->articleLoading && !empty($articleIDs)) {
83+
/** @var array<int, ViewableArticle> */
84+
$articles = [];
85+
if ($this->articleLoading && $articleIDs !== []) {
8386
$articleList = new ViewableArticleList();
84-
// to prevent an infinity loop, because the list loads otherwise the article content
87+
// Prevents an infinite loop, because the list would load the
88+
// content itself.
8589
$articleList->enableContentLoading(false);
8690
$articleList->setObjectIDs($articleIDs);
8791
$articleList->readObjects();
92+
$articles = $articleList->getObjects();
8893
}
8994

9095
foreach ($this->getObjects() as $articleContent) {
@@ -99,11 +104,12 @@ public function readObjects()
99104
}
100105

101106
if ($this->articleLoading) {
102-
if ($articleList->search($articleContent->articleID) !== null) {
103-
$articleContent->setArticle($articleList->search($articleContent->articleID));
104-
} else {
107+
$article = $articles[$articleContent->articleID] ?? null;
108+
if ($article === null) {
105109
throw new \LogicException('Unable to find article with id "' . $articleContent->articleID . '".');
106110
}
111+
112+
$articleContent->setArticle($article);
107113
}
108114
}
109115
}

wcfsetup/install/files/lib/data/contact/option/ContactOptionAction.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public function update()
118118
}
119119
}
120120

121+
/**
122+
* @return array<string, string>
123+
*/
121124
#[\Override]
122125
public function getI18nSaveTypes(): array
123126
{

wcfsetup/install/files/lib/data/contact/recipient/ContactRecipientAction.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public function update()
108108
}
109109
}
110110

111+
/**
112+
* @return array<string, string>
113+
*/
111114
#[\Override]
112115
public function getI18nSaveTypes(): array
113116
{

wcfsetup/install/files/lib/data/custom/option/CustomOptionAction.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* @copyright 2001-2019 WoltLab GmbH
1515
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1616
* @since 3.1
17+
* @deprecated 6.2 Use `IFormOption` instead
1718
*
1819
* @template TCustomOption of CustomOption = CustomOption
1920
* @template TCustomOptionEditor of CustomOptionEditor|DatabaseObjectDecorator<TCustomOption> = CustomOptionEditor
2021
* @extends AbstractDatabaseObjectAction<TCustomOption, TCustomOptionEditor>
2122
* @phpstan-ignore generics.notSubtype
22-
* @deprecated 6.2 Use `IFormOption` instead
2323
*/
2424
abstract class CustomOptionAction extends AbstractDatabaseObjectAction implements IToggleAction
2525
{

0 commit comments

Comments
 (0)