Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c86fc51

Browse files
author
smoench
committed
[5.0][Filesystem] add parameter type hints
1 parent a25848b commit c86fc51

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Filesystem
3838
* @throws FileNotFoundException When originFile doesn't exist
3939
* @throws IOException When copy fails
4040
*/
41-
public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
41+
public function copy(string $originFile, string $targetFile, bool $overwriteNewerFiles = false)
4242
{
4343
$originIsLocal = stream_is_local($originFile) || 0 === stripos($originFile, 'file://');
4444
if ($originIsLocal && !is_file($originFile)) {
@@ -91,7 +91,7 @@ public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
9191
*
9292
* @throws IOException On any directory creation failure
9393
*/
94-
public function mkdir($dirs, $mode = 0777)
94+
public function mkdir($dirs, int $mode = 0777)
9595
{
9696
foreach ($this->toIterable($dirs) as $dir) {
9797
if (is_dir($dir)) {
@@ -143,7 +143,7 @@ public function exists($files)
143143
*
144144
* @throws IOException When touch fails
145145
*/
146-
public function touch($files, $time = null, $atime = null)
146+
public function touch($files, int $time = null, int $atime = null)
147147
{
148148
foreach ($this->toIterable($files) as $file) {
149149
$touch = $time ? @touch($file, $time, $atime) : @touch($file);
@@ -196,7 +196,7 @@ public function remove($files)
196196
*
197197
* @throws IOException When the change fails
198198
*/
199-
public function chmod($files, $mode, $umask = 0000, $recursive = false)
199+
public function chmod($files, int $mode, int $umask = 0000, bool $recursive = false)
200200
{
201201
foreach ($this->toIterable($files) as $file) {
202202
if (true !== @chmod($file, $mode & ~$umask)) {
@@ -217,7 +217,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
217217
*
218218
* @throws IOException When the change fails
219219
*/
220-
public function chown($files, $user, $recursive = false)
220+
public function chown($files, string $user, bool $recursive = false)
221221
{
222222
foreach ($this->toIterable($files) as $file) {
223223
if ($recursive && is_dir($file) && !is_link($file)) {
@@ -244,7 +244,7 @@ public function chown($files, $user, $recursive = false)
244244
*
245245
* @throws IOException When the change fails
246246
*/
247-
public function chgrp($files, $group, $recursive = false)
247+
public function chgrp($files, string $group, bool $recursive = false)
248248
{
249249
foreach ($this->toIterable($files) as $file) {
250250
if ($recursive && is_dir($file) && !is_link($file)) {
@@ -272,7 +272,7 @@ public function chgrp($files, $group, $recursive = false)
272272
* @throws IOException When target file or directory already exists
273273
* @throws IOException When origin cannot be renamed
274274
*/
275-
public function rename($origin, $target, $overwrite = false)
275+
public function rename(string $origin, string $target, bool $overwrite = false)
276276
{
277277
// we check that target does not exist
278278
if (!$overwrite && $this->isReadable($target)) {
@@ -300,7 +300,7 @@ public function rename($origin, $target, $overwrite = false)
300300
*
301301
* @throws IOException When windows path is longer than 258 characters
302302
*/
303-
private function isReadable($filename)
303+
private function isReadable(string $filename)
304304
{
305305
$maxPathLength = PHP_MAXPATHLEN - 2;
306306

@@ -320,7 +320,7 @@ private function isReadable($filename)
320320
*
321321
* @throws IOException When symlink fails
322322
*/
323-
public function symlink($originDir, $targetDir, $copyOnWindows = false)
323+
public function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false)
324324
{
325325
if ('\\' === \DIRECTORY_SEPARATOR) {
326326
$originDir = strtr($originDir, '/', '\\');
@@ -356,7 +356,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
356356
* @throws FileNotFoundException When original file is missing or not a file
357357
* @throws IOException When link fails, including if link already exists
358358
*/
359-
public function hardlink($originFile, $targetFiles)
359+
public function hardlink(string $originFile, $targetFiles)
360360
{
361361
if (!$this->exists($originFile)) {
362362
throw new FileNotFoundException(null, 0, null, $originFile);
@@ -385,7 +385,7 @@ public function hardlink($originFile, $targetFiles)
385385
* @param string $target
386386
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
387387
*/
388-
private function linkException($origin, $target, $linkType)
388+
private function linkException(string $origin, string $target, string $linkType)
389389
{
390390
if (self::$lastError) {
391391
if ('\\' === \DIRECTORY_SEPARATOR && false !== strpos(self::$lastError, 'error code(1314)')) {
@@ -411,7 +411,7 @@ private function linkException($origin, $target, $linkType)
411411
*
412412
* @return string|null
413413
*/
414-
public function readlink($path, $canonicalize = false)
414+
public function readlink(string $path, bool $canonicalize = false)
415415
{
416416
if (!$canonicalize && !is_link($path)) {
417417
return;
@@ -444,7 +444,7 @@ public function readlink($path, $canonicalize = false)
444444
*
445445
* @return string Path of target relative to starting path
446446
*/
447-
public function makePathRelative($endPath, $startPath)
447+
public function makePathRelative(string $endPath, string $startPath)
448448
{
449449
if (!$this->isAbsolutePath($startPath)) {
450450
throw new InvalidArgumentException(sprintf('The start path "%s" is not absolute.', $startPath));
@@ -535,7 +535,7 @@ public function makePathRelative($endPath, $startPath)
535535
*
536536
* @throws IOException When file type is unknown
537537
*/
538-
public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = [])
538+
public function mirror(string $originDir, string $targetDir, \Traversable $iterator = null, array $options = [])
539539
{
540540
$targetDir = rtrim($targetDir, '/\\');
541541
$originDir = rtrim($originDir, '/\\');
@@ -598,7 +598,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
598598
*
599599
* @return bool
600600
*/
601-
public function isAbsolutePath($file)
601+
public function isAbsolutePath(string $file)
602602
{
603603
return strspn($file, '/\\', 0, 1)
604604
|| (\strlen($file) > 3 && ctype_alpha($file[0])
@@ -618,7 +618,7 @@ public function isAbsolutePath($file)
618618
*
619619
* @return string The new temporary filename (with path), or throw an exception on failure
620620
*/
621-
public function tempnam($dir, $prefix)
621+
public function tempnam(string $dir, string $prefix)
622622
{
623623
list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
624624

@@ -669,7 +669,7 @@ public function tempnam($dir, $prefix)
669669
*
670670
* @throws IOException if the file cannot be written to
671671
*/
672-
public function dumpFile($filename, $content)
672+
public function dumpFile(string $filename, $content)
673673
{
674674
if (\is_array($content)) {
675675
throw new \TypeError(sprintf('Argument 2 passed to %s() must be string or resource, %s given.', __METHOD__, $content));
@@ -706,7 +706,7 @@ public function dumpFile($filename, $content)
706706
*
707707
* @throws IOException If the file is not writable
708708
*/
709-
public function appendToFile($filename, $content)
709+
public function appendToFile(string $filename, $content)
710710
{
711711
if (\is_array($content)) {
712712
throw new \TypeError(sprintf('Argument 2 passed to %s() must be string or resource, %s given.', __METHOD__, $content));

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,6 @@ public function providePathsForIsAbsolutePath()
13971397
['var/lib', false],
13981398
['../var/lib', false],
13991399
['', false],
1400-
[null, false],
14011400
];
14021401
}
14031402

0 commit comments

Comments
 (0)