original_string: public function getFilePath(FileManager $file_manager)
      {
          $current_file = $file_manager->getCurrentFile();
          $target_file = $file_manager->getTargetFile();
  
          if (($current_file->getFilename() == "" && !is_null($target_file->getFilename()))) {
              throw new \Exception("Filename cannot be empty when there is a target file");
          }
  
          $root = $file_manager->getUploadPath();
          $dir_path = $file_manager->getDirPath();
  
          if (empty($dir_path)) {
              $dir = $root;
          } else {
              if (strcasecmp("../", $dir_path) >= 1) {
                  throw new \Exception("Invalid filepath or filename");
              }
              $dir = $this->getFileManager()->DirTrim($root, $dir_path, true);
          }
  
          try {
              $file_manager->checkPath($dir);
              if (!is_null($target_file)) {
                  $file_manager->checkPath($target_file->getFilepath(true));
              }
          } catch (\Exception $e) {
              throw new \Exception($e->getMessage(), $e->getCode());
          }
  
          return $dir;
      }
code: public function getFilePath(FileManager $file_manager)
      {
          $current_file = $file_manager->getCurrentFile();
          $target_file = $file_manager->getTargetFile();
  
          if (($current_file->getFilename() == "" && !is_null($target_file->getFilename()))) {
              throw new \Exception("Filename cannot be empty when there is a target file");
          }
  
          $root = $file_manager->getUploadPath();
          $dir_path = $file_manager->getDirPath();
  
          if (empty($dir_path)) {
              $dir = $root;
          } else {
              if (strcasecmp("../", $dir_path) >= 1) {
                  throw new \Exception("Invalid filepath or filename");
              }
              $dir = $this->getFileManager()->DirTrim($root, $dir_path, true);
          }
  
          try {
              $file_manager->checkPath($dir);
              if (!is_null($target_file)) {
                  $file_manager->checkPath($target_file->getFilepath(true));
              }
          } catch (\Exception $e) {
              throw new \Exception($e->getMessage(), $e->getCode());
          }
  
          return $dir;
      }
code_tokens: public function getFilePath ( FileManager $ file_manager ) { $ current_file = $ file_manager -> getCurrentFile ( ) ; $ target_file = $ file_manager -> getTargetFile ( ) ; if ( ( $ current_file -> getFilename ( ) == "" && ! is_null ( $ target_file -> getFilename ( ) ) ) ) { throw new \ Exception ( "Filename cannot be empty when there is a target file" ) ; } $ root = $ file_manager -> getUploadPath ( ) ; $ dir_path = $ file_manager -> getDirPath ( ) ; if ( empty ( $ dir_path ) ) { $ dir = $ root ; } else { if ( strcasecmp ( "../" , $ dir_path ) >= 1 ) { throw new \ Exception ( "Invalid filepath or filename" ) ; } $ dir = $ this -> getFileManager ( ) -> DirTrim ( $ root , $ dir_path , true ) ; } try { $ file_manager -> checkPath ( $ dir ) ; if ( ! is_null ( $ target_file ) ) { $ file_manager -> checkPath ( $ target_file -> getFilepath ( true ) ) ; } } catch ( \ Exception $ e ) { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } return $ dir ; }
docstring: Get and check the current file path
  
  @param FileManager $file_manager
  @throws \Exception when the file name is empty while there is a target file or when the file is invalid
  @return bool|string
docstring_tokens: Get and check the current file path