Recursively renaming files and folders with PHP

I wanted to rename lots of filed and folders for my modules, but not to do it manually I made an php script that does this for me. Also I used my IDE to rename code(class names and methods). So just replace root where is the code you want to change file and folder names and do that for strings also.

function scandir_rec($root, $old_string, $new_string) {
  if (!is_dir($root)) {
    return;
  }

  $dirs = scandir($root);

  foreach ($dirs as $dir) {
    if ($dir == '.' || $dir == '..') {
      continue;
    }
    $path = $root . '/' . $dir;
    if (is_file($path)) {

      $newFile = str_replace($old_string, $new_string, $path);
      if ($path != $newFile){
        rename($path, $newFile);
      }
    } else if (is_dir($path)) {

      $newFile = str_replace($old_string, $new_string, $path);
      if ($path != $newFile){
        rename($path, $newFile);
      }
      scandir_rec($path);
    }
  }
}

$root = "/var/www/code/site/web";
$old_string = "some_string";
$new_string = "some_string";
$dir = scandir_rec ($root, $old_string, $new_string);