Skip to content

Commit

Permalink
[6.x] Fix method and remove duplication (#30632)
Browse files Browse the repository at this point in the history
* [6.x] Fix method and remove duplication

* Fixed whitespace

* Update FileFactory.php
  • Loading branch information
shadoWalker89 authored and taylorotwell committed Nov 20, 2019
1 parent 01869bc commit 8acfa75
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Illuminate/Http/Testing/FileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ class FileFactory
*/
public function create($name, $kilobytes = 0)
{
$tmp = tmpfile();

if (is_string($kilobytes)) {
file_put_contents($tmp, $kilobytes);
return $this->createWithContent($name, $kilobytes);
}

return tap(new File($name, $tmp), function ($file) use ($kilobytes) {
$file->sizeToReport = is_string($kilobytes) ? fstat($tmp)['size'] : ($kilobytes * 1024);
return tap(new File($name, tmpfile()), function ($file) use ($kilobytes) {
$file->sizeToReport = $kilobytes * 1024;
});
}

Expand All @@ -36,6 +34,7 @@ public function create($name, $kilobytes = 0)
public function createWithContent($name, $content)
{
$tmpfile = tmpfile();

fwrite($tmpfile, $content);

return tap(new File($name, $tmpfile), function ($file) use ($tmpfile) {
Expand Down

0 comments on commit 8acfa75

Please sign in to comment.