Skip to content

Commit

Permalink
fix nullable string
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Nov 29, 2024
1 parent 2ef8225 commit f0edc75
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/SpreadCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function getAdapterByName(string $ext, string $name): SpreadInterf
return new ($class);
}

public static function getAdapterForFile(string $filename, string $ext = null): SpreadInterface
public static function getAdapterForFile(string $filename, ?string $ext = null): SpreadInterface
{
if ($ext === null) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
Expand Down Expand Up @@ -350,10 +350,8 @@ protected static function getExtensionFromOpts(array $opts, ?string $fallback =
return is_string($ext) ? $ext : null;
}

public static function read(
string $filename,
...$opts
): Generator {
public static function read(string $filename, ...$opts): Generator
{
$ext = self::getExtensionFromOpts($opts);
$adapter = self::getAdapterFromOpts($opts, $ext);
if (!$adapter) {
Expand All @@ -362,11 +360,8 @@ public static function read(
return $adapter->readFile($filename, ...$opts);
}

public static function readString(
string $contents,
string $ext = null,
...$opts
): Generator {
public static function readString(string $contents, ?string $ext = null, ...$opts): Generator
{
$ext = self::getExtensionFromOpts($opts, $ext);
if ($ext === null) {
$ext = self::getExtensionForContent($contents);
Expand All @@ -378,11 +373,8 @@ public static function readString(
return $adapter->readString($contents, ...$opts);
}

public static function write(
iterable $data,
string $filename,
...$opts
): bool {
public static function write(iterable $data, string $filename, ...$opts): bool
{
$ext = self::getExtensionFromOpts($opts);
$adapter = self::getAdapterFromOpts($opts, $ext);
if (!$adapter) {
Expand All @@ -391,11 +383,8 @@ public static function write(
return $adapter->writeFile($data, $filename, ...$opts);
}

public static function writeString(
iterable $data,
string $ext = null,
...$opts
): string {
public static function writeString(iterable $data, ?string $ext = null, ...$opts): string
{
$ext = self::getExtensionFromOpts($opts);
$adapter = self::getAdapterFromOpts($opts, $ext);
if (!$adapter && !$ext) {
Expand Down

0 comments on commit f0edc75

Please sign in to comment.