Skip to content

Commit 935a09b

Browse files
authored
Merge branch 'master' into fix-http-trailer-headers
2 parents 8223d0d + d060f04 commit 935a09b

21 files changed

Lines changed: 93 additions & 25 deletions

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ indent_style = space
1919
max_line_length = off
2020
trim_trailing_whitespace = false
2121

22+
[*.neon]
23+
indent_size = 4
24+
indent_style = space
25+
2226
[*.php]
2327
indent_size = 4
2428
indent_style = space

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
/compatibility_test export-ignore
55
/demo export-ignore
66
/tests export-ignore
7+
/utils/PHPStan export-ignore
78
.gitattributes export-ignore
89
.editorconfig export-ignore
910
.gitignore export-ignore
1011
ROADMAP.md export-ignore
1112
phpunit.xml.dist export-ignore
1213
.php-cs-fixer.dist.php export-ignore
14+
db.sql export-ignore
15+
phpstan.dist.neon export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ phpstan.neon
77
phpunit.xml
88
.php-cs-fixer.cache
99
.phpunit.cache/
10+
.phpunit.result.cache

autoloader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
*/
5858
class SimplePie_Autoloader
5959
{
60+
/** @var string */
6061
protected $path;
6162

6263
/**
@@ -72,7 +73,7 @@ public function __construct()
7273
*
7374
* @param string $class The name of the class to attempt to load.
7475
*/
75-
public function autoload($class)
76+
public function autoload(string $class): void
7677
{
7778
// Only load the class if it starts with "SimplePie"
7879
if (strpos($class, 'SimplePie') !== 0)

demo/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838

3939
// Output buffer
40-
function callable_htmlspecialchars($string)
40+
function callable_htmlspecialchars(string $string): string
4141
{
4242
return htmlspecialchars($string);
4343
}

library/SimplePie/Decode/HTML/Entities.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function parse()
7272
*
7373
* @access private
7474
* @return string|false The next byte, or false, if there is no more data
75+
* @phpstan-impure
7576
*/
7677
public function consume()
7778
{
@@ -547,6 +548,7 @@ public function entity()
547548
'zwnj;' => "\xE2\x80\x8C"
548549
];
549550

551+
$consumed = '';
550552
for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++) {
551553
// Cast for PHPStan on PHP < 8.0: We consumed as per the loop condition,
552554
// so `$this->consumed` is non-empty and the substr offset is valid.

phpstan.dist.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
- library/
66
- src/
77
- tests/
8+
- utils/
89

910
ignoreErrors:
1011
# Ignore that only one const exists atm

src/File.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ public function __construct(string $url, int $timeout = 10, int $redirects = 5,
121121
}
122122
unset($curl_options[CURLOPT_HTTPHEADER]);
123123
}
124-
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) {
124+
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.21.6', '>=')) {
125+
curl_setopt($fp, CURLOPT_ACCEPT_ENCODING, '');
126+
} else {
125127
curl_setopt($fp, CURLOPT_ENCODING, '');
126128
}
129+
/** @var non-empty-string $url */
127130
curl_setopt($fp, CURLOPT_URL, $url);
128-
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
129-
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
131+
curl_setopt($fp, CURLOPT_RETURNTRANSFER, true);
132+
curl_setopt($fp, CURLOPT_FAILONERROR, true);
130133
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
131134
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
132135
curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url));
@@ -144,7 +147,11 @@ public function __construct(string $url, int $timeout = 10, int $redirects = 5,
144147
$responseBody = curl_exec($fp);
145148
$responseHeaders .= "\r\n";
146149
if (curl_errno($fp) === CURLE_WRITE_ERROR || curl_errno($fp) === CURLE_BAD_CONTENT_ENCODING) {
147-
curl_setopt($fp, CURLOPT_ENCODING, 'none');
150+
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.21.6', '>=')) {
151+
curl_setopt($fp, CURLOPT_ACCEPT_ENCODING, 'none');
152+
} else {
153+
curl_setopt($fp, CURLOPT_ENCODING, 'none');
154+
}
148155
$responseHeaders = '';
149156
$responseBody = curl_exec($fp);
150157
$responseHeaders .= "\r\n";

src/HTTP/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private function add_header(string $name, string $value): void
243243
$headers[$name][] = $value;
244244
} else {
245245
// For PHPStan: should be enforced by template parameter but PHPStan is not smart enough.
246-
/** @var array<string, string>) */
246+
/** @var array<string,string> */
247247
$headers = &$this->headers;
248248
$headers[$name] .= ', ' . $value;
249249
}
@@ -258,7 +258,7 @@ private function replace_header(string $name, string $value): void
258258
$headers[$name] = [$value];
259259
} else {
260260
// For PHPStan: should be enforced by template parameter but PHPStan is not smart enough.
261-
/** @var array<string, string>) */
261+
/** @var array<string,string> */
262262
$headers = &$this->headers;
263263
$headers[$name] = $value;
264264
}

src/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ public function get_date(string $date_format = 'j F Y, g:i a')
672672
return $this->data['date']['parsed'];
673673

674674
default:
675-
return date($date_format, $this->data['date']['parsed']);
675+
return $this->data['date']['parsed'] !== null ? date($date_format, $this->data['date']['parsed']) : null;
676676
}
677677
}
678678

0 commit comments

Comments
 (0)