Skip to content

Commit f92dc45

Browse files
Added optional parameter $DIRECTORY_SEPARATOR to split function to address a possible issue in Windows environments.
1 parent b97dedf commit f92dc45

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
"php": "^7.3"
77
},
88
"require-dev": {
9-
"mikey179/vfsstream": "dev-master",
10-
"phpunit/phpunit": "^8.0",
11-
"php-coveralls/php-coveralls": "^2.1"
12-
9+
"mikey179/vfsstream": "^1.6",
10+
"phpunit/phpunit": "^9.5",
11+
"php-coveralls/php-coveralls": "^2.4"
1312
},
1413
"license": "MIT",
1514
"authors": [
@@ -18,7 +17,7 @@
1817
"email": "[email protected]"
1918
}
2019
],
21-
"minimum-stability": "alpha",
20+
"minimum-stability": "stable",
2221
"autoload": {
2322
"psr-4": {
2423
"MichaelDrennen\\LocalFile\\": "src"

src/LocalFile.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ public static function lineCount( string $filePath ): int {
3535
}
3636

3737

38+
3839
/**
39-
* @param string $pathToSourceFile
40-
* @param int $linesPerFile
41-
* @param string $prefix
40+
* @param string $pathToSourceFile
41+
* @param int $linesPerFile
42+
* @param string|null $prefix
4243
* @param string|null $destinationPath
43-
*
44-
* @returns array An array of the paths to the split files.
45-
* @throws \MichaelDrennen\LocalFile\Exceptions\CantWriteToReadOnlyDirectory
46-
* @throws \MichaelDrennen\LocalFile\Exceptions\SourceFileDoesNotExist
47-
* @throws \MichaelDrennen\LocalFile\Exceptions\UnableToReadFile
48-
* @throws \MichaelDrennen\LocalFile\Exceptions\UnableToOpenSplitFileHandle
49-
* @throws \MichaelDrennen\LocalFile\Exceptions\UnableToWriteLineToSplitFile
44+
* @param string $DIRECTORY_SEPARATOR
45+
* @return array An array of the paths to the split files.
46+
* @throws CantWriteToReadOnlyDirectory
47+
* @throws SourceFileDoesNotExist
48+
* @throws UnableToOpenSplitFileHandle
49+
* @throws UnableToReadFile
50+
* @throws UnableToWriteLineToSplitFile
5051
*/
51-
public static function split( string $pathToSourceFile, $linesPerFile = 1000, string $prefix = null, string $destinationPath = null ): array {
52+
public static function split( string $pathToSourceFile,
53+
$linesPerFile = 1000,
54+
string $prefix = null,
55+
string $destinationPath = null,
56+
string $DIRECTORY_SEPARATOR = DIRECTORY_SEPARATOR): array {
5257

5358
if ( false === file_exists( $pathToSourceFile ) ):
5459
throw new SourceFileDoesNotExist( "Can't split [" . $pathToSourceFile . "] because it doesn't exist." );
@@ -75,8 +80,8 @@ public static function split( string $pathToSourceFile, $linesPerFile = 1000, st
7580
/**
7681
* Make sure there is a trailing DIRECTORY_SEPARATOR
7782
*/
78-
if ( DIRECTORY_SEPARATOR != substr( $destinationPath, -1 ) ):
79-
$destinationPath .= DIRECTORY_SEPARATOR;
83+
if ( $DIRECTORY_SEPARATOR != substr( $destinationPath, -1 ) ):
84+
$destinationPath .= $DIRECTORY_SEPARATOR;
8085
endif;
8186

8287
if ( false === is_writeable( $destinationPath ) ):
@@ -90,7 +95,6 @@ public static function split( string $pathToSourceFile, $linesPerFile = 1000, st
9095

9196
while ( false !== ( $line = fgets( $sourceHandle ) ) ):
9297

93-
9498
$line = trim( $line );
9599

96100
// process the line read.

0 commit comments

Comments
 (0)