@@ -31,14 +31,10 @@ class Filesystem
31
31
* If the target file is newer, it is overwritten only when the
32
32
* $overwriteNewerFiles option is set to true.
33
33
*
34
- * @param string $originFile The original filename
35
- * @param string $targetFile The target filename
36
- * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten
37
- *
38
34
* @throws FileNotFoundException When originFile doesn't exist
39
35
* @throws IOException When copy fails
40
36
*/
41
- public function copy ($ originFile , $ targetFile , $ overwriteNewerFiles = false )
37
+ public function copy (string $ originFile , string $ targetFile , bool $ overwriteNewerFiles = false )
42
38
{
43
39
$ originIsLocal = stream_is_local ($ originFile ) || 0 === stripos ($ originFile , 'file:// ' );
44
40
if ($ originIsLocal && !is_file ($ originFile )) {
@@ -87,11 +83,10 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
87
83
* Creates a directory recursively.
88
84
*
89
85
* @param string|iterable $dirs The directory path
90
- * @param int $mode The directory mode
91
86
*
92
87
* @throws IOException On any directory creation failure
93
88
*/
94
- public function mkdir ($ dirs , $ mode = 0777 )
89
+ public function mkdir ($ dirs , int $ mode = 0777 )
95
90
{
96
91
foreach ($ this ->toIterable ($ dirs ) as $ dir ) {
97
92
if (is_dir ($ dir )) {
@@ -143,7 +138,7 @@ public function exists($files)
143
138
*
144
139
* @throws IOException When touch fails
145
140
*/
146
- public function touch ($ files , $ time = null , $ atime = null )
141
+ public function touch ($ files , int $ time = null , int $ atime = null )
147
142
{
148
143
foreach ($ this ->toIterable ($ files ) as $ file ) {
149
144
$ touch = $ time ? @touch ($ file , $ time , $ atime ) : @touch ($ file );
@@ -196,7 +191,7 @@ public function remove($files)
196
191
*
197
192
* @throws IOException When the change fails
198
193
*/
199
- public function chmod ($ files , $ mode , $ umask = 0000 , $ recursive = false )
194
+ public function chmod ($ files , int $ mode , int $ umask = 0000 , bool $ recursive = false )
200
195
{
201
196
foreach ($ this ->toIterable ($ files ) as $ file ) {
202
197
if (true !== @chmod ($ file , $ mode & ~$ umask )) {
@@ -211,13 +206,11 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
211
206
/**
212
207
* Change the owner of an array of files or directories.
213
208
*
214
- * @param string|iterable $files A filename, an array of files, or a \Traversable instance to change owner
215
- * @param string $user The new owner user name
216
- * @param bool $recursive Whether change the owner recursively or not
209
+ * @param string|iterable $files A filename, an array of files, or a \Traversable instance to change owner
217
210
*
218
211
* @throws IOException When the change fails
219
212
*/
220
- public function chown ($ files , $ user , $ recursive = false )
213
+ public function chown ($ files , string $ user , bool $ recursive = false )
221
214
{
222
215
foreach ($ this ->toIterable ($ files ) as $ file ) {
223
216
if ($ recursive && is_dir ($ file ) && !is_link ($ file )) {
@@ -238,13 +231,11 @@ public function chown($files, $user, $recursive = false)
238
231
/**
239
232
* Change the group of an array of files or directories.
240
233
*
241
- * @param string|iterable $files A filename, an array of files, or a \Traversable instance to change group
242
- * @param string $group The group name
243
- * @param bool $recursive Whether change the group recursively or not
234
+ * @param string|iterable $files A filename, an array of files, or a \Traversable instance to change group
244
235
*
245
236
* @throws IOException When the change fails
246
237
*/
247
- public function chgrp ($ files , $ group , $ recursive = false )
238
+ public function chgrp ($ files , string $ group , bool $ recursive = false )
248
239
{
249
240
foreach ($ this ->toIterable ($ files ) as $ file ) {
250
241
if ($ recursive && is_dir ($ file ) && !is_link ($ file )) {
@@ -265,14 +256,10 @@ public function chgrp($files, $group, $recursive = false)
265
256
/**
266
257
* Renames a file or a directory.
267
258
*
268
- * @param string $origin The origin filename or directory
269
- * @param string $target The new filename or directory
270
- * @param bool $overwrite Whether to overwrite the target if it already exists
271
- *
272
259
* @throws IOException When target file or directory already exists
273
260
* @throws IOException When origin cannot be renamed
274
261
*/
275
- public function rename ($ origin , $ target , $ overwrite = false )
262
+ public function rename (string $ origin , string $ target , bool $ overwrite = false )
276
263
{
277
264
// we check that target does not exist
278
265
if (!$ overwrite && $ this ->isReadable ($ target )) {
@@ -294,13 +281,11 @@ public function rename($origin, $target, $overwrite = false)
294
281
/**
295
282
* Tells whether a file exists and is readable.
296
283
*
297
- * @param string $filename Path to the file
298
- *
299
284
* @return bool
300
285
*
301
286
* @throws IOException When windows path is longer than 258 characters
302
287
*/
303
- private function isReadable ($ filename )
288
+ private function isReadable (string $ filename )
304
289
{
305
290
$ maxPathLength = PHP_MAXPATHLEN - 2 ;
306
291
@@ -314,13 +299,9 @@ private function isReadable($filename)
314
299
/**
315
300
* Creates a symbolic link or copy a directory.
316
301
*
317
- * @param string $originDir The origin directory path
318
- * @param string $targetDir The symbolic link name
319
- * @param bool $copyOnWindows Whether to copy files if on Windows
320
- *
321
302
* @throws IOException When symlink fails
322
303
*/
323
- public function symlink ($ originDir , $ targetDir , $ copyOnWindows = false )
304
+ public function symlink (string $ originDir , string $ targetDir , bool $ copyOnWindows = false )
324
305
{
325
306
if ('\\' === \DIRECTORY_SEPARATOR ) {
326
307
$ originDir = strtr ($ originDir , '/ ' , '\\' );
@@ -350,13 +331,12 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
350
331
/**
351
332
* Creates a hard link, or several hard links to a file.
352
333
*
353
- * @param string $originFile The original file
354
334
* @param string|string[] $targetFiles The target file(s)
355
335
*
356
336
* @throws FileNotFoundException When original file is missing or not a file
357
337
* @throws IOException When link fails, including if link already exists
358
338
*/
359
- public function hardlink ($ originFile , $ targetFiles )
339
+ public function hardlink (string $ originFile , $ targetFiles )
360
340
{
361
341
if (!$ this ->exists ($ originFile )) {
362
342
throw new FileNotFoundException (null , 0 , null , $ originFile );
@@ -381,11 +361,9 @@ public function hardlink($originFile, $targetFiles)
381
361
}
382
362
383
363
/**
384
- * @param string $origin
385
- * @param string $target
386
364
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
387
365
*/
388
- private function linkException ($ origin , $ target , $ linkType )
366
+ private function linkException (string $ origin , string $ target , string $ linkType )
389
367
{
390
368
if (self ::$ lastError ) {
391
369
if ('\\' === \DIRECTORY_SEPARATOR && false !== strpos (self ::$ lastError , 'error code(1314) ' )) {
@@ -406,12 +384,9 @@ private function linkException($origin, $target, $linkType)
406
384
* - if $path does not exist, returns null
407
385
* - if $path exists, returns its absolute fully resolved final version
408
386
*
409
- * @param string $path A filesystem path
410
- * @param bool $canonicalize Whether or not to return a canonicalized path
411
- *
412
387
* @return string|null
413
388
*/
414
- public function readlink ($ path , $ canonicalize = false )
389
+ public function readlink (string $ path , bool $ canonicalize = false )
415
390
{
416
391
if (!$ canonicalize && !is_link ($ path )) {
417
392
return ;
@@ -439,12 +414,9 @@ public function readlink($path, $canonicalize = false)
439
414
/**
440
415
* Given an existing path, convert it to a path relative to a given starting path.
441
416
*
442
- * @param string $endPath Absolute path of target
443
- * @param string $startPath Absolute path where traversal begins
444
- *
445
417
* @return string Path of target relative to starting path
446
418
*/
447
- public function makePathRelative ($ endPath , $ startPath )
419
+ public function makePathRelative (string $ endPath , string $ startPath )
448
420
{
449
421
if (!$ this ->isAbsolutePath ($ startPath )) {
450
422
throw new InvalidArgumentException (sprintf ('The start path "%s" is not absolute. ' , $ startPath ));
@@ -524,18 +496,16 @@ public function makePathRelative($endPath, $startPath)
524
496
* - existing files in the target directory will be overwritten, except if they are newer (see the `override` option)
525
497
* - files in the target directory that do not exist in the source directory will not be deleted (see the `delete` option)
526
498
*
527
- * @param string $originDir The origin directory
528
- * @param string $targetDir The target directory
529
- * @param \Traversable|null $iterator Iterator that filters which files and directories to copy, if null a recursive iterator is created
530
- * @param array $options An array of boolean options
531
- * Valid options are:
532
- * - $options['override'] If true, target files newer than origin files are overwritten (see copy(), defaults to false)
533
- * - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink(), defaults to false)
534
- * - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
499
+ * @param \Traversable|null $iterator Iterator that filters which files and directories to copy, if null a recursive iterator is created
500
+ * @param array $options An array of boolean options
501
+ * Valid options are:
502
+ * - $options['override'] If true, target files newer than origin files are overwritten (see copy(), defaults to false)
503
+ * - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink(), defaults to false)
504
+ * - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
535
505
*
536
506
* @throws IOException When file type is unknown
537
507
*/
538
- public function mirror ($ originDir , $ targetDir , \Traversable $ iterator = null , $ options = [])
508
+ public function mirror (string $ originDir , string $ targetDir , \Traversable $ iterator = null , array $ options = [])
539
509
{
540
510
$ targetDir = rtrim ($ targetDir , '/ \\' );
541
511
$ originDir = rtrim ($ originDir , '/ \\' );
@@ -594,11 +564,9 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
594
564
/**
595
565
* Returns whether the file path is an absolute path.
596
566
*
597
- * @param string $file A file path
598
- *
599
567
* @return bool
600
568
*/
601
- public function isAbsolutePath ($ file )
569
+ public function isAbsolutePath (string $ file )
602
570
{
603
571
return strspn ($ file , '/ \\' , 0 , 1 )
604
572
|| (\strlen ($ file ) > 3 && ctype_alpha ($ file [0 ])
@@ -612,13 +580,12 @@ public function isAbsolutePath($file)
612
580
/**
613
581
* Creates a temporary file with support for custom stream wrappers.
614
582
*
615
- * @param string $dir The directory where the temporary filename will be created
616
583
* @param string $prefix The prefix of the generated temporary filename
617
584
* Note: Windows uses only the first three characters of prefix
618
585
*
619
586
* @return string The new temporary filename (with path), or throw an exception on failure
620
587
*/
621
- public function tempnam ($ dir , $ prefix )
588
+ public function tempnam (string $ dir , string $ prefix )
622
589
{
623
590
list ($ scheme , $ hierarchy ) = $ this ->getSchemeAndHierarchy ($ dir );
624
591
@@ -664,12 +631,11 @@ public function tempnam($dir, $prefix)
664
631
/**
665
632
* Atomically dumps content into a file.
666
633
*
667
- * @param string $filename The file to be written to
668
- * @param string|resource $content The data to write into the file
634
+ * @param string|resource $content The data to write into the file
669
635
*
670
636
* @throws IOException if the file cannot be written to
671
637
*/
672
- public function dumpFile ($ filename , $ content )
638
+ public function dumpFile (string $ filename , $ content )
673
639
{
674
640
if (\is_array ($ content )) {
675
641
throw new \TypeError (sprintf ('Argument 2 passed to %s() must be string or resource, %s given. ' , __METHOD__ , $ content ));
@@ -701,12 +667,11 @@ public function dumpFile($filename, $content)
701
667
/**
702
668
* Appends content to an existing file.
703
669
*
704
- * @param string $filename The file to which to append content
705
- * @param string|resource $content The content to append
670
+ * @param string|resource $content The content to append
706
671
*
707
672
* @throws IOException If the file is not writable
708
673
*/
709
- public function appendToFile ($ filename , $ content )
674
+ public function appendToFile (string $ filename , $ content )
710
675
{
711
676
if (\is_array ($ content )) {
712
677
throw new \TypeError (sprintf ('Argument 2 passed to %s() must be string or resource, %s given. ' , __METHOD__ , $ content ));
0 commit comments