Skip to content

Commit 31fd91f

Browse files
committed
SCA: simplify some ifs in favour of null coalescing operator
1 parent 596d12b commit 31fd91f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Filesystem.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
5454

5555
if ($doCopy) {
5656
// https://bugs.php.net/bug.php?id=64634
57-
if (false === $source = @fopen($originFile, 'r')) {
57+
if (false === $source = @fopen($originFile, 'rb')) {
5858
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
5959
}
6060

6161
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
62-
if (false === $target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true))))) {
62+
if (false === $target = @fopen($targetFile, 'wb', null, stream_context_create(array('ftp' => array('overwrite' => true))))) {
6363
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
6464
}
6565

@@ -557,10 +557,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
557557
}
558558
}
559559

560-
$copyOnWindows = false;
561-
if (isset($options['copy_on_windows'])) {
562-
$copyOnWindows = $options['copy_on_windows'];
563-
}
560+
$copyOnWindows = $options['copy_on_windows'] ?? false;
564561

565562
if (null === $iterator) {
566563
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
@@ -650,7 +647,7 @@ public function tempnam($dir, $prefix)
650647

651648
// Use fopen instead of file_exists as some streams do not support stat
652649
// Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
653-
$handle = @fopen($tmpFile, 'x+');
650+
$handle = @fopen($tmpFile, 'x+b');
654651

655652
// If unsuccessful restart the loop
656653
if (false === $handle) {

0 commit comments

Comments
 (0)