Skip to content

Commit

Permalink
refactor: explicit nullable parameters (#4251)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostdebruijn authored Nov 25, 2024
1 parent 2caa541 commit 6261631
Show file tree
Hide file tree
Showing 33 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/Cache/MemoryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MemoryCache implements CacheInterface
/**
* @param int|null $memoryLimit
*/
public function __construct(int $memoryLimit = null)
public function __construct(?int $memoryLimit = null)
{
$this->memoryLimit = $memoryLimit;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/MemoryCacheDeprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MemoryCacheDeprecated implements CacheInterface
/**
* @param int|null $memoryLimit
*/
public function __construct(int $memoryLimit = null)
public function __construct(?int $memoryLimit = null)
{
$this->memoryLimit = $memoryLimit;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Concerns/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait Exportable
*
* @throws NoFilenameGivenException
*/
public function download(string $fileName = null, string $writerType = null, array $headers = null)
public function download(?string $fileName = null, ?string $writerType = null, ?array $headers = null)
{
$headers = $headers ?? $this->headers ?? [];
$fileName = $fileName ?? $this->fileName ?? null;
Expand All @@ -39,7 +39,7 @@ public function download(string $fileName = null, string $writerType = null, arr
*
* @throws NoFilePathGivenException
*/
public function store(string $filePath = null, string $disk = null, string $writerType = null, $diskOptions = [])
public function store(?string $filePath = null, ?string $disk = null, ?string $writerType = null, $diskOptions = [])
{
$filePath = $filePath ?? $this->filePath ?? null;

Expand All @@ -65,7 +65,7 @@ public function store(string $filePath = null, string $disk = null, string $writ
*
* @throws NoFilePathGivenException
*/
public function queue(string $filePath = null, string $disk = null, string $writerType = null, $diskOptions = [])
public function queue(?string $filePath = null, ?string $disk = null, ?string $writerType = null, $diskOptions = [])
{
$filePath = $filePath ?? $this->filePath ?? null;

Expand Down
8 changes: 4 additions & 4 deletions src/Concerns/Importable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait Importable
*
* @throws NoFilePathGivenException
*/
public function import($filePath = null, string $disk = null, string $readerType = null)
public function import($filePath = null, ?string $disk = null, ?string $readerType = null)
{
$filePath = $this->getFilePath($filePath);

Expand All @@ -48,7 +48,7 @@ public function import($filePath = null, string $disk = null, string $readerType
*
* @throws NoFilePathGivenException
*/
public function toArray($filePath = null, string $disk = null, string $readerType = null): array
public function toArray($filePath = null, ?string $disk = null, ?string $readerType = null): array
{
$filePath = $this->getFilePath($filePath);

Expand All @@ -68,7 +68,7 @@ public function toArray($filePath = null, string $disk = null, string $readerTyp
*
* @throws NoFilePathGivenException
*/
public function toCollection($filePath = null, string $disk = null, string $readerType = null): Collection
public function toCollection($filePath = null, ?string $disk = null, ?string $readerType = null): Collection
{
$filePath = $this->getFilePath($filePath);

Expand All @@ -89,7 +89,7 @@ public function toCollection($filePath = null, string $disk = null, string $read
* @throws NoFilePathGivenException
* @throws InvalidArgumentException
*/
public function queue($filePath = null, string $disk = null, string $readerType = null)
public function queue($filePath = null, ?string $disk = null, ?string $readerType = null)
{
if (!$this instanceof ShouldQueue) {
throw new InvalidArgumentException('Importable should implement ShouldQueue to be queued.');
Expand Down
16 changes: 8 additions & 8 deletions src/Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function download($export, string $fileName, string $writerType = null, array $headers = [])
public function download($export, string $fileName, ?string $writerType = null, array $headers = [])
{
// Clear output buffer to prevent stuff being prepended to the Excel output.
if (ob_get_length() > 0) {
Expand All @@ -99,7 +99,7 @@ public function download($export, string $fileName, string $writerType = null, a
*
* @param string|null $disk Fallback for usage with named properties
*/
public function store($export, string $filePath, string $diskName = null, string $writerType = null, $diskOptions = [], string $disk = null)
public function store($export, string $filePath, ?string $diskName = null, ?string $writerType = null, $diskOptions = [], ?string $disk = null)
{
if ($export instanceof ShouldQueue) {
return $this->queue($export, $filePath, $diskName ?: $disk, $writerType, $diskOptions);
Expand All @@ -120,7 +120,7 @@ public function store($export, string $filePath, string $diskName = null, string
/**
* {@inheritdoc}
*/
public function queue($export, string $filePath, string $disk = null, string $writerType = null, $diskOptions = [])
public function queue($export, string $filePath, ?string $disk = null, ?string $writerType = null, $diskOptions = [])
{
$writerType = FileTypeDetector::detectStrict($filePath, $writerType);

Expand Down Expand Up @@ -149,7 +149,7 @@ public function raw($export, string $writerType)
/**
* {@inheritdoc}
*/
public function import($import, $filePath, string $disk = null, string $readerType = null)
public function import($import, $filePath, ?string $disk = null, ?string $readerType = null)
{
$readerType = FileTypeDetector::detect($filePath, $readerType);
$response = $this->reader->read($import, $filePath, $readerType, $disk);
Expand All @@ -164,7 +164,7 @@ public function import($import, $filePath, string $disk = null, string $readerTy
/**
* {@inheritdoc}
*/
public function toArray($import, $filePath, string $disk = null, string $readerType = null): array
public function toArray($import, $filePath, ?string $disk = null, ?string $readerType = null): array
{
$readerType = FileTypeDetector::detect($filePath, $readerType);

Expand All @@ -174,7 +174,7 @@ public function toArray($import, $filePath, string $disk = null, string $readerT
/**
* {@inheritdoc}
*/
public function toCollection($import, $filePath, string $disk = null, string $readerType = null): Collection
public function toCollection($import, $filePath, ?string $disk = null, ?string $readerType = null): Collection
{
$readerType = FileTypeDetector::detect($filePath, $readerType);

Expand All @@ -184,7 +184,7 @@ public function toCollection($import, $filePath, string $disk = null, string $re
/**
* {@inheritdoc}
*/
public function queueImport(ShouldQueue $import, $filePath, string $disk = null, string $readerType = null)
public function queueImport(ShouldQueue $import, $filePath, ?string $disk = null, ?string $readerType = null)
{
return $this->import($import, $filePath, $disk, $readerType);
}
Expand All @@ -197,7 +197,7 @@ public function queueImport(ShouldQueue $import, $filePath, string $disk = null,
*
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
protected function export($export, string $fileName, string $writerType = null): TemporaryFile
protected function export($export, string $fileName, ?string $writerType = null): TemporaryFile
{
$writerType = FileTypeDetector::detectStrict($fileName, $writerType);

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/NoFilePathGivenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NoFilePathGivenException extends InvalidArgumentException implements Larav
public function __construct(
$message = 'A filepath needs to be passed.',
$code = 0,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/NoFilenameGivenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NoFilenameGivenException extends InvalidArgumentException implements Larav
public function __construct(
$message = 'A filename needs to be passed in order to download the export',
$code = 0,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/NoTypeDetectedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NoTypeDetectedException extends Exception implements LaravelExcelException
public function __construct(
$message = 'No ReaderType or WriterType could be detected. Make sure you either pass a valid extension to the filename or pass an explicit type.',
$code = 0,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/UnreadableFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UnreadableFileException extends Exception implements LaravelExcelException
public function __construct(
$message = 'File could not be read',
$code = 0,
Throwable $previous = null
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Exporter
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function download($export, string $fileName, string $writerType = null, array $headers = []);
public function download($export, string $fileName, ?string $writerType = null, array $headers = []);

/**
* @param object $export
Expand All @@ -27,7 +27,7 @@ public function download($export, string $fileName, string $writerType = null, a
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function store($export, string $filePath, string $disk = null, string $writerType = null, $diskOptions = []);
public function store($export, string $filePath, ?string $disk = null, ?string $writerType = null, $diskOptions = []);

/**
* @param object $export
Expand All @@ -37,7 +37,7 @@ public function store($export, string $filePath, string $disk = null, string $wr
* @param mixed $diskOptions
* @return \Illuminate\Foundation\Bus\PendingDispatch
*/
public function queue($export, string $filePath, string $disk = null, string $writerType = null, $diskOptions = []);
public function queue($export, string $filePath, ?string $disk = null, ?string $writerType = null, $diskOptions = []);

/**
* @param object $export
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/ReaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ReaderFactory
*
* @throws Exception
*/
public static function make($import, TemporaryFile $file, string $readerType = null): IReader
public static function make($import, TemporaryFile $file, ?string $readerType = null): IReader
{
$reader = IOFactory::createReader(
$readerType ?: static::identify($file)
Expand Down
14 changes: 7 additions & 7 deletions src/Fakes/ExcelFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ExcelFake implements Exporter, Importer
/**
* {@inheritdoc}
*/
public function download($export, string $fileName, string $writerType = null, array $headers = [])
public function download($export, string $fileName, ?string $writerType = null, array $headers = [])
{
$this->downloads[$fileName] = $export;

Expand All @@ -69,7 +69,7 @@ public function download($export, string $fileName, string $writerType = null, a
*
* @param string|null $diskName Fallback for usage with named properties
*/
public function store($export, string $filePath, string $disk = null, string $writerType = null, $diskOptions = [], string $diskName = null)
public function store($export, string $filePath, ?string $disk = null, ?string $writerType = null, $diskOptions = [], ?string $diskName = null)
{
if ($export instanceof ShouldQueue) {
return $this->queue($export, $filePath, $disk ?: $diskName, $writerType);
Expand All @@ -83,7 +83,7 @@ public function store($export, string $filePath, string $disk = null, string $wr
/**
* {@inheritdoc}
*/
public function queue($export, string $filePath, string $disk = null, string $writerType = null, $diskOptions = [])
public function queue($export, string $filePath, ?string $disk = null, ?string $writerType = null, $diskOptions = [])
{
Queue::fake();

Expand Down Expand Up @@ -124,7 +124,7 @@ public function raw($export, string $writerType)
* @param string|null $readerType
* @return Reader|PendingDispatch
*/
public function import($import, $file, string $disk = null, string $readerType = null)
public function import($import, $file, ?string $disk = null, ?string $readerType = null)
{
if ($import instanceof ShouldQueue) {
return $this->queueImport($import, $file, $disk, $readerType);
Expand All @@ -144,7 +144,7 @@ public function import($import, $file, string $disk = null, string $readerType =
* @param string|null $readerType
* @return array
*/
public function toArray($import, $file, string $disk = null, string $readerType = null): array
public function toArray($import, $file, ?string $disk = null, ?string $readerType = null): array
{
$filePath = ($file instanceof UploadedFile) ? $file->getFilename() : $file;

Expand All @@ -160,7 +160,7 @@ public function toArray($import, $file, string $disk = null, string $readerType
* @param string|null $readerType
* @return Collection
*/
public function toCollection($import, $file, string $disk = null, string $readerType = null): Collection
public function toCollection($import, $file, ?string $disk = null, ?string $readerType = null): Collection
{
$filePath = ($file instanceof UploadedFile) ? $file->getFilename() : $file;

Expand All @@ -176,7 +176,7 @@ public function toCollection($import, $file, string $disk = null, string $reader
* @param string $readerType
* @return PendingDispatch
*/
public function queueImport(ShouldQueue $import, $file, string $disk = null, string $readerType = null)
public function queueImport(ShouldQueue $import, $file, ?string $disk = null, ?string $readerType = null)
{
Queue::fake();

Expand Down
2 changes: 1 addition & 1 deletion src/Files/Disk.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Disk
* @param string|null $name
* @param array $diskOptions
*/
public function __construct(IlluminateFilesystem $disk, string $name = null, array $diskOptions = [])
public function __construct(IlluminateFilesystem $disk, ?string $name = null, array $diskOptions = [])
{
$this->disk = $disk;
$this->name = $name;
Expand Down
2 changes: 1 addition & 1 deletion src/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(Factory $filesystem)
* @param array $diskOptions
* @return Disk
*/
public function disk(string $disk = null, array $diskOptions = []): Disk
public function disk(?string $disk = null, array $diskOptions = []): Disk
{
return new Disk(
$this->filesystem->disk($disk),
Expand Down
2 changes: 1 addition & 1 deletion src/Files/TemporaryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function sync(): TemporaryFile
* @param string|null $disk
* @return TemporaryFile
*/
public function copyFrom($filePath, string $disk = null): TemporaryFile
public function copyFrom($filePath, ?string $disk = null): TemporaryFile
{
if ($filePath instanceof UploadedFile) {
$readStream = fopen($filePath->getRealPath(), 'rb');
Expand Down
10 changes: 5 additions & 5 deletions src/Files/TemporaryFileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TemporaryFileFactory
* @param string|null $temporaryPath
* @param string|null $temporaryDisk
*/
public function __construct(string $temporaryPath = null, string $temporaryDisk = null)
public function __construct(?string $temporaryPath = null, ?string $temporaryDisk = null)
{
$this->temporaryPath = $temporaryPath;
$this->temporaryDisk = $temporaryDisk;
Expand All @@ -30,7 +30,7 @@ public function __construct(string $temporaryPath = null, string $temporaryDisk
* @param string|null $fileExtension
* @return TemporaryFile
*/
public function make(string $fileExtension = null): TemporaryFile
public function make(?string $fileExtension = null): TemporaryFile
{
if (null !== $this->temporaryDisk) {
return $this->makeRemote($fileExtension);
Expand All @@ -44,7 +44,7 @@ public function make(string $fileExtension = null): TemporaryFile
* @param string|null $fileExtension
* @return LocalTemporaryFile
*/
public function makeLocal(string $fileName = null, string $fileExtension = null): LocalTemporaryFile
public function makeLocal(?string $fileName = null, ?string $fileExtension = null): LocalTemporaryFile
{
if (!file_exists($this->temporaryPath) && !mkdir($concurrentDirectory = $this->temporaryPath, config('excel.temporary_files.local_permissions.dir', 0777), true) && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
Expand All @@ -59,7 +59,7 @@ public function makeLocal(string $fileName = null, string $fileExtension = null)
* @param string|null $fileExtension
* @return RemoteTemporaryFile
*/
private function makeRemote(string $fileExtension = null): RemoteTemporaryFile
private function makeRemote(?string $fileExtension = null): RemoteTemporaryFile
{
$filename = $this->generateFilename($fileExtension);

Expand All @@ -74,7 +74,7 @@ private function makeRemote(string $fileExtension = null): RemoteTemporaryFile
* @param string|null $fileExtension
* @return string
*/
private function generateFilename(string $fileExtension = null): string
private function generateFilename(?string $fileExtension = null): string
{
return 'laravel-excel-' . Str::random(32) . ($fileExtension ? '.' . $fileExtension : '');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/FileTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FileTypeDetector
*
* @throws NoTypeDetectedException
*/
public static function detect($filePath, string $type = null)
public static function detect($filePath, ?string $type = null)
{
if (null !== $type) {
return $type;
Expand All @@ -41,7 +41,7 @@ public static function detect($filePath, string $type = null)
*
* @throws NoTypeDetectedException
*/
public static function detectStrict(string $filePath, string $type = null): string
public static function detectStrict(string $filePath, ?string $type = null): string
{
$type = static::detect($filePath, $type);

Expand Down
Loading

0 comments on commit 6261631

Please sign in to comment.