Skip to content

Commit c083ff3

Browse files
committed
Clean up type declarations
1 parent 0835a6c commit c083ff3

47 files changed

Lines changed: 178 additions & 194 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/AdminBar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public static function listInvalidations( int $max_items = 5 ) {
254254
}
255255
}
256256

257-
public static function listInvalidationsInProgress( int $max_items = 5 ) {
257+
public static function listInvalidationsInProgress( int $max_items = 5 ): ?array {
258258
$invalidations = self::listInvalidations( $max_items );
259259
if ( ! $invalidations ) {
260260
return null;

src/CLI/Args.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use WP_CLI;
77

88
class Args {
9+
/**
10+
* @param array<int, mixed> $args
11+
*/
912
public static function parse(
1013
array $args,
1114
?array $assoc_args = null,

src/CrawledFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static function removeOutdated( \Iterator $paths ): \Iterator {
195195
// Delete previously generated files under the directories,
196196
// both the crawled and the processed.
197197
array_map(
198-
function ( $dir ) use ( $path ): void {
198+
function ( string $dir ) use ( $path ): void {
199199
$file_path = FilesHelper::getFilePath( $dir, $path->path );
200200
$suffix = ltrim( $file_path, '/' );
201201
$full_path = trailingslashit( $dir ) . $suffix;

src/Crawler.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,13 @@
2525

2626
class Crawler {
2727

28-
/**
29-
* @var Client
30-
*/
31-
private $client;
28+
private readonly \GuzzleHttp\Client $client;
3229

3330
private readonly Uri $site_uri;
3431

35-
/**
36-
* @var integer
37-
*/
38-
private $crawled = 0;
32+
private int $crawled = 0;
3933

40-
/**
41-
* @var integer
42-
*/
43-
private $cache_hits = 0;
34+
private int $cache_hits = 0;
4435

4536
private int $concurrency;
4637

@@ -145,6 +136,9 @@ public function crawlComplete(): void {
145136
do_action( Controller::getHookName( 'crawling_complete' ), $args );
146137
}
147138

139+
/**
140+
* @param string[] $site_urls
141+
*/
148142
public function crawlPath( PathInfo $detected, array $site_urls ): PromiseInterface {
149143
$absolute_uri = URLHelper::normalize( $this->site_uri . $detected->path );
150144
try {
@@ -158,7 +152,7 @@ public function crawlPath( PathInfo $detected, array $site_urls ): PromiseInterf
158152
}
159153

160154
return $this->client->sendAsync( $request )->then(
161-
function ( $response ) use ( &$detected, &$site_urls ) {
155+
function ( $response ) use ( &$detected, &$site_urls ): array {
162156
$status = $response->getStatusCode();
163157

164158
if ( in_array( $status, STATIC_DEPLOY_REDIRECT_CODES, true ) ) {
@@ -202,7 +196,7 @@ function ( $response ) use ( &$detected, &$site_urls ) {
202196
'path' => $path_info,
203197
];
204198
},
205-
function () use ( &$detected ) {
199+
function () use ( &$detected ): array {
206200
return [
207201
'error' => 'Error crawling ' . $detected->path,
208202
'path' => $detected,

src/DetectPluginAssets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function detect(
4141
}
4242

4343
$active_plugin_dirs = array_map(
44-
function ( $active_plugin ) {
44+
function ( int|string $active_plugin ): string {
4545
$dir = explode( '/', $active_plugin )[0];
4646
if ( STATIC_DEPLOY_DEBUG ) {
4747
WsLog::d( "Active plugin dir: {$dir}" );

src/DirectDeployer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
namespace StaticDeploy;
99

1010
class DirectDeployer {
11-
private $crawler;
12-
private $deployer;
11+
private readonly Crawler $crawler;
12+
private readonly object $deployer;
1313
public DirectDeployConfig $config;
14-
private $processor;
14+
private readonly PostProcessor $processor;
1515
public bool $ready = false;
16-
private $url_discovery;
16+
private readonly URLDiscovery $url_discovery;
1717

1818
public function __construct(
1919
?DirectDeployConfig $config = null,

src/FileFiltering.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FileFiltering {
88
* @var array<FileIgnorePattern>
99
* Files and directories to ignore
1010
*/
11-
private $patterns_to_ignore = [];
11+
private array $patterns_to_ignore = [];
1212

1313
public function __construct() {
1414
$paths_to_ignore = Options::getLineDelimitedBlobValue( 'pathsToIgnore' );
@@ -38,7 +38,7 @@ public function crawlableFiles(
3838
$filter_iter = new \RecursiveCallbackFilterIterator(
3939
$dir_iter,
4040
// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter
41-
function ( $current, $key, $iterator ) use ( $abs_base_dir ) {
41+
function ( $current, $key, $iterator ) use ( $abs_base_dir ): bool {
4242
// Filter out both directories and files
4343
foreach ( $this->patterns_to_ignore as $pattern_to_ignore ) {
4444
if ( $pattern_to_ignore->matches( $abs_base_dir, $current ) ) {

src/FileIgnorePattern.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class FileIgnorePattern {
1010
* @var bool
1111
* Match only directories and not files.
1212
*/
13-
private $only_directories;
13+
private bool $only_directories;
1414

1515
/**
1616
* @var string
1717
* Regex tested against relative URLs.
1818
*/
19-
private $url_regex;
19+
private readonly string $url_regex;
2020

2121
/**
2222
* Following gitignore rules:

src/JobQueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public static function setStatus( int $id, string $status ): void {
267267
Db::query(
268268
$query,
269269
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
270-
on_error: function ( $error ) use ( $query ) {
270+
on_error: function ( $error ) use ( $query ): int|bool {
271271
// Try to create status_update_at column
272272
self::createTable();
273273
return Db::query( $query );

src/Local/LocalDeployer.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ class LocalDeployer {
1414

1515
const DEFAULT_NAMESPACE = 'static-deploy-addon-local/default';
1616

17-
/**
18-
* @var integer
19-
*/
20-
private $deployed_ct = 0;
17+
private int $deployed_ct = 0;
2118

22-
/**
23-
* @var integer
24-
*/
25-
private $deploy_cache_ct = 0;
19+
private int $deploy_cache_ct = 0;
2620

27-
/**
28-
* @var integer
29-
*/
30-
private $deploy_error_ct = 0;
21+
private int $deploy_error_ct = 0;
3122

3223
public static function getDeployerSlug(): string {
3324
return 'static-deploy-addon-local';
3425
}
3526

27+
/**
28+
* @return array<string, string>
29+
*/
3630
public static function getDeployerData(): array {
3731
return [
3832
'description' => 'Deploys to a local directory',

0 commit comments

Comments
 (0)