Skip to content

Commit 2d29643

Browse files
committed
added NarrowReturnType extension to remove |false from native functions and methods
1 parent 2c321dc commit 2d29643

6 files changed

Lines changed: 623 additions & 0 deletions

File tree

extension-narrowReturnType.neon

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
services:
2+
-
3+
class: Nette\PHPStan\Type\NarrowReturnTypeResolver([
4+
# PHP still returns |false, but it's trivial — indicates a programming error or unrealistic state
5+
# ---------
6+
7+
# Regex (false = invalid pattern)
8+
preg_match
9+
preg_split
10+
preg_grep
11+
12+
# JSON
13+
json_encode
14+
15+
# Output buffering (false = no active buffer)
16+
ob_get_clean
17+
ob_get_contents
18+
ob_get_flush
19+
ob_get_length
20+
21+
# Compression (false = error that won't happen with valid data)
22+
gzcompress
23+
gzencode
24+
gzdeflate
25+
zlib_encode
26+
deflate_add
27+
28+
# System information
29+
getcwd
30+
gethostname
31+
getmypid
32+
getmyuid
33+
getmygid
34+
php_ini_loaded_file
35+
sys_getloadavg
36+
37+
# mb_string (false = invalid encoding)
38+
mb_chr
39+
mb_ord
40+
mb_split
41+
42+
# Operations on a valid file handle
43+
fstat
44+
ftell
45+
fwrite
46+
fputs
47+
fputcsv
48+
49+
# Date/Time
50+
date_timezone_get
51+
52+
# Intl
53+
normalizer_normalize
54+
msgfmt_format
55+
56+
# GD operations on a valid resource
57+
imageaffine
58+
imageaffinematrixconcat
59+
imageaffinematrixget
60+
imagecolorallocate
61+
imagecolorallocatealpha
62+
imagecolorat
63+
imagecrop
64+
imagecropauto
65+
imageftbbox
66+
imagefttext
67+
imagettfbbox
68+
imagettftext
69+
imagerotate
70+
imagescale
71+
imagegrabscreen
72+
imagegrabwindow
73+
74+
# Curl
75+
curl_copy_handle
76+
curl_escape
77+
curl_unescape
78+
79+
# Openssl (false = invalid algorithm/parameters)
80+
openssl_cipher_iv_length
81+
openssl_digest
82+
83+
# Session (false = no active session)
84+
session_id
85+
session_name
86+
session_module_name
87+
session_save_path
88+
session_cache_limiter
89+
session_encode
90+
91+
# Other
92+
convert_uudecode
93+
nl_langinfo
94+
image_type_to_extension
95+
curl_version
96+
97+
# Intl
98+
Normalizer::normalize
99+
NumberFormatter::format
100+
NumberFormatter::formatCurrency
101+
IntlDateFormatter::format
102+
Transliterator::transliterate
103+
104+
# DOM
105+
DOMDocument::save
106+
DOMDocument::saveHTML
107+
DOMDocument::saveHTMLFile
108+
DOMDocument::saveXML
109+
DOMText::splitText
110+
111+
112+
# PHPStan reports |false but current PHP no longer returns false
113+
# ---------
114+
115+
hash
116+
hash_hmac
117+
hash_hkdf
118+
hash_pbkdf2
119+
array_combine
120+
explode
121+
str_split
122+
mb_strlen
123+
mb_encoding_aliases
124+
fpassthru
125+
date_add
126+
date_sub
127+
date_date_set
128+
date_isodate_set
129+
date_time_set
130+
date_timestamp_set
131+
date_timezone_set
132+
imagecolorexact
133+
imagecolorexactalpha
134+
openssl_random_pseudo_bytes
135+
substr_compare
136+
sleep
137+
long2ip
138+
fgetss
139+
gzgetss
140+
gzpassthru
141+
jdtounix
142+
apache_request_headers
143+
apache_response_headers
144+
145+
DateInterval::createFromDateString
146+
PDOStatement::fetchAll
147+
SplFileObject::fgetss
148+
])
149+
tags: [phpstan.broker.expressionTypeResolverExtension]

extension.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
parameters:
2+
3+
includes:
4+
- extension-narrowReturnType.neon

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ parameters:
99
analyse:
1010
- tests/data/*
1111

12+
ignoreErrors:
13+
-
14+
identifiers: [phpstanApi.method]
15+
path: src/Type/NarrowReturnTypeResolver.php
16+
1217
includes:
1318
- extension.neon

0 commit comments

Comments
 (0)