Skip to content

Commit 2a42448

Browse files
committed
refactor: remove underscores from private methods and vars (#334)
1 parent bb0b939 commit 2a42448

File tree

6 files changed

+133
-133
lines changed

6 files changed

+133
-133
lines changed

inc/class-cachify-db.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public static function store_item( string $hash, string $data, int $lifetime, bo
5959
array(
6060
'data' => $data,
6161
'meta' => array(
62-
'queries' => self::_page_queries(),
63-
'timer' => self::_page_timer(),
64-
'memory' => self::_page_memory(),
62+
'queries' => self::page_queries(),
63+
'timer' => self::page_timer(),
64+
'memory' => self::page_memory(),
6565
'time' => current_time( 'timestamp' ),
6666
),
6767
),
@@ -128,7 +128,7 @@ public static function print_cache( bool $sig_detail, $cache ): void {
128128
/* Signature - might contain runtime information, so it's generated at this point */
129129
if ( isset( $cache['meta'] ) ) {
130130
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
131-
echo self::_cache_signature( $sig_detail, $cache['meta'] );
131+
echo self::cache_signature( $sig_detail, $cache['meta'] );
132132
}
133133

134134
/* Quit */
@@ -165,7 +165,7 @@ public static function get_stats(): int {
165165
* @since 2.0
166166
* @since 2.3.0 added $detail parameter
167167
*/
168-
private static function _cache_signature( bool $detail, $meta ): string {
168+
private static function cache_signature( bool $detail, $meta ): string {
169169
/* No array? */
170170
if ( ! is_array( $meta ) ) {
171171
return '';
@@ -188,9 +188,9 @@ private static function _cache_signature( bool $detail, $meta ): string {
188188
),
189189
sprintf(
190190
'With Cachify: %d DB queries, %s seconds, %s',
191-
self::_page_queries(),
192-
self::_page_timer(),
193-
self::_page_memory()
191+
self::page_queries(),
192+
self::page_timer(),
193+
self::page_memory()
194194
)
195195
);
196196
} else {
@@ -213,7 +213,7 @@ private static function _cache_signature( bool $detail, $meta ): string {
213213
*
214214
* @since 0.1
215215
*/
216-
private static function _page_queries(): int {
216+
private static function page_queries(): int {
217217
return $GLOBALS['wpdb']->num_queries;
218218
}
219219

@@ -224,7 +224,7 @@ private static function _page_queries(): int {
224224
*
225225
* @since 0.1
226226
*/
227-
private static function _page_timer(): string {
227+
private static function page_timer(): string {
228228
return timer_stop( 0, 2 );
229229
}
230230

@@ -235,7 +235,7 @@ private static function _page_timer(): string {
235235
*
236236
* @since 0.7
237237
*/
238-
private static function _page_memory(): string {
238+
private static function page_memory(): string {
239239
return ( function_exists( 'memory_get_usage' ) ? size_format( memory_get_usage(), 2 ) : 0 );
240240
}
241241
}

inc/class-cachify-hdd.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public static function store_item( string $hash, string $data, int $lifetime, bo
7676
}
7777

7878
/* Store data */
79-
self::_create_files(
80-
$data . self::_cache_signature( $sig_detail )
79+
self::create_files(
80+
$data . self::cache_signature( $sig_detail )
8181
);
8282
}
8383

@@ -91,7 +91,7 @@ public static function store_item( string $hash, string $data, int $lifetime, bo
9191
*/
9292
public static function get_item( string $hash ) {
9393
return is_readable(
94-
self::_file_html()
94+
self::file_html()
9595
);
9696
}
9797

@@ -104,8 +104,8 @@ public static function get_item( string $hash ) {
104104
* @since 2.0
105105
*/
106106
public static function delete_item( string $hash, string $url ): void {
107-
self::_clear_dir(
108-
self::_file_path( $url )
107+
self::clear_dir(
108+
self::file_path( $url )
109109
);
110110
}
111111

@@ -115,7 +115,7 @@ public static function delete_item( string $hash, string $url ): void {
115115
* @since 2.0
116116
*/
117117
public static function clear_cache(): void {
118-
self::_clear_dir(
118+
self::clear_dir(
119119
CACHIFY_CACHE_DIR,
120120
true
121121
);
@@ -130,7 +130,7 @@ public static function clear_cache(): void {
130130
* @since 2.0
131131
*/
132132
public static function print_cache( bool $sig_detail, $cache ): void {
133-
$filename = self::_file_html();
133+
$filename = self::file_html();
134134
$size = is_readable( $filename ) ? readfile( $filename ) : false;
135135

136136
if ( ! empty( $size ) ) {
@@ -147,7 +147,7 @@ public static function print_cache( bool $sig_detail, $cache ): void {
147147
* @since 2.0
148148
*/
149149
public static function get_stats(): int {
150-
return (int) self::_dir_size( CACHIFY_CACHE_DIR );
150+
return (int) self::dir_size( CACHIFY_CACHE_DIR );
151151
}
152152

153153
/**
@@ -160,7 +160,7 @@ public static function get_stats(): int {
160160
* @since 2.0
161161
* @since 2.3.0 added $detail parameter
162162
*/
163-
private static function _cache_signature( bool $detail ): string {
163+
private static function cache_signature( bool $detail ): string {
164164
return sprintf(
165165
"\n\n<!-- %s\n%s @ %s -->",
166166
'Cachify | https://cachify.pluginkollektiv.org',
@@ -179,24 +179,24 @@ private static function _cache_signature( bool $detail ): string {
179179
*
180180
* @since 2.0
181181
*/
182-
private static function _create_files( string $data ): void {
183-
$file_path = self::_file_path();
182+
private static function create_files( string $data ): void {
183+
$file_path = self::file_path();
184184

185185
/* Create directory */
186186
if ( ! wp_mkdir_p( $file_path ) ) {
187187
trigger_error( esc_html( __METHOD__ . ": Unable to create directory {$file_path}." ), E_USER_WARNING );
188188
return;
189189
}
190190
/* Write to file */
191-
self::_create_file( self::_file_html( $file_path ), $data );
191+
self::create_file( self::file_html( $file_path ), $data );
192192

193193
/**
194194
* Filter that allows to enable/disable gzip file creation
195195
*
196196
* @param bool $create_gzip_files Whether to create gzip files. Default is `true`
197197
*/
198198
if ( self::is_gzip_enabled() ) {
199-
self::_create_file( self::_file_gzip( $file_path ), gzencode( $data, 9 ) );
199+
self::create_file( self::file_gzip( $file_path ), gzencode( $data, 9 ) );
200200
}
201201
}
202202

@@ -208,7 +208,7 @@ private static function _create_files( string $data ): void {
208208
*
209209
* @since 2.0
210210
*/
211-
private static function _create_file( string $file, string $data ): void {
211+
private static function create_file( string $file, string $data ): void {
212212
/* Writable? */
213213
$handle = @fopen( $file, 'wb' );
214214
if ( ! $handle ) {
@@ -237,7 +237,7 @@ private static function _create_file( string $file, string $data ): void {
237237
*
238238
* @since 2.0
239239
*/
240-
private static function _clear_dir( string $dir, bool $recursive = false ): void {
240+
private static function clear_dir( string $dir, bool $recursive = false ): void {
241241
// Remove trailing slash.
242242
$dir = untrailingslashit( $dir );
243243

@@ -260,19 +260,19 @@ private static function _clear_dir( string $dir, bool $recursive = false ): void
260260
if ( is_dir( $object ) ) {
261261
if ( $recursive ) {
262262
// Recursively clear the directory.
263-
self::_clear_dir( $object, $recursive );
264-
} elseif ( self::_user_can_delete( $object ) && 0 === count( glob( trailingslashit( $object ) . '*' ) ) ) {
263+
self::clear_dir( $object, $recursive );
264+
} elseif ( self::user_can_delete( $object ) && 0 === count( glob( trailingslashit( $object ) . '*' ) ) ) {
265265
// Delete the directory, if empty.
266266
@rmdir( $object );
267267
}
268-
} elseif ( self::_user_can_delete( $object ) ) {
268+
} elseif ( self::user_can_delete( $object ) ) {
269269
// Delete the file.
270270
unlink( $object );
271271
}
272272
}
273273

274274
// Remove directory, if empty.
275-
if ( self::_user_can_delete( $dir ) && 0 === count( glob( trailingslashit( $dir ) . '*' ) ) ) {
275+
if ( self::user_can_delete( $dir ) && 0 === count( glob( trailingslashit( $dir ) . '*' ) ) ) {
276276
@rmdir( $dir );
277277
}
278278

@@ -289,7 +289,7 @@ private static function _clear_dir( string $dir, bool $recursive = false ): void
289289
*
290290
* @since 2.0
291291
*/
292-
public static function _dir_size( string $dir = '.' ) {
292+
private static function dir_size( string $dir = '.' ) {
293293
/* Is directory? */
294294
if ( ! is_dir( $dir ) ) {
295295
return false;
@@ -316,7 +316,7 @@ public static function _dir_size( string $dir = '.' ) {
316316

317317
/* Directory or file */
318318
if ( is_dir( $object ) ) {
319-
$size += self::_dir_size( $object );
319+
$size += self::dir_size( $object );
320320
} else {
321321
$size += filesize( $object );
322322
}
@@ -334,7 +334,7 @@ public static function _dir_size( string $dir = '.' ) {
334334
*
335335
* @since 2.0
336336
*/
337-
private static function _file_path( ?string $path = null ): string {
337+
private static function file_path( ?string $path = null ): string {
338338
$prefix = is_ssl() ? 'https-' : '';
339339

340340
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
@@ -366,8 +366,8 @@ private static function _file_path( ?string $path = null ): string {
366366
*
367367
* @since 2.0
368368
*/
369-
private static function _file_html( string $file_path = '' ): string {
370-
return ( empty( $file_path ) ? self::_file_path() : $file_path ) . 'index.html';
369+
private static function file_html( string $file_path = '' ): string {
370+
return ( empty( $file_path ) ? self::file_path() : $file_path ) . 'index.html';
371371
}
372372

373373
/**
@@ -379,8 +379,8 @@ private static function _file_html( string $file_path = '' ): string {
379379
*
380380
* @since 2.0
381381
*/
382-
private static function _file_gzip( string $file_path = '' ): string {
383-
return ( empty( $file_path ) ? self::_file_path() : $file_path ) . 'index.html.gz';
382+
private static function file_gzip( string $file_path = '' ): string {
383+
return ( empty( $file_path ) ? self::file_path() : $file_path ) . 'index.html.gz';
384384
}
385385

386386
/**
@@ -390,7 +390,7 @@ private static function _file_gzip( string $file_path = '' ): string {
390390
*
391391
* @return bool
392392
*/
393-
private static function _user_can_delete( string $file ): bool {
393+
private static function user_can_delete( string $file ): bool {
394394
if ( ! is_file( $file ) && ! is_dir( $file ) ) {
395395
return false;
396396
}

0 commit comments

Comments
 (0)