Skip to content

Commit 5bad3df

Browse files
committed
More phpstan cleanup
Suppress error messages inside test cases that are checking for validity of normalization
1 parent 573e452 commit 5bad3df

9 files changed

Lines changed: 90 additions & 99 deletions

File tree

include/branches.inc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ function compare_version(array $arrayA, string $versionB)
380380
return 0;
381381
}
382382

383-
function version_array(string $version, ?int $length = null)
383+
function version_array(string $version, ?int $length = null): mixed
384384
{
385385
$versionArray = array_map(
386386
'intval',
@@ -426,7 +426,10 @@ function get_current_release_for_branch(int $major, ?int $minor): ?string {
426426

427427

428428
// Get latest release version and info.
429-
function release_get_latest() {
429+
/**
430+
* @return array{mixed,mixed}
431+
*/
432+
function release_get_latest(): array {
430433
$RELEASES = Branches::getReleaseData();
431434

432435
$version = '0.0.0';
@@ -443,7 +446,7 @@ function release_get_latest() {
443446
return [$version, $current];
444447
}
445448

446-
function show_source_releases()
449+
function show_source_releases(): void
447450
{
448451
$RELEASES = Branches::getReleaseData();
449452

include/gpg-keys.inc

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

33
use phpweb\Releases\Branches;
44

5-
require __DIR__ . '/branches.inc';
6-
75
// GPG keys used for signing releases.
86

97
function gpg_key_get(string $rm): ?string {

phpstan-baseline.neon

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ parameters:
3030
count: 1
3131
path: include/branches.inc
3232

33-
-
34-
message: '#^Function get_active_branches\(\) has parameter \$include_recent_eols with no type specified\.$#'
35-
identifier: missingType.parameter
36-
count: 1
37-
path: include/branches.inc
38-
3933
-
4034
message: '#^Function get_all_branches\(\) has no return type specified\.$#'
4135
identifier: missingType.return
@@ -109,8 +103,8 @@ parameters:
109103
path: include/branches.inc
110104

111105
-
112-
message: '#^Function version_array\(\) has no return type specified\.$#'
113-
identifier: missingType.return
106+
message: '#^Offset ''note'' on array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\} in isset\(\) does not exist\.$#'
107+
identifier: isset.offset
114108
count: 1
115109
path: include/branches.inc
116110

@@ -120,12 +114,30 @@ parameters:
120114
count: 2
121115
path: include/branches.inc
122116

117+
-
118+
message: '#^Parameter \#2 \$timestamp of function date expects int\|null, int\|false given\.$#'
119+
identifier: argument.type
120+
count: 1
121+
path: include/branches.inc
122+
123123
-
124124
message: '#^Parameter \#3 \$length of function substr expects int\|null, int\<0, max\>\|false given\.$#'
125125
identifier: argument.type
126126
count: 2
127127
path: include/branches.inc
128128

129+
-
130+
message: '#^Parameter \#3 \$length of function substr expects int\|null, int\|false given\.$#'
131+
identifier: argument.type
132+
count: 1
133+
path: include/branches.inc
134+
135+
-
136+
message: '#^Result of && is always false\.$#'
137+
identifier: booleanAnd.alwaysFalse
138+
count: 1
139+
path: include/branches.inc
140+
129141
-
130142
message: '#^Function bugfix\(\) has parameter \$number with no type specified\.$#'
131143
identifier: missingType.parameter
@@ -1314,30 +1326,12 @@ parameters:
13141326
count: 1
13151327
path: include/site.inc
13161328

1317-
-
1318-
message: '#^Function release_get_latest\(\) has no return type specified\.$#'
1319-
identifier: missingType.return
1320-
count: 1
1321-
path: include/version.inc
1322-
1323-
-
1324-
message: '#^Function show_source_releases\(\) has no return type specified\.$#'
1325-
identifier: missingType.return
1326-
count: 1
1327-
path: include/version.inc
1328-
13291329
-
13301330
message: '#^Offset ''announcement'' on array\{version\: ''8\.2\.31'', date\: ''07 May 2026'', tags\: array\{''security''\}, sha256\: array\{''tar\.gz''\: ''083c2f61cc5f527eb29…'', ''tar\.bz2''\: ''948183fa04cf261c9b9…'', ''tar\.xz''\: ''95eae411d594fe6f6e5…''\}\}\|array\{version\: ''8\.3\.31'', date\: ''07 May 2026'', tags\: array\{''security''\}, sha256\: array\{''tar\.gz''\: ''4e7baaf0a690e954a20…'', ''tar\.bz2''\: ''e6986b1fd37eb254021…'', ''tar\.xz''\: ''66410cee07f4b2baeb0…''\}\}\|array\{version\: ''8\.4\.22'', date\: ''04 Jun 2026'', tags\: array\{\}, sha256\: array\{''tar\.gz''\: ''a012c2c9724baf214a7…'', ''tar\.bz2''\: ''4b16e7e2c384ce25e07…'', ''tar\.xz''\: ''696c0f6ad92e94c5905…''\}\}\|array\{version\: ''8\.5\.7'', date\: ''04 Jun 2026'', tags\: array\{\}, sha256\: array\{''tar\.gz''\: ''e5eba93fd6dd3241d0e…'', ''tar\.bz2''\: ''4ef9355f784d4b32015…'', ''tar\.xz''\: ''01ba2ed1c2658dacf91…''\}\} on left side of \?\? does not exist\.$#'
13311331
identifier: nullCoalesce.offset
13321332
count: 1
13331333
path: include/version.inc
13341334

1335-
-
1336-
message: '#^Parameter \#3 \$length of function substr expects int\|null, int\|false given\.$#'
1337-
identifier: argument.type
1338-
count: 1
1339-
path: include/version.inc
1340-
13411335
-
13421336
message: '#^Variable \$SIDEBAR_DATA might not be defined\.$#'
13431337
identifier: variable.undefined
@@ -2323,10 +2317,16 @@ parameters:
23232317
path: public/releases/feed.php
23242318

23252319
-
2326-
message: '#^Variable \$RELEASES might not be defined\.$#'
2327-
identifier: variable.undefined
2320+
message: '#^Cannot access offset ''date'' on array\{version\: string, announcement\: bool, tags\: list\<string\>, date\: string, source\: list\<array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\}\>\}\|false\.$#'
2321+
identifier: offsetAccess.nonOffsetAccessible
23282322
count: 1
2329-
path: public/releases/feed.php
2323+
path: public/releases/index.php
2324+
2325+
-
2326+
message: '#^Cannot access offset ''supported_versions'' on array\{version\: string, announcement\: bool, tags\: list\<string\>, date\: string, source\: list\<array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\}\>\}\|false\.$#'
2327+
identifier: offsetAccess.nonOffsetAccessible
2328+
count: 1
2329+
path: public/releases/index.php
23302330

23312331
-
23322332
message: '#^Function mk_rel\(\) has parameter \$announcement with no value type specified in iterable type array\.$#'
@@ -2347,21 +2347,27 @@ parameters:
23472347
path: public/releases/index.php
23482348

23492349
-
2350-
message: '#^Parameter \#1 \.\.\.\$arg1 of function max expects non\-empty\-array, list\<int\|string\> given\.$#'
2351-
identifier: argument.type
2350+
message: '#^Offset ''announcement'' on array\{version\: string, announcement\: bool, tags\: list\<string\>, date\: string, source\: list\<array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\}\>\} on left side of \?\? always exists and is not nullable\.$#'
2351+
identifier: nullCoalesce.offset
23522352
count: 1
23532353
path: public/releases/index.php
23542354

23552355
-
2356-
message: '#^Variable \$OLDRELEASES might not be defined\.$#'
2357-
identifier: variable.undefined
2358-
count: 3
2356+
message: '#^Offset ''museum'' on array\{version\: string, announcement\: bool, tags\: list\<string\>, date\: string, source\: list\<array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\}\>\} on left side of \?\? does not exist\.$#'
2357+
identifier: nullCoalesce.offset
2358+
count: 1
23592359
path: public/releases/index.php
23602360

23612361
-
2362-
message: '#^Variable \$RELEASES might not be defined\.$#'
2363-
identifier: variable.undefined
2364-
count: 2
2362+
message: '#^Offset ''source'' on array\{version\: string, announcement\: bool, tags\: list\<string\>, date\: string, source\: list\<array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\}\>\} on left side of \?\? always exists and is not nullable\.$#'
2363+
identifier: nullCoalesce.offset
2364+
count: 1
2365+
path: public/releases/index.php
2366+
2367+
-
2368+
message: '#^Offset ''windows'' on array\{version\: string, announcement\: bool, tags\: list\<string\>, date\: string, source\: list\<array\{filename\: string, name\: string, md5\?\: string, sha256\?\: string, date\: string\}\>\} on left side of \?\? does not exist\.$#'
2369+
identifier: nullCoalesce.offset
2370+
count: 1
23652371
path: public/releases/index.php
23662372

23672373
-
@@ -2430,18 +2436,6 @@ parameters:
24302436
count: 1
24312437
path: public/submit-event.php
24322438

2433-
-
2434-
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, float\|string given\.$#'
2435-
identifier: argument.type
2436-
count: 1
2437-
path: public/supported-versions.php
2438-
2439-
-
2440-
message: '#^Possibly invalid array key type float\|string\.$#'
2441-
identifier: offsetAccess.invalidOffset
2442-
count: 1
2443-
path: public/supported-versions.php
2444-
24452439
-
24462440
message: '#^Variable \$COUNTRIES might not be defined\.$#'
24472441
identifier: variable.undefined

phpstan.neon.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ parameters:
1919
- include/releases.inc
2020
- include/pregen-news.inc
2121
- include/pregen-confs.inc
22+
23+
# Can do cleanup after, without the previous items themsleves being new errors
24+
reportUnmatchedIgnoredErrors: false
25+
26+
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
27+
editorUrlTitle: '%%relFile%%:%%line%%'

public/releases/branches.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function formatDate($date = null) {
1515
foreach ($releases as $branch => $release) {
1616
$current[$branch] = [
1717
'branch' => $branch,
18-
'latest' => ($release['version'] ?? null),
18+
'latest' => $release['version'],
1919
'state' => Branches::getBranchSupportStatus($branch),
2020
'initial_release' => formatDate(Branches::getBranchReleaseDate($branch)),
2121
'active_support_end' => formatDate(Branches::getBranchBugsEOLDate($branch)),

public/releases/index.php

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

55
$_SERVER['BASE_PAGE'] = 'releases/index.php';
66
require_once __DIR__ . '/../../include/prepend.inc';
7-
require_once __DIR__ . "/../../include/branches.inc";
87

98
$RELEASES = Branches::getReleaseData();
109
$OLDRELEASES = Branches::getOldReleaseData();
@@ -58,9 +57,7 @@
5857
}
5958
} else {
6059
foreach ($RELEASES as $major => $release) {
61-
$version = key($release);
6260
$r = current($release);
63-
$r["version"] = $version;
6461
$r['supported_versions'] = $supportedVersions[$major] ?? [];
6562
$machineReadable[$major] = $r;
6663
}
@@ -89,6 +86,8 @@
8986
</p>\n";
9087

9188
$active_majors = array_keys($RELEASES);
89+
assert(!empty($active_majors));
90+
9291
$latest = max($active_majors);
9392
foreach ($OLDRELEASES as $major => $a) {
9493
echo '<a id="v' . $major . '"></a>';

src/Releases/Branches.php

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
use function ksort;
1212
use function strlen;
1313
use function strncmp;
14-
use function strpos;
15-
use function strtotime;
16-
use function substr;
1714
use function version_compare;
1815

1916
/**
@@ -174,6 +171,10 @@ public static function get_all_branches(): array
174171
return $branches;
175172
}
176173

174+
/**
175+
* @param bool $include_recent_eols
176+
* @return array<int, array<string, NormalizedReleaseStruct>>
177+
*/
177178
public static function active(bool $include_recent_eols = true): array
178179
{
179180
$recentInterval = new DateInterval('P28D');
@@ -211,15 +212,18 @@ public static function active(bool $include_recent_eols = true): array
211212
return $branches;
212213
}
213214

214-
/* If you provide an array to $always_include, note that the version numbers
215-
* must be in $RELEASES _and_ must be the full version number, not the branch:
216-
* ie provide array('5.3.29'), not array('5.3'). */
217-
public static function eol(?bool $always_include = null): array
215+
/**
216+
* @return array<int, array<string, array{
217+
* date: string,
218+
* link: string,
219+
* version: string,
220+
* }>>
221+
*/
222+
public static function eol(): array
218223
{
219224
$GLOBAL_OLDRELEASES = self::getOldReleaseData();
220225
$GLOBAL_RELEASES = self::getReleaseData();
221226

222-
$always_include = $always_include ?: [];
223227
$branches = [];
224228
$now = new DateTime();
225229

@@ -231,8 +235,8 @@ public static function eol(?bool $always_include = null): array
231235
if (!isset($branches[$major][$branch])
232236
|| version_compare($version, $branches[$major][$branch]['version'], 'gt')
233237
) {
234-
$branches[$major][$branch] = [
235-
'date' => strtotime($release['date']),
238+
$branches[(string)$major][$branch] = [
239+
'date' => $release['date'],
236240
'link' => "/releases#$version",
237241
'version' => $version,
238242
];
@@ -251,31 +255,6 @@ public static function eol(?bool $always_include = null): array
251255
if (isset($branches[$major][$branch])) {
252256
unset($branches[$major][$branch]);
253257
}
254-
} else {
255-
/* Add the release information to the EOL branches array, since it
256-
* should be newer than the information we got from $OLDRELEASES. */
257-
$always_include[] = $version;
258-
}
259-
}
260-
}
261-
262-
// Include any release in the always_include list that's in $RELEASES.
263-
if ($always_include) {
264-
foreach ($always_include as $version) {
265-
$parts = explode('.', $version);
266-
$major = $parts[0];
267-
268-
if (isset($GLOBAL_RELEASES[$major][$version])) {
269-
$release = $GLOBAL_RELEASES[$major][$version];
270-
$branch = self::versionToBranch($version);
271-
272-
if ($branch) {
273-
$branches[$major][$branch] = [
274-
'date' => strtotime($release['source'][0]['date']),
275-
'link' => "/downloads#v$version",
276-
'version' => $version,
277-
];
278-
}
279258
}
280259
}
281260
}
@@ -320,10 +299,7 @@ public static function getFinalReleaseForBranch(string $branch): ?array
320299
$GLOBAL_OLDRELEASES = self::getOldReleaseData();
321300
$GLOBAL_RELEASES = self::getReleaseData();
322301
$branch = self::versionToBranch($branch);
323-
if (!$branch) {
324-
return null;
325-
}
326-
$major = substr($branch, 0, strpos($branch, '.'));
302+
[$major] = explode('.', $branch);
327303

328304
$last = "$branch.0";
329305
foreach ($GLOBAL_OLDRELEASES[$major] as $version => $release) {
@@ -368,7 +344,7 @@ public static function getBranchBugsEOLDate(string $branch): ?DateTime
368344
}
369345

370346
// Extend the release cycle to the end of the year
371-
return $date?->setDate($date->format('Y'), 12, 31);
347+
return $date?->setDate((int)$date->format('Y'), 12, 31);
372348
}
373349

374350
public static function getBranchSecurityEOLDate(string $branch): ?DateTime
@@ -396,7 +372,7 @@ public static function getBranchSecurityEOLDate(string $branch): ?DateTime
396372
$date = $date?->add(new DateInterval('P4Y'));
397373

398374
// Extend the release cycle to the end of the year
399-
return $date?->setDate($date->format('Y'), 12, 31);
375+
return $date?->setDate((int)$date->format('Y'), 12, 31);
400376
}
401377

402378
public static function getBranchReleaseDate(string $branch): ?DateTime

src/autoload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
require_once __DIR__ . '/../include/branches.inc';
4+
35
/**
46
* @see https://github.com/php-fig/fig-standards/blob/a1a0674a742c9d07c5dd450209fb33b115ee7b40/accepted/PSR-4-autoloader-examples.md#closure-example
57
*/

0 commit comments

Comments
 (0)