forked from fastsitephp/fastsitephp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpstan.neon
261 lines (260 loc) · 11.3 KB
/
phpstan.neon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# This file is used for linting FastSitePHP with the PHP Static Analysis Tool [phpstan]:
# https://github.com/phpstan/phpstan
#
# To lint the code base:
# 1) Download [phpstan.phar] from:
# https://github.com/phpstan/phpstan/releases
# 2) Run:
# php phpstan.phar analyse --level 8 -a autoload.php -c phpstan.neon src > phpstan_results.txt
#
# Currently all code through extensive Unit Testing so most errors need to be excluded
# based phpstan's on strict checking of PHP Code using PHPDoc Comments and expected types.
# For example many php built-in functions will return [false] on failure while phpstan
# assumes they return int|string|etc. FastSitePHP is built around PHP's flexibility
# and is similar to using JavaScript or Python while PHP Static Analysis Tool seem
# to assume code should be more like C# or Java.
#
# Alternative options that have been tested. Just like [phpstan] running these would
# need a lot of config files so currently only [phpstan] is used.
# https://github.com/vimeo/psalm
# https://github.com/phan/phan
#
# Simliar to [phpstan] a (*.phar) file would be downloaded and ran.
# php psalm.phar > psalm_results.txt
# php phan.phar > phan_results.txt
#
# IMPORTANT - If editing the code base do not fix "errors" based on [phpstan].
# Rather if the related code is fully unit tested then exclude the error in this file.
# If the code is not fully testsed then it should be or it needs to be carefully
# reviewed and manually tested.
parameters:
checkMissingIterableValueType: false
inferPrivatePropertyTypeFromConstructor: false
ignoreErrors:
-
message: '#Access to an undefined property#'
path: src/Data/AbstractVendorDatabase.php
-
message: '#Undefined variable#'
paths:
- src/Data/AbstractVendorDatabase.php
- src/Templates/error-cli.php
- src/Templates/error.php
- src/Templates/html-template.php
-
message: '#Variable \$e might not be defined#'
paths:
- src/Templates/error-cli.php
- src/Templates/error.php
-
message: '#PHPDoc tag @param has invalid value#'
path: src/Data/AbstractDatabase.php
-
message: '#PHPDoc tag @param for parameter (s+) with type array|null is not subtype of native type array#'
paths:
- src/Data/Database.php
- src/Data/Log/AbstractLogger.php
- src/Environment/DotEnv.php
- src/Net/HttpClient.php
-
message: '#Binary operation (.+) results in an error#'
path: src/Net/IP.php
-
message: '#Call to an undefined method object#'
path: src/Templates/error-cli.php
-
message: '#Strict comparison using === between string|false and null will always evaluate to false.#'
paths:
- src/Application.php
- src/AppMin.php
-
message: '#Result of || is always true#'
paths:
- src/Data/Validator.php
- src/Security/Crypto/JWT.php
- src/Web/Request.php
- src/Web/Response.php
-
message: '#Result of && is always false#'
paths:
- src/Encoding/Base64Url.php
- src/Net/IP.php
- src/Polyfill/hex_compat.php
- src/Templates/error.php
-
message: '#Comparison operation ">" between int<min, 0>|false and 0 is always false.#'
path: src/Application.php
-
message: '#Unreachable statement - code above always terminates#'
paths:
- src/Net/SmtpClient.php
- src/Security/Crypto/AbstractCrypto.php
-
message: '#Strict comparison using === between string and null will always evaluate to false#'
paths:
- src/Security/Crypto/FileEncryption.php
-
# The items on the next error are based on phpstan assuming a user always passes a string if the PHPDoc Block
# specifies a string. These are error that can be matched based on [is_string()].
# These branches are reachable as confirmed in Unit Tests.
message: '#Else branch is unreachable because previous condition is always true#'
paths:
- src/Lang/I18N.php
- src/Lang/L10N.php
-
# These errors are similar ot the above where phpstan assumes user cannot pass invalid input.
# And some of these are related to mixed types not being handled by phpstan.
# These conditions are reachable as confirmed in Unit Tests.
message: '#Strict comparison using (.*) will always evaluate to false#'
paths:
- src/Lang/I18N.php
- src/Lang/L10N.php
- src/Security/Crypto/FileEncryption.php
- src/Net/HttpClient.php
- src/Security/Crypto/AbstractCrypto.php
-
# Below check is logic based on differnces between 32-bit and 64-bit builds of PHP.
message: '#Comparison operation (.*) between int and 2147483647 is always true#'
paths:
- src/Security/Crypto/Encryption.php
- src/Security/Crypto/SignedData.php
-
# According to PHP Docs int should be passed and it has been confirmed to work
# and used on production sites.
message: '#of function ini_set expects string, int given.#'
path: src/Data/OdbcDatabase.php
-
# This is tested and confirmed to work on both 32-bit and 64-bit systems
message: '#bcpow expects string, int given#'
path: src/Net/IP.php
-
message: '#function openssl_pkey_export expects string, null given#'
path: src/Security/Crypto/PublicKey.php
-
# Interface classes and some Abstract files are more readable when not using PHPDoc Comments.
# Additionally well tested protected and private props do not need always typehints.
# Including PHPDocs wiht every single private and protected prop can make the code less
# readable as props will be displayed over many screens rather than together.
message: '#Property (.+) has no typehint specified#'
paths:
- src/Data/AbstractDatabase.php
- src/Data/Db2Database.php
- src/Data/OdbcDatabase.php
- src/Data/KeyValue/SqliteStorage.php
- src/Data/Log/HtmlLogger.php
- src/FileSystem/Search.php
- src/FileSystem/Sync.php
- src/Lang/L10N.php
- src/Lang/I18N.php
- src/Media/Image.php
- src/Net/Email.php
- src/Net/SmtpClient.php
- src/Security/Crypto/AbstractCrypto.php
- src/Security/Crypto/Encryption.php
- src/Security/Crypto/FileEncryption.php
- src/Security/Password.php
-
# See above comments
message: '#Method (.+) no typehint specified#'
paths:
- src/Data/AbstractDatabase.php
- src/Data/DatabaseInterface.php
- src/Data/KeyValue/StorageInterface.php
- src/Security/Crypto/CryptoInterface.php
-
# See above comments
message: '#Method (.+) no return typehint specified#'
paths:
- src/Data/DatabaseInterface.php
- src/Data/KeyValue/StorageInterface.php
- src/Security/Crypto/CryptoInterface.php
-
# PHP uses and allows mixed types in many functions however phpstan is very stict
# and will give many false positives for calls that will work plus it seems to have
# errors related to the return types of built-in functions in some cases.
# FastSitePHP goes though a lot of unit testing for these items so they can
# be ignored once the code is tested.
message: '#Parameter (.+) expects (.+) given#'
paths:
- src/AppMin.php
- src/Application.php
- src/Net/Email.php
- src/Net/HttpClient.php
- src/Net/SmtpClient.php
- src/Environment/DotEnv.php
- src/Environment/System.php
- src/FileSystem/Search.php
- src/Lang/I18N.php
- src/Lang/L10N.php
- src/Media/Image.php
- src/Net/Config.php
- src/Security/Crypto/AbstractCrypto.php
- src/Security/Crypto/Encryption.php
- src/Security/Crypto/FileEncryption.php
- src/Security/Crypto/SignedData.php
- src/Security/Web/CsrfStateless.php
- src/Net/IP.php
- src/Encoding/Json.php
-
# Similar issue to the above error
message: '#Method (.+) should return (.+) but returns#'
paths:
- src/AppMin.php
- src/Application.php
- src/Data/Database.php
- src/Data/Log/HtmlLogger.php
- src/Net/Email.php
- src/Security/Crypto/Encryption.php
- src/Net/HttpClient.php
- src/Environment/System.php
- src/Lang/I18N.php
- src/Net/Config.php
- src/Security/Crypto/SignedData.php
- src/Security/Password.php
-
# Similar issue to the above error. This one aslo applies to getter/setter functions.
message: '#Argument of an invalid type#'
paths:
- src/Data/Database.php
- src/Encoding/Utf8.php
- src/Net/Email.php
- src/Lang/I18N.php
-
# Getter/Setting type functions are not handled well by phpstan
message: '#Cannot call method#'
paths:
- src/Application.php
- src/FileSystem/Sync.php
- src/Lang/L10N.php
- src/Security/Crypto/FileEncryption.php
-
message: '#Cannot access offset#'
paths:
- src/Net/SmtpClient.php
- src/Security/Crypto/PublicKey.php
-
message: '#Offset (.+) does not exist on#'
paths:
- src/Lang/Time.php
- src/Lang/I18N.php
- src/Net/HttpClient.php
-
message: '#Cannot assign offset#'
paths:
- src/Net/Config.php
- src/Net/SmtpClient.php
-
message: '#Property (.+) does not accept#'
path: src/Net/HttpClient.php
-
message: '#Cannot call method#'
paths:
- src/AppMin.php
- src/Data/Database.php
-
message: '#Cannot access property#'
paths:
- src/Application.php
- src/AppMin.php
- src/FileSystem/Security.php
- src/Net/Config.php