public function checkTargetPath(string $targetPath): void
    {
        if ($this->fileSystem->has($targetPath)) {
            if (! $this->config->hasOverwrite()) {
                throw new FileExistsException(sprintf('The target file "%s" already exists', $targetPath));
            }
            if ($this->config->hasBackup()) {
                $backupTarget = $targetPath . '.bak';
                if ($this->fileSystem->has($backupTarget)) {
                    throw new FileExistsException(sprintf(
                        'The backup target file "%s" already exists',
                        $backupTarget
                    ));
                }
                $this->fileSystem->copy($targetPath, $backupTarget);
            }
            $this->fileSystem->delete($targetPath);
        }
    }
public function checkTargetPath(string $targetPath): void
    {
        if ($this->fileSystem->has($targetPath)) {
            if (! $this->config->hasOverwrite()) {
                throw new FileExistsException(sprintf('The target file "%s" already exists', $targetPath));
            }
            if ($this->config->hasBackup()) {
                $backupTarget = $targetPath . '.bak';
                if ($this->fileSystem->has($backupTarget)) {
                    throw new FileExistsException(sprintf(
                        'The backup target file "%s" already exists',
                        $backupTarget
                    ));
                }
                $this->fileSystem->copy($targetPath, $backupTarget);
            }
            $this->fileSystem->delete($targetPath);
        }
    }
public function checkTargetPath ( string $ targetPath ) : void { if ( $ this -> fileSystem -> has ( $ targetPath ) ) { if ( ! $ this -> config -> hasOverwrite ( ) ) { throw new FileExistsException ( sprintf ( 'The target file "%s" already exists' , $ targetPath ) ) ; } if ( $ this -> config -> hasBackup ( ) ) { $ backupTarget = $ targetPath . '.bak' ; if ( $ this -> fileSystem -> has ( $ backupTarget ) ) { throw new FileExistsException ( sprintf ( 'The backup target file "%s" already exists' , $ backupTarget ) ) ; } $ this -> fileSystem -> copy ( $ targetPath , $ backupTarget ) ; } $ this -> fileSystem -> delete ( $ targetPath ) ; } }
Check if an old file exists. If overwrite option is activated, delete it, else, throw an exception.

@param string $targetPath The target file path.

@throws FileExistsException If overwrite option is deactivated and file exists.
Check if an old file exists . If overwrite option is activated delete it else throw an exception .