Skip to content

Commit

Permalink
Add typehints to the FilesystemInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Feb 21, 2020
1 parent 84f9188 commit d5759f5
Showing 1 changed file with 11 additions and 40 deletions.
51 changes: 11 additions & 40 deletions src/Filesystem/FilesystemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,19 @@ interface FilesystemInterface
*
* By default, if the target already exists, it is not overridden.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param bool $override Whether to override an existing file or not
*
* @throws FileNotFoundException When originFile doesn't exist
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false);
public function copy(string $originFile, string $targetFile, bool $override = false);

/**
* Creates a directory recursively.
*
* @param string|array|\Traversable $dirs The directory path
* @param int $mode The directory mode
*
* @throws IOException On any directory creation failure
*/
public function mkdir($dirs, $mode = 0777);
public function mkdir($dirs, int $mode = 0777);

/**
* Checks the existence of files or directories.
Expand All @@ -57,12 +52,10 @@ public function exists($files);
* Sets access and modification time of file.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to create
* @param int $time The touch time as a Unix timestamp
* @param int $atime The access time as a Unix timestamp
*
* @throws IOException When touch fails
*/
public function touch($files, $time = null, $atime = null);
public function touch($files, int $time = null, int $atime = null);

/**
* Removes files or directories.
Expand All @@ -77,64 +70,47 @@ public function remove($files);
* Change mode for an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change mode
* @param int $mode The new mode (octal)
* @param int $umask The mode mask (octal)
* @param bool $recursive Whether change the mod recursively or not
*
* @throws IOException When the change fail
*/
public function chmod($files, $mode, $umask = 0000, $recursive = false);
public function chmod($files, int $mode, int $umask = 0000, bool $recursive = false);

/**
* Change the owner of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
*
* @throws IOException When the change fail
*/
public function chown($files, $user, $recursive = false);
public function chown($files, string $user, bool $recursive = false);

/**
* Change the group of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change group
* @param string $group The group name
* @param bool $recursive Whether change the group recursively or not
*
* @throws IOException When the change fail
*/
public function chgrp($files, $group, $recursive = false);
public function chgrp($files, string $group, bool $recursive = false);

/**
* Renames a file or a directory.
*
* @param string $origin The origin filename or directory
* @param string $target The new filename or directory
* @param bool $overwrite Whether to overwrite the target if it already exists
*
* @throws IOException When target file or directory already exists
* @throws IOException When origin cannot be renamed
*/
public function rename($origin, $target, $overwrite = false);
public function rename(string $origin, string $target, bool $overwrite = false);

/**
* Creates a symbolic link or copy a directory.
*
* @param string $originDir The origin directory path
* @param string $targetDir The symbolic link name
* @param bool $copyOnWindows Whether to copy files if on Windows
*
* @throws IOException When symlink fails
*/
public function symlink($originDir, $targetDir, $copyOnWindows = false);
public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false);

/**
* Mirrors a directory to another.
*
* @param string $originDir The origin directory
* @param string $targetDir The target directory
* @param \Traversable $iterator A Traversable instance
* @param array $options An array of boolean options
* Valid options are:
Expand All @@ -144,26 +120,21 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false);
*
* @throws IOException When file type is unknown
*/
public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = []);
public function mirror(string $originDir, string $targetDir, \Traversable $iterator = null, array $options = []);

/**
* Given an existing path, convert it to a path relative to a given starting path.
*
* @param string $endPath Absolute path of target
* @param string $startPath Absolute path where traversal begins
*
* @return string Path of target relative to starting path
*/
public function makePathRelative($endPath, $startPath);
public function makePathRelative(string $endPath, string $startPath);

/**
* Returns whether the file path is an absolute path.
*
* @param string $file A file path
*
* @return bool
*/
public function isAbsolutePath($file);
public function isAbsolutePath(string $file);

public function getFileContents(string $file): string;
}

0 comments on commit d5759f5

Please sign in to comment.