Skip to content

Commit 58d4318

Browse files
committed
improve typing in ViewRenderer
1 parent 4ec7b22 commit 58d4318

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ parameters:
2525
count: 25
2626
- message: '#^In method "WP2Static\\\S+::\S+", you should not use the \$_(GET|POST) superglobal#'
2727
path: src/ViewRenderer.php
28-
count: 18
28+
count: 10
2929
- message: "#^Cannot access property \\$value on mixed\\.$#"
3030
path: views/options-page.php
3131
count: 4

src/ViewRenderer.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ public static function renderPostProcessedSitePaths() : void {
151151
$paths = ProcessedSite::getPaths();
152152

153153
// Apply search
154-
if ( ! empty( $_GET['s'] ) ) {
155-
$s = $_GET['s'];
154+
$search_term = strval( filter_input( INPUT_GET, 's' ) );
155+
if ( $search_term !== '' ) {
156156
$paths = array_filter(
157157
$paths,
158-
function ( $path ) use ( $s ) {
159-
return stripos( $path, $s ) !== false;
158+
function ( $path ) use ( $search_term ) {
159+
return stripos( $path, $search_term ) !== false;
160160
}
161161
);
162162
}
@@ -184,12 +184,12 @@ public static function renderStaticSitePaths() : void {
184184
$paths = StaticSite::getPaths();
185185

186186
// Apply search
187-
if ( ! empty( $_GET['s'] ) ) {
188-
$s = $_GET['s'];
187+
$search_term = strval( filter_input( INPUT_GET, 's' ) );
188+
if ( $search_term !== '' ) {
189189
$paths = array_filter(
190190
$paths,
191-
function ( $path ) use ( $s ) {
192-
return stripos( $path, $s ) !== false;
191+
function ( $path ) use ( $search_term ) {
192+
return stripos( $path, $search_term ) !== false;
193193
}
194194
);
195195
}
@@ -214,17 +214,18 @@ public static function renderDeployCache() : void {
214214
die( 'Forbidden' );
215215
}
216216

217-
$paths = isset( $_GET['deploy_namespace'] )
218-
? DeployCache::getPaths( $_GET['deploy_namespace'] )
217+
$deploy_namespace = strval( filter_input( INPUT_GET, 'deploy_namespace' ) );
218+
$paths = $deploy_namespace !== ''
219+
? DeployCache::getPaths( $deploy_namespace )
219220
: DeployCache::getPaths();
220221

221222
// Apply search
222-
if ( ! empty( $_GET['s'] ) ) {
223-
$s = $_GET['s'];
223+
$search_term = strval( filter_input( INPUT_GET, 's' ) );
224+
if ( $search_term !== '' ) {
224225
$paths = array_filter(
225226
$paths,
226-
function ( $path ) use ( $s ) {
227-
return stripos( $path, $s ) !== false;
227+
function ( $path ) use ( $search_term ) {
228+
return stripos( $path, $search_term ) !== false;
228229
}
229230
);
230231
}

0 commit comments

Comments
 (0)