Skip to content

Commit

Permalink
Moved files now retain the current Object
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wakelin committed Feb 9, 2022
1 parent a2bb0f4 commit d7f0b36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions SpacesAPI/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ public function copy(string $newFilename): File
*/
public function move(string $newFilename): File
{
$newFile = $this->copy($newFilename);
$this->copy($newFilename);
$this->delete();
$this->_filename = $newFilename;
$this->fetchFileInfo();

return $newFile;
return $this;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions docs/File.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ public move (string $newFilename)
```

Move or rename a file
The `File` instance on which you call `move` will become invalid and calling methods on it will result in a `FileDoesntExistException`

The instance of `File` is now the moved object

**Parameters**

Expand Down
2 changes: 1 addition & 1 deletion tests/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testCanMoveRenameFile()
$file = self::$file->copy('test.txt');
$file->move('renamed-file.txt');

$this->assertEquals("Lorem ipsum", self::$space->file('renamed-file.txt')->getContents());
$this->assertEquals("renamed-file.txt", $file->filename);

$this->expectException(FileDoesntExistException::class);
self::$space->file('test.txt');
Expand Down

0 comments on commit d7f0b36

Please sign in to comment.