Run Rector on your code to see what it can do for you:
{ public function run(string $param) { - $r = preg_replace( '#^/(foo|bar)/(\w+)/.+$#', '$2', $param, 1, $count ); - if ( $count !== 1 ) { - $r = preg_replace( '#^/hello/(\w+)/.+$#', '$1', $param, 1 ); + if ( $count !== 1 ) { + return preg_replace( '#^/hello/(\w+)/.+$#', '$1', $param, 1 ); } - return $r; + return preg_replace( '#^/(foo|bar)/(\w+)/.+$#', '$2', $param, 1, $count ); } }
Applied Rules:
Is the result wrong?
rector.php