From c28bf48b75b0f388cf9617feaf5b5055c359923b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Thu, 21 Dec 2023 12:26:39 +0000 Subject: [PATCH] Avoid PHP notices on missing variables --- src/Context/FeatureContext.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 0be6c542..8ceea879 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -700,13 +700,17 @@ function ( $matches ) use ( $phar_path, $shell_path ) { * Replace variables callback. */ private function replace_var( $matches ) { - $cmd = $matches[0]; + $str = $matches[0]; foreach ( array_slice( $matches, 1 ) as $key ) { - $cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd ); + $str = str_replace( + '{' . $key . '}', + array_key_exists( $key, $this->variables ) ? $this->variables[ $key ] : '', + $str + ); } - return $cmd; + return $str; } /**