Skip to content

Commit 96332d4

Browse files
committed
links.php: mark params as nullable
Implicitly marking parameter as nullable is deprecated
1 parent c17a6ac commit 96332d4

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

tools/links/links.config.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
$exclusionTests = array_merge_recursive(UrlTester::getDefaultExclusionTests(), [
2424
'url' => [
25-
function (string $url, string $file = null): bool {
25+
function (string $url, ?string $file = null): bool {
2626
// docs/index.md content is not Markdown but HTML with server URLs
2727
return 'docs/index.md' === $file && str_starts_with($url, 'docs/');
2828
},
29-
function (string $url, string $file = null): bool {
29+
function (string $url, ?string $file = null): bool {
3030
// ibexa.co APIs needing authentication, namespaces, commercial aliases, etc.
3131
return str_starts_with($url, 'https://updates.ibexa.co') // 401
3232
|| str_starts_with($url, 'https://support.ibexa.co') // 302 → /login
@@ -43,18 +43,18 @@ function (string $url, string $file = null): bool {
4343
|| str_starts_with($url, 'https://reco.perso.ibexa.co') // 403
4444
;
4545
},
46-
function (string $url, string $file = null): bool {
46+
function (string $url, ?string $file = null): bool {
4747
// Third parties APIs, namespaces, etc.
4848
return str_starts_with($url, 'https://api.fastly.com') // 301 or 403
4949
|| str_starts_with($url, 'https://unsplash.com') // 405
5050
|| str_starts_with($url, 'http://docbook.org/ns/') // 301
5151
|| str_starts_with($url, 'http://www.w3.org/1999/xlink') // 301 → https
5252
;
5353
},
54-
function (string $url, string $file = null): bool {
54+
function (string $url, ?string $file = null): bool {
5555
return (bool)preg_match('@(https?:)?//([a-z]+\.)?(localhost|127.0.0.1)(:[0-9]+)?(/.*|$)@', $url);
5656
},
57-
function (string $url, string $file = null): bool {
57+
function (string $url, ?string $file = null): bool {
5858
// Fake, placeholders, local servers, etc.
5959
return str_contains($url, 'foobar.com')
6060
|| str_contains($url, 'mydomain.com')
@@ -71,14 +71,14 @@ function (string $url, string $file = null): bool {
7171
|| str_contains($url, '//my.varnish.server')
7272
;
7373
},
74-
function (string $url, string $file = null): bool {
74+
function (string $url, ?string $file = null): bool {
7575
return str_starts_with($url, '/assets/')
7676
|| str_contains($url, '{{ asset(');
7777
},
78-
function (string $url, string $file = null): bool {
78+
function (string $url, ?string $file = null): bool {
7979
return false !== strpos($url, 'javascript:');
8080
},
81-
function (string $url, string $file = null): bool {
81+
function (string $url, ?string $file = null): bool {
8282
return str_contains($url, '{{ path(')
8383
//|| str_contains($url, '{{ ez_path(')
8484
|| str_contains($url, '{{ ibexa_path(')
@@ -89,39 +89,39 @@ function (string $url, string $file = null): bool {
8989
|| str_contains($url, '{{ ibexa_checkout_step_url(')
9090
;
9191
},
92-
function (string $url, string $file = null): bool {
92+
function (string $url, ?string $file = null): bool {
9393
return str_ends_with($file, '/rest_api_authentication.md')
9494
&& str_ends_with($url, 'web+ez:DELETE /content/locations/1/2');
9595
},
96-
function (string $url, string $file = null): bool {
96+
function (string $url, ?string $file = null): bool {
9797
return str_ends_with($file, '/file_url_handling.md')
9898
&& (str_contains($url, 'http://`') || str_contains($url, 'ftp://`'));
9999
},
100100
],
101101
'location' => [
102-
function (string $url, string $location, string $file = null): bool {
102+
function (string $url, string $location, ?string $file = null): bool {
103103
return $url === $location && str_starts_with($url, 'https://twitter.com/');
104104
},
105-
function (string $url, string $location, string $file = null): bool {
105+
function (string $url, string $location, ?string $file = null): bool {
106106
return str_starts_with($url, 'https://youtu.be/') && explode('/', $url)[3] . '&feature=youtu.be' === explode('?v=', $location)[1];
107107
},
108-
function (string $url, string $location, string $file = null): bool {
108+
function (string $url, string $location, ?string $file = null): bool {
109109
return str_starts_with($url, 'https://www.facebook.com/') && str_starts_with($location, 'https://www.facebook.com/unsupportedbrowser');
110110
},
111-
function (string $url, string $location, string $file = null): bool {
111+
function (string $url, string $location, ?string $file = null): bool {
112112
return 'https://www.json.org/' === $url && 'https://www.JSON.org/json-en.html' === $location;
113113
},
114114
],
115115
'fragment' => [
116-
/*function (string $url, string $file = null): bool {
116+
/*function (string $url, ?string $file = null): bool {
117117
return str_ends_with($file, '.md') && (
118118
// ## Commerce [[% include 'snippets/commerce_badge.md' %]]
119119
str_ends_with($url, '/permission_use_cases.md#commerce')
120120
// ### Ensure proper Captcha behavior [[% include 'snippets/experience_badge.md' %]] [[% include 'snippets/commerce_badge.md' %]]
121121
|| str_ends_with($url, '/reverse_proxy.md#ensure-proper-captcha-behavior')
122122
);
123123
},*/
124-
function (string $url, string $file = null): bool {
124+
function (string $url, ?string $file = null): bool {
125125
return str_starts_with($url, 'https://classic.yarnpkg.com/en/docs/')
126126
|| str_starts_with($url, 'https://ddev.readthedocs.io/');
127127
},

tools/links/links.php

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

33
/**
4-
* Store a internal or external URL,
4+
* URL to be tested.
5+
*
6+
* Store an internal or external URL,
57
* optionally the text of the corresponding link,
68
* optionally where it has been found (in which file at which line),
79
* and offers to test/check the existence of URL's destination.
@@ -55,7 +57,8 @@ class TestableUrl
5557
public const DEFAULT_SCHEME = 'https';
5658

5759
/**
58-
* Represent a URL, potentially extracted from a file, which can be tested
60+
* Represent a URL, potentially extracted from a file, which can be tested.
61+
*
5962
* @param string $url The URL itself
6063
* @param string|null $text The text of the link to the URL
6164
* @param string|null $file The file in which the URL has been found
@@ -64,7 +67,7 @@ class TestableUrl
6467
* @param bool|string|null $find By default, URL is considered absolute or relative; If true, the URL will be considered partial and the target must be searched to solve the URL; If a string is given, this string will be used as a search prefix
6568
* @param bool $test Set to true to test the URL immediately at construction time
6669
*/
67-
public function __construct(string $url, string $text = null, string $file = null, string $line = null, array $replacements = null, mixed $find = false, bool $test = false)
70+
public function __construct(string $url, ?string $text = null, ?string $file = null, ?string $line = null, ?array $replacements = null, mixed $find = false, bool $test = false)
6871
{
6972
$this->url = $url;
7073
$this->text = $text;
@@ -78,7 +81,8 @@ public function __construct(string $url, string $text = null, string $file = nul
7881
}
7982

8083
/**
81-
* Test/check the URL and fill its related properties (code, headers, etc.)
84+
* Test/check the URL and fill its related properties (code, headers, etc.).
85+
*
8286
* @param bool $testLocations If it's a redirection (through a `location` header), test the redirect target
8387
* @param bool $testFragment If the eventual fragment/hash/anchor part should be tested
8488
* @param bool $cache Test again even if already tested
@@ -99,7 +103,8 @@ public function test(bool $testLocations = true, bool $testFragment = true, bool
99103
}
100104

101105
/**
102-
* Has the URL been tested/checked
106+
* Has the URL been tested/checked.
107+
*
103108
* @return bool
104109
*/
105110
public function isTested(): bool
@@ -109,6 +114,7 @@ public function isTested(): bool
109114

110115
/**
111116
* The raw URL
117+
*
112118
* @return string
113119
*/
114120
public function getUrl(): string
@@ -184,9 +190,12 @@ public static function solveRelativePath(string $sourcePath, string $targetPath)
184190
}
185191

186192
/**
193+
* Get testable URI.
194+
*
187195
* If the file where the URL has been found is known,
188196
* solve relative path of internal URL
189-
* or add file URL to fragment
197+
* or add file URL to fragment.
198+
*
190199
* @return string
191200
*/
192201
public function getSolvedUrl(): string
@@ -269,18 +278,19 @@ public function isInternal(): bool
269278
public const NOT_TESTABLE_CODE = 999;
270279

271280
/**
272-
* Test/check a URL and return result data
281+
* Test/check a URL and return result data.
282+
*
273283
* If the URL is external, return the response HTTP headers (as an array), the HTTP status code as an integer, the eventual `location` HTTP header used for redirection, if there is a fragment to test, if that fragment has been found in the content available at the URL
274284
* If the URL is internal, return the code 200 if the target exists, 404 if not, if there is a fragment to test, if that fragment has been found in the content available at the URL
275285
* @param string $url The URL istsel
276-
* @param bool|null $external If it's an external URL or not
286+
* @param bool|null $external If it's an external URL (`true`) or not (`false`), if `null`, the system try to guess it using {@see \TestableUrl::isExternalUrl()}
277287
* @param bool $testFragment If the eventual fragment/hash/anchor part should be tested
278288
* @param int $retryCount Number of retries on time out
279289
* @param int $retryDelay Delay in seconds before retrying
280290
* @param int $tryNumber Try number (first try is numbered 1)
281291
* @return array ['headers' => null|array, 'code' => int, 'location' => null|string, 'fragment_found' => null|bool]
282292
*/
283-
public static function testUrl(string $url, bool $external = null, bool $testFragment = true, int $retryCount = 1, int $retryDelay = 300, int $tryNumber = 1): array
293+
public static function testUrl(string $url, ?bool $external = null, bool $testFragment = true, int $retryCount = 1, int $retryDelay = 300, int $tryNumber = 1): array
284294
{
285295
$headers = null;
286296
$code = self::NOT_TESTABLE_CODE;

0 commit comments

Comments
 (0)