Skip to content

Commit 75ae2ed

Browse files
CS fixes
1 parent b802cde commit 75ae2ed

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

Exception/FileNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(?string $message = null, int $code = 0, ?\Throwable
2525
if (null === $path) {
2626
$message = 'File could not be found.';
2727
} else {
28-
$message = sprintf('File "%s" could not be found.', $path);
28+
$message = \sprintf('File "%s" could not be found.', $path);
2929
}
3030
}
3131

Filesystem.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe
4040
{
4141
$originIsLocal = stream_is_local($originFile) || 0 === stripos($originFile, 'file://');
4242
if ($originIsLocal && !is_file($originFile)) {
43-
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
43+
throw new FileNotFoundException(\sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
4444
}
4545

4646
$this->mkdir(\dirname($targetFile));
@@ -53,12 +53,12 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe
5353
if ($doCopy) {
5454
// https://bugs.php.net/64634
5555
if (!$source = self::box('fopen', $originFile, 'r')) {
56-
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading: ', $originFile, $targetFile).self::$lastError, 0, null, $originFile);
56+
throw new IOException(\sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading: ', $originFile, $targetFile).self::$lastError, 0, null, $originFile);
5757
}
5858

5959
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
6060
if (!$target = self::box('fopen', $targetFile, 'w', false, stream_context_create(['ftp' => ['overwrite' => true]]))) {
61-
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing: ', $originFile, $targetFile).self::$lastError, 0, null, $originFile);
61+
throw new IOException(\sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing: ', $originFile, $targetFile).self::$lastError, 0, null, $originFile);
6262
}
6363

6464
$bytesCopied = stream_copy_to_stream($source, $target);
@@ -67,7 +67,7 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe
6767
unset($source, $target);
6868

6969
if (!is_file($targetFile)) {
70-
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
70+
throw new IOException(\sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
7171
}
7272

7373
if ($originIsLocal) {
@@ -78,7 +78,7 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe
7878
self::box('touch', $targetFile, filemtime($originFile));
7979

8080
if ($bytesCopied !== $bytesOrigin = filesize($originFile)) {
81-
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
81+
throw new IOException(\sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
8282
}
8383
}
8484
}
@@ -99,7 +99,7 @@ public function mkdir(string|iterable $dirs, int $mode = 0777)
9999
}
100100

101101
if (!self::box('mkdir', $dir, $mode, true) && !is_dir($dir)) {
102-
throw new IOException(sprintf('Failed to create "%s": ', $dir).self::$lastError, 0, null, $dir);
102+
throw new IOException(\sprintf('Failed to create "%s": ', $dir).self::$lastError, 0, null, $dir);
103103
}
104104
}
105105
}
@@ -113,7 +113,7 @@ public function exists(string|iterable $files): bool
113113

114114
foreach ($this->toIterable($files) as $file) {
115115
if (\strlen($file) > $maxPathLength) {
116-
throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
116+
throw new IOException(\sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
117117
}
118118

119119
if (!file_exists($file)) {
@@ -138,7 +138,7 @@ public function touch(string|iterable $files, ?int $time = null, ?int $atime = n
138138
{
139139
foreach ($this->toIterable($files) as $file) {
140140
if (!($time ? self::box('touch', $file, $time, $atime) : self::box('touch', $file))) {
141-
throw new IOException(sprintf('Failed to touch "%s": ', $file).self::$lastError, 0, null, $file);
141+
throw new IOException(\sprintf('Failed to touch "%s": ', $file).self::$lastError, 0, null, $file);
142142
}
143143
}
144144
}
@@ -168,7 +168,7 @@ private static function doRemove(array $files, bool $isRecursive): void
168168
if (is_link($file)) {
169169
// See https://bugs.php.net/52176
170170
if (!(self::box('unlink', $file) || '\\' !== \DIRECTORY_SEPARATOR || self::box('rmdir', $file)) && file_exists($file)) {
171-
throw new IOException(sprintf('Failed to remove symlink "%s": ', $file).self::$lastError);
171+
throw new IOException(\sprintf('Failed to remove symlink "%s": ', $file).self::$lastError);
172172
}
173173
} elseif (is_dir($file)) {
174174
if (!$isRecursive) {
@@ -199,10 +199,10 @@ private static function doRemove(array $files, bool $isRecursive): void
199199
$file = $origFile;
200200
}
201201

202-
throw new IOException(sprintf('Failed to remove directory "%s": ', $file).$lastError);
202+
throw new IOException(\sprintf('Failed to remove directory "%s": ', $file).$lastError);
203203
}
204204
} elseif (!self::box('unlink', $file) && ((self::$lastError && str_contains(self::$lastError, 'Permission denied')) || file_exists($file))) {
205-
throw new IOException(sprintf('Failed to remove file "%s": ', $file).self::$lastError);
205+
throw new IOException(\sprintf('Failed to remove file "%s": ', $file).self::$lastError);
206206
}
207207
}
208208
}
@@ -222,7 +222,7 @@ public function chmod(string|iterable $files, int $mode, int $umask = 0000, bool
222222
{
223223
foreach ($this->toIterable($files) as $file) {
224224
if (!self::box('chmod', $file, $mode & ~$umask)) {
225-
throw new IOException(sprintf('Failed to chmod file "%s": ', $file).self::$lastError, 0, null, $file);
225+
throw new IOException(\sprintf('Failed to chmod file "%s": ', $file).self::$lastError, 0, null, $file);
226226
}
227227
if ($recursive && is_dir($file) && !is_link($file)) {
228228
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
@@ -252,11 +252,11 @@ public function chown(string|iterable $files, string|int $user, bool $recursive
252252
}
253253
if (is_link($file) && \function_exists('lchown')) {
254254
if (!self::box('lchown', $file, $user)) {
255-
throw new IOException(sprintf('Failed to chown file "%s": ', $file).self::$lastError, 0, null, $file);
255+
throw new IOException(\sprintf('Failed to chown file "%s": ', $file).self::$lastError, 0, null, $file);
256256
}
257257
} else {
258258
if (!self::box('chown', $file, $user)) {
259-
throw new IOException(sprintf('Failed to chown file "%s": ', $file).self::$lastError, 0, null, $file);
259+
throw new IOException(\sprintf('Failed to chown file "%s": ', $file).self::$lastError, 0, null, $file);
260260
}
261261
}
262262
}
@@ -284,11 +284,11 @@ public function chgrp(string|iterable $files, string|int $group, bool $recursive
284284
}
285285
if (is_link($file) && \function_exists('lchgrp')) {
286286
if (!self::box('lchgrp', $file, $group)) {
287-
throw new IOException(sprintf('Failed to chgrp file "%s": ', $file).self::$lastError, 0, null, $file);
287+
throw new IOException(\sprintf('Failed to chgrp file "%s": ', $file).self::$lastError, 0, null, $file);
288288
}
289289
} else {
290290
if (!self::box('chgrp', $file, $group)) {
291-
throw new IOException(sprintf('Failed to chgrp file "%s": ', $file).self::$lastError, 0, null, $file);
291+
throw new IOException(\sprintf('Failed to chgrp file "%s": ', $file).self::$lastError, 0, null, $file);
292292
}
293293
}
294294
}
@@ -306,7 +306,7 @@ public function rename(string $origin, string $target, bool $overwrite = false)
306306
{
307307
// we check that target does not exist
308308
if (!$overwrite && $this->isReadable($target)) {
309-
throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
309+
throw new IOException(\sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
310310
}
311311

312312
if (!self::box('rename', $origin, $target)) {
@@ -317,7 +317,7 @@ public function rename(string $origin, string $target, bool $overwrite = false)
317317

318318
return;
319319
}
320-
throw new IOException(sprintf('Cannot rename "%s" to "%s": ', $origin, $target).self::$lastError, 0, null, $target);
320+
throw new IOException(\sprintf('Cannot rename "%s" to "%s": ', $origin, $target).self::$lastError, 0, null, $target);
321321
}
322322
}
323323

@@ -331,7 +331,7 @@ private function isReadable(string $filename): bool
331331
$maxPathLength = \PHP_MAXPATHLEN - 2;
332332

333333
if (\strlen($filename) > $maxPathLength) {
334-
throw new IOException(sprintf('Could not check if file is readable because path length exceeds %d characters.', $maxPathLength), 0, null, $filename);
334+
throw new IOException(\sprintf('Could not check if file is readable because path length exceeds %d characters.', $maxPathLength), 0, null, $filename);
335335
}
336336

337337
return is_readable($filename);
@@ -392,7 +392,7 @@ public function hardlink(string $originFile, string|iterable $targetFiles)
392392
}
393393

394394
if (!is_file($originFile)) {
395-
throw new FileNotFoundException(sprintf('Origin file "%s" is not a file.', $originFile));
395+
throw new FileNotFoundException(\sprintf('Origin file "%s" is not a file.', $originFile));
396396
}
397397

398398
foreach ($this->toIterable($targetFiles) as $targetFile) {
@@ -416,10 +416,10 @@ private function linkException(string $origin, string $target, string $linkType)
416416
{
417417
if (self::$lastError) {
418418
if ('\\' === \DIRECTORY_SEPARATOR && str_contains(self::$lastError, 'error code(1314)')) {
419-
throw new IOException(sprintf('Unable to create "%s" link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
419+
throw new IOException(\sprintf('Unable to create "%s" link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
420420
}
421421
}
422-
throw new IOException(sprintf('Failed to create "%s" link from "%s" to "%s": ', $linkType, $origin, $target).self::$lastError, 0, null, $target);
422+
throw new IOException(\sprintf('Failed to create "%s" link from "%s" to "%s": ', $linkType, $origin, $target).self::$lastError, 0, null, $target);
423423
}
424424

425425
/**
@@ -456,11 +456,11 @@ public function readlink(string $path, bool $canonicalize = false): ?string
456456
public function makePathRelative(string $endPath, string $startPath): string
457457
{
458458
if (!$this->isAbsolutePath($startPath)) {
459-
throw new InvalidArgumentException(sprintf('The start path "%s" is not absolute.', $startPath));
459+
throw new InvalidArgumentException(\sprintf('The start path "%s" is not absolute.', $startPath));
460460
}
461461

462462
if (!$this->isAbsolutePath($endPath)) {
463-
throw new InvalidArgumentException(sprintf('The end path "%s" is not absolute.', $endPath));
463+
throw new InvalidArgumentException(\sprintf('The end path "%s" is not absolute.', $endPath));
464464
}
465465

466466
// Normalize separators on Windows
@@ -548,7 +548,7 @@ public function mirror(string $originDir, string $targetDir, ?\Traversable $iter
548548
$originDirLen = \strlen($originDir);
549549

550550
if (!$this->exists($originDir)) {
551-
throw new IOException(sprintf('The origin directory specified "%s" was not found.', $originDir), 0, null, $originDir);
551+
throw new IOException(\sprintf('The origin directory specified "%s" was not found.', $originDir), 0, null, $originDir);
552552
}
553553

554554
// Iterate in destination folder to remove obsolete entries
@@ -592,7 +592,7 @@ public function mirror(string $originDir, string $targetDir, ?\Traversable $iter
592592
} elseif (is_file($file)) {
593593
$this->copy($file, $target, $options['override'] ?? false);
594594
} else {
595-
throw new IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
595+
throw new IOException(\sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
596596
}
597597
}
598598
}
@@ -670,7 +670,7 @@ public function tempnam(string $dir, string $prefix, string $suffix = ''): strin
670670
public function dumpFile(string $filename, $content)
671671
{
672672
if (\is_array($content)) {
673-
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
673+
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
674674
}
675675

676676
$dir = \dirname($filename);
@@ -691,7 +691,7 @@ public function dumpFile(string $filename, $content)
691691

692692
try {
693693
if (false === self::box('file_put_contents', $tmpFile, $content)) {
694-
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
694+
throw new IOException(\sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
695695
}
696696

697697
self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~umask());
@@ -721,7 +721,7 @@ public function dumpFile(string $filename, $content)
721721
public function appendToFile(string $filename, $content/* , bool $lock = false */)
722722
{
723723
if (\is_array($content)) {
724-
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
724+
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
725725
}
726726

727727
$dir = \dirname($filename);
@@ -733,7 +733,7 @@ public function appendToFile(string $filename, $content/* , bool $lock = false *
733733
$lock = \func_num_args() > 2 && func_get_arg(2);
734734

735735
if (false === self::box('file_put_contents', $filename, $content, \FILE_APPEND | ($lock ? \LOCK_EX : 0))) {
736-
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
736+
throw new IOException(\sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
737737
}
738738
}
739739

@@ -755,7 +755,7 @@ private function getSchemeAndHierarchy(string $filename): array
755755
private static function assertFunctionExists(string $func): void
756756
{
757757
if (!\function_exists($func)) {
758-
throw new IOException(sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func));
758+
throw new IOException(\sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func));
759759
}
760760
}
761761

Path.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,11 @@ public static function isRelative(string $path): bool
437437
public static function makeAbsolute(string $path, string $basePath): string
438438
{
439439
if ('' === $basePath) {
440-
throw new InvalidArgumentException(sprintf('The base path must be a non-empty string. Got: "%s".', $basePath));
440+
throw new InvalidArgumentException(\sprintf('The base path must be a non-empty string. Got: "%s".', $basePath));
441441
}
442442

443443
if (!self::isAbsolute($basePath)) {
444-
throw new InvalidArgumentException(sprintf('The base path "%s" is not an absolute path.', $basePath));
444+
throw new InvalidArgumentException(\sprintf('The base path "%s" is not an absolute path.', $basePath));
445445
}
446446

447447
if (self::isAbsolute($path)) {
@@ -531,12 +531,12 @@ public static function makeRelative(string $path, string $basePath): string
531531
// If the passed path is absolute, but the base path is not, we
532532
// cannot generate a relative path
533533
if ('' !== $root && '' === $baseRoot) {
534-
throw new InvalidArgumentException(sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath));
534+
throw new InvalidArgumentException(\sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath));
535535
}
536536

537537
// Fail if the roots of the two paths are different
538538
if ($baseRoot && $root !== $baseRoot) {
539-
throw new InvalidArgumentException(sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot));
539+
throw new InvalidArgumentException(\sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot));
540540
}
541541

542542
if ('' === $relativeBasePath) {

Tests/FilesystemTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ protected function tearDown(): void
8282
*/
8383
protected function assertFilePermissions($expectedFilePerms, $filePath)
8484
{
85-
$actualFilePerms = (int) substr(sprintf('%o', fileperms($filePath)), -3);
85+
$actualFilePerms = (int) substr(\sprintf('%o', fileperms($filePath)), -3);
8686
$this->assertEquals(
8787
$expectedFilePerms,
8888
$actualFilePerms,
89-
sprintf('File permissions for %s must be %s. Actual %s', $filePath, $expectedFilePerms, $actualFilePerms)
89+
\sprintf('File permissions for %s must be %s. Actual %s', $filePath, $expectedFilePerms, $actualFilePerms)
9090
);
9191
}
9292

0 commit comments

Comments
 (0)