Skip to content

Commit 416ebba

Browse files
author
Leon
committed
fix linting
1 parent 5fc6f4b commit 416ebba

3 files changed

Lines changed: 32 additions & 25 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"classmap-authoritative": true
5656
},
5757
"scripts": {
58-
"phpstan": "vendor/bin/phpstan analyse",
58+
"phpstan": "php -d memory_limit=-1 vendor/bin/phpstan analyse",
5959
"phpcs": "vendor/bin/phpcs --standard=./tools/phpcs.xml --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/views/*.php ./",
6060
"phpcbf": "vendor/bin/phpcbf --standard=./tools/phpcs.xml --ignore=*/js/*,*/tests/*,*/admin/*,*/coverage/*,*.js,*/vendor/*,*/views/*.php ./",
6161
"phpunit": "vendor/bin/phpunit ./tests/unit/",

src/Controller.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public static function seedOptions() : void {
7373
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
7474

7575
$query_string =
76-
"INSERT IGNORE INTO $table_name (name, value, label, description) VALUES (%s, %s, %s, %s);";
76+
"INSERT IGNORE INTO $table_name (name, value, label, description) " .
77+
'VALUES (%s, %s, %s, %s);';
7778

7879
$query = $wpdb->prepare(
7980
$query_string,
@@ -253,7 +254,7 @@ public static function renderS3Page() : void {
253254

254255
public function deploy( string $processed_site_path, string $enabled_deployer ) : void {
255256
if ( $enabled_deployer !== 'wp2static-addon-s3' ) {
256-
return;
257+
return;
257258
}
258259

259260
\WP2Static\WsLog::l( 'S3 Addon deploying' );
@@ -284,7 +285,7 @@ public static function createOptionsTable() : void {
284285
// dbDelta doesn't handle unique indexes well.
285286
$indexes = $wpdb->query( "SHOW INDEX FROM $table_name WHERE key_name = 'name'" );
286287
if ( 0 === $indexes ) {
287-
$result = $wpdb->query( "CREATE UNIQUE INDEX name ON $table_name (name)" );
288+
$result = $wpdb->query( "CREATE UNIQUE INDEX name ON $table_name (name)" );
288289
if ( false === $result ) {
289290
\WP2Static\WsLog::l( "Failed to create 'name' index on $table_name." );
290291
}
@@ -495,14 +496,14 @@ public static function getValue( string $name ) : string {
495496
}
496497

497498
public function addOptionsPage() : void {
498-
add_submenu_page(
499-
null,
500-
'S3 Deployment Options',
501-
'S3 Deployment Options',
502-
'manage_options',
503-
'wp2static-addon-s3',
504-
[ $this, 'renderS3Page' ]
505-
);
499+
add_submenu_page(
500+
'',
501+
'S3 Deployment Options',
502+
'S3 Deployment Options',
503+
'manage_options',
504+
'wp2static-addon-s3',
505+
[ $this, 'renderS3Page' ]
506+
);
506507
}
507508
}
508509

src/Deployer.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ public function upload_files( string $processed_site_path ) : void {
8585
ltrim( $cache_key, '/' );
8686

8787
$mime_type = MimeTypes::GuessMimeType( $filename );
88-
if ( "text/" === substr( $mime_type, 0, 5 ) ) {
88+
if ( 'text/' === substr( $mime_type, 0, 5 ) ) {
8989
$mime_type = $mime_type . '; charset=UTF-8';
9090
}
9191

9292
$put_data['Key'] = $s3_key;
9393
$put_data['ContentType'] = $mime_type;
94-
$put_data_hash = md5( json_encode( $put_data ) );
94+
$put_data_hash = md5( (string) json_encode( $put_data ) );
9595
$put_data['Body'] = file_get_contents( $filename );
96-
$body_hash = md5( $put_data['Body'] );
96+
$body_hash = md5( (string) $put_data['Body'] );
9797
$hash = md5( $put_data_hash . $body_hash );
9898

9999
$is_cached = \WP2Static\DeployCache::fileisCached(
@@ -113,7 +113,7 @@ public function upload_files( string $processed_site_path ) : void {
113113

114114
if ( $cf_max_paths >= count( $cf_stale_paths ) ) {
115115
$cf_key = $cache_key;
116-
if ( 0 === substr_compare( $cf_key, '/index.html', -11) ) {
116+
if ( 0 === substr_compare( $cf_key, '/index.html', -11 ) ) {
117117
$cf_key = substr( $cf_key, 0, -10 );
118118
}
119119
array_push( $cf_stale_paths, $cf_key );
@@ -142,7 +142,7 @@ public function upload_files( string $processed_site_path ) : void {
142142

143143
$put_data['Key'] = $s3_key;
144144
$put_data['WebsiteRedirectLocation'] = $redirect['redirect_to'];
145-
$hash = md5( json_encode( $put_data ) );
145+
$hash = md5( (string) json_encode( $put_data ) );
146146

147147
$is_cached = \WP2Static\DeployCache::fileisCached(
148148
$cache_key,
@@ -161,7 +161,7 @@ public function upload_files( string $processed_site_path ) : void {
161161

162162
if ( $cf_max_paths >= count( $cf_stale_paths ) ) {
163163
$cf_key = $cache_key;
164-
if ( 0 === substr_compare( $cf_key, '/index.html', -11) ) {
164+
if ( 0 === substr_compare( $cf_key, '/index.html', -11 ) ) {
165165
$cf_key = substr( $cf_key, 0, -10 );
166166
}
167167
array_push( $cf_stale_paths, $cf_key );
@@ -170,7 +170,7 @@ public function upload_files( string $processed_site_path ) : void {
170170
}
171171

172172
$distribution_id = Controller::getValue( 'cfDistributionID' );
173-
$num_stale = count ( $cf_stale_paths );
173+
$num_stale = count( $cf_stale_paths );
174174
if ( $distribution_id && $num_stale > 0 ) {
175175
if ( $num_stale > $cf_max_paths ) {
176176
self::cloudfront_invalidate_all_items();
@@ -207,7 +207,7 @@ public static function s3_client() : \Aws\S3\S3Client {
207207
Controller::getValue( 's3SecretAccessKey' )
208208
),
209209
];
210-
} else if ( Controller::getValue( 's3Profile' ) ) {
210+
} elseif ( Controller::getValue( 's3Profile' ) ) {
211211
$client_options['profile'] = Controller::getValue( 's3Profile' );
212212
}
213213

@@ -241,7 +241,7 @@ public static function cloudfront_client() : \Aws\CloudFront\CloudFrontClient {
241241
'credentials' => $credentials,
242242
]
243243
);
244-
} else if ( Controller::getValue( 'cfProfile' ) ) {
244+
} elseif ( Controller::getValue( 'cfProfile' ) ) {
245245
// Use the specified profile.
246246
$client = \Aws\CloudFront\CloudFrontClient::factory(
247247
[
@@ -263,8 +263,12 @@ public static function cloudfront_client() : \Aws\CloudFront\CloudFrontClient {
263263
return $client;
264264
}
265265

266-
public static function create_invalidation( string $distribution_id, array $items )
267-
: string {
266+
/**
267+
* Create invalidation in CloudFront
268+
*
269+
* @param mixed[] $items mixed array
270+
*/
271+
public static function create_invalidation( string $distribution_id, array $items ) : string {
268272
$client = self::cloudfront_client();
269273

270274
return $client->createInvalidation(
@@ -289,8 +293,10 @@ public static function cloudfront_invalidate_all_items() : void {
289293
\WP2Static\WsLog::l( 'Invalidating all CloudFront paths' );
290294

291295
try {
292-
self::create_invalidation( Controller::getValue( 'cfDistributionID' ),
293-
[ '/*' ]);
296+
self::create_invalidation(
297+
Controller::getValue( 'cfDistributionID' ),
298+
[ '/*' ]
299+
);
294300
} catch ( AwsException $e ) {
295301
// output error message if fails
296302
error_log( $e->getMessage() );

0 commit comments

Comments
 (0)