From 62616317c5ec07e885c5d7f6b537f57a7239c2ff Mon Sep 17 00:00:00 2001 From: Joost de Bruijn Date: Mon, 25 Nov 2024 19:41:59 +0100 Subject: [PATCH] refactor: explicit nullable parameters (#4251) --- src/Cache/MemoryCache.php | 2 +- src/Cache/MemoryCacheDeprecated.php | 2 +- src/Concerns/Exportable.php | 6 +++--- src/Concerns/Importable.php | 8 ++++---- src/Excel.php | 16 ++++++++-------- src/Exceptions/NoFilePathGivenException.php | 2 +- src/Exceptions/NoFilenameGivenException.php | 2 +- src/Exceptions/NoTypeDetectedException.php | 2 +- src/Exceptions/UnreadableFileException.php | 2 +- src/Exporter.php | 6 +++--- src/Factories/ReaderFactory.php | 2 +- src/Fakes/ExcelFake.php | 14 +++++++------- src/Files/Disk.php | 2 +- src/Files/Filesystem.php | 2 +- src/Files/TemporaryFile.php | 2 +- src/Files/TemporaryFileFactory.php | 10 +++++----- src/Helpers/FileTypeDetector.php | 4 ++-- src/Importer.php | 8 ++++---- src/Imports/EndRowFinder.php | 2 +- src/Imports/HeadingRowFormatter.php | 2 +- src/Jobs/QueueImport.php | 2 +- src/Jobs/StoreQueuedExport.php | 2 +- src/Mixins/DownloadCollectionMixin.php | 2 +- src/Mixins/DownloadQueryMacro.php | 2 +- src/Mixins/ImportAsMacro.php | 2 +- src/Mixins/ImportMacro.php | 2 +- src/Mixins/StoreCollectionMixin.php | 2 +- src/Mixins/StoreQueryMacro.php | 2 +- src/QueuedWriter.php | 2 +- src/Reader.php | 8 ++++---- src/Row.php | 2 +- src/Sheet.php | 6 +++--- src/Writer.php | 2 +- 33 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/Cache/MemoryCache.php b/src/Cache/MemoryCache.php index 8854529be..977458558 100644 --- a/src/Cache/MemoryCache.php +++ b/src/Cache/MemoryCache.php @@ -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; } diff --git a/src/Cache/MemoryCacheDeprecated.php b/src/Cache/MemoryCacheDeprecated.php index 9c5cca757..92844d390 100644 --- a/src/Cache/MemoryCacheDeprecated.php +++ b/src/Cache/MemoryCacheDeprecated.php @@ -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; } diff --git a/src/Concerns/Exportable.php b/src/Concerns/Exportable.php index 3004ef954..3aa2e1938 100644 --- a/src/Concerns/Exportable.php +++ b/src/Concerns/Exportable.php @@ -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; @@ -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; @@ -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; diff --git a/src/Concerns/Importable.php b/src/Concerns/Importable.php index 13be397a1..6c3c359ba 100644 --- a/src/Concerns/Importable.php +++ b/src/Concerns/Importable.php @@ -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); @@ -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); @@ -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); @@ -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.'); diff --git a/src/Excel.php b/src/Excel.php index c78564350..d784c9604 100644 --- a/src/Excel.php +++ b/src/Excel.php @@ -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) { @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); } @@ -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); diff --git a/src/Exceptions/NoFilePathGivenException.php b/src/Exceptions/NoFilePathGivenException.php index 494cae900..06a8865b7 100644 --- a/src/Exceptions/NoFilePathGivenException.php +++ b/src/Exceptions/NoFilePathGivenException.php @@ -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); } diff --git a/src/Exceptions/NoFilenameGivenException.php b/src/Exceptions/NoFilenameGivenException.php index 2fa8dcf5e..a5bbbe971 100644 --- a/src/Exceptions/NoFilenameGivenException.php +++ b/src/Exceptions/NoFilenameGivenException.php @@ -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); } diff --git a/src/Exceptions/NoTypeDetectedException.php b/src/Exceptions/NoTypeDetectedException.php index ecb44b93d..04a97d603 100644 --- a/src/Exceptions/NoTypeDetectedException.php +++ b/src/Exceptions/NoTypeDetectedException.php @@ -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); } diff --git a/src/Exceptions/UnreadableFileException.php b/src/Exceptions/UnreadableFileException.php index 36213d274..4ff840134 100644 --- a/src/Exceptions/UnreadableFileException.php +++ b/src/Exceptions/UnreadableFileException.php @@ -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); } diff --git a/src/Exporter.php b/src/Exporter.php index fe9e2489a..06c2c7dc7 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -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 @@ -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 @@ -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 diff --git a/src/Factories/ReaderFactory.php b/src/Factories/ReaderFactory.php index 3a0ee7de8..dcab8f6eb 100644 --- a/src/Factories/ReaderFactory.php +++ b/src/Factories/ReaderFactory.php @@ -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) diff --git a/src/Fakes/ExcelFake.php b/src/Fakes/ExcelFake.php index d8cb0aadd..ff42d5c98 100644 --- a/src/Fakes/ExcelFake.php +++ b/src/Fakes/ExcelFake.php @@ -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; @@ -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); @@ -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(); @@ -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); @@ -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; @@ -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; @@ -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(); diff --git a/src/Files/Disk.php b/src/Files/Disk.php index ea4bd3947..023e9329d 100644 --- a/src/Files/Disk.php +++ b/src/Files/Disk.php @@ -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; diff --git a/src/Files/Filesystem.php b/src/Files/Filesystem.php index b70815d4f..88cc47b90 100644 --- a/src/Files/Filesystem.php +++ b/src/Files/Filesystem.php @@ -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), diff --git a/src/Files/TemporaryFile.php b/src/Files/TemporaryFile.php index ebf849c1c..501f41d7b 100644 --- a/src/Files/TemporaryFile.php +++ b/src/Files/TemporaryFile.php @@ -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'); diff --git a/src/Files/TemporaryFileFactory.php b/src/Files/TemporaryFileFactory.php index d3cef4133..b67a97fb0 100644 --- a/src/Files/TemporaryFileFactory.php +++ b/src/Files/TemporaryFileFactory.php @@ -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; @@ -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); @@ -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)); @@ -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); @@ -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 : ''); } diff --git a/src/Helpers/FileTypeDetector.php b/src/Helpers/FileTypeDetector.php index 4b55bf86d..d855e4fd6 100644 --- a/src/Helpers/FileTypeDetector.php +++ b/src/Helpers/FileTypeDetector.php @@ -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; @@ -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); diff --git a/src/Importer.php b/src/Importer.php index 2f15bb914..db4c2e91a 100644 --- a/src/Importer.php +++ b/src/Importer.php @@ -14,7 +14,7 @@ interface Importer * @param string|null $readerType * @return Reader|\Illuminate\Foundation\Bus\PendingDispatch */ - public function import($import, $filePath, string $disk = null, string $readerType = null); + public function import($import, $filePath, ?string $disk = null, ?string $readerType = null); /** * @param object $import @@ -23,7 +23,7 @@ public function import($import, $filePath, string $disk = null, string $readerTy * @param string|null $readerType * @return array */ - public function toArray($import, $filePath, string $disk = null, string $readerType = null): array; + public function toArray($import, $filePath, ?string $disk = null, ?string $readerType = null): array; /** * @param object $import @@ -32,7 +32,7 @@ public function toArray($import, $filePath, string $disk = null, string $readerT * @param string|null $readerType * @return Collection */ - public function toCollection($import, $filePath, string $disk = null, string $readerType = null): Collection; + public function toCollection($import, $filePath, ?string $disk = null, ?string $readerType = null): Collection; /** * @param ShouldQueue $import @@ -41,5 +41,5 @@ public function toCollection($import, $filePath, string $disk = null, string $re * @param string $readerType * @return \Illuminate\Foundation\Bus\PendingDispatch */ - public function queueImport(ShouldQueue $import, $filePath, string $disk = null, string $readerType = null); + public function queueImport(ShouldQueue $import, $filePath, ?string $disk = null, ?string $readerType = null); } diff --git a/src/Imports/EndRowFinder.php b/src/Imports/EndRowFinder.php index 285cb25fe..2049d2dd8 100644 --- a/src/Imports/EndRowFinder.php +++ b/src/Imports/EndRowFinder.php @@ -12,7 +12,7 @@ class EndRowFinder * @param int|null $highestRow * @return int|null */ - public static function find($import, int $startRow = null, int $highestRow = null) + public static function find($import, ?int $startRow = null, ?int $highestRow = null) { if (!$import instanceof WithLimit) { return null; diff --git a/src/Imports/HeadingRowFormatter.php b/src/Imports/HeadingRowFormatter.php index 5a651d209..5c3e1f1be 100644 --- a/src/Imports/HeadingRowFormatter.php +++ b/src/Imports/HeadingRowFormatter.php @@ -50,7 +50,7 @@ public static function format(array $headings): array /** * @param string $name */ - public static function default(string $name = null) + public static function default(?string $name = null) { if (null !== $name && !isset(static::$customFormatters[$name]) && !in_array($name, static::$defaultFormatters, true)) { throw new InvalidArgumentException(sprintf('Formatter "%s" does not exist', $name)); diff --git a/src/Jobs/QueueImport.php b/src/Jobs/QueueImport.php index 1e3cc3a02..243e556a5 100644 --- a/src/Jobs/QueueImport.php +++ b/src/Jobs/QueueImport.php @@ -22,7 +22,7 @@ class QueueImport implements ShouldQueue /** * @param ShouldQueue $import */ - public function __construct(ShouldQueue $import = null) + public function __construct(?ShouldQueue $import = null) { if ($import) { $this->timeout = $import->timeout ?? null; diff --git a/src/Jobs/StoreQueuedExport.php b/src/Jobs/StoreQueuedExport.php index 5469a927f..8f6a79013 100644 --- a/src/Jobs/StoreQueuedExport.php +++ b/src/Jobs/StoreQueuedExport.php @@ -36,7 +36,7 @@ class StoreQueuedExport implements ShouldQueue * @param string|null $disk * @param array|string $diskOptions */ - public function __construct(TemporaryFile $temporaryFile, string $filePath, string $disk = null, $diskOptions = []) + public function __construct(TemporaryFile $temporaryFile, string $filePath, ?string $disk = null, $diskOptions = []) { $this->disk = $disk; $this->filePath = $filePath; diff --git a/src/Mixins/DownloadCollectionMixin.php b/src/Mixins/DownloadCollectionMixin.php index c8a0f4616..42985e773 100644 --- a/src/Mixins/DownloadCollectionMixin.php +++ b/src/Mixins/DownloadCollectionMixin.php @@ -16,7 +16,7 @@ class DownloadCollectionMixin */ public function downloadExcel() { - return function (string $fileName, string $writerType = null, $withHeadings = false, array $responseHeaders = []) { + return function (string $fileName, ?string $writerType = null, $withHeadings = false, array $responseHeaders = []) { $export = new class($this, $withHeadings) implements FromCollection, WithHeadings { use Exportable; diff --git a/src/Mixins/DownloadQueryMacro.php b/src/Mixins/DownloadQueryMacro.php index 9780eb63f..8c5707668 100644 --- a/src/Mixins/DownloadQueryMacro.php +++ b/src/Mixins/DownloadQueryMacro.php @@ -12,7 +12,7 @@ class DownloadQueryMacro { public function __invoke() { - return function (string $fileName, string $writerType = null, $withHeadings = false) { + return function (string $fileName, ?string $writerType = null, $withHeadings = false) { $export = new class($this, $withHeadings) implements FromQuery, WithHeadings { use Exportable; diff --git a/src/Mixins/ImportAsMacro.php b/src/Mixins/ImportAsMacro.php index 64422f1dd..a58544a45 100644 --- a/src/Mixins/ImportAsMacro.php +++ b/src/Mixins/ImportAsMacro.php @@ -10,7 +10,7 @@ class ImportAsMacro { public function __invoke() { - return function (string $filename, callable $mapping, string $disk = null, string $readerType = null) { + return function (string $filename, callable $mapping, ?string $disk = null, ?string $readerType = null) { $import = new class(get_class($this->getModel()), $mapping) implements ToModel { use Importable; diff --git a/src/Mixins/ImportMacro.php b/src/Mixins/ImportMacro.php index 4085fb47a..a3630b3a4 100644 --- a/src/Mixins/ImportMacro.php +++ b/src/Mixins/ImportMacro.php @@ -11,7 +11,7 @@ class ImportMacro { public function __invoke() { - return function (string $filename, string $disk = null, string $readerType = null) { + return function (string $filename, ?string $disk = null, ?string $readerType = null) { $import = new class(get_class($this->getModel())) implements ToModel, WithHeadingRow { use Importable; diff --git a/src/Mixins/StoreCollectionMixin.php b/src/Mixins/StoreCollectionMixin.php index 72e99f915..eadb1581b 100644 --- a/src/Mixins/StoreCollectionMixin.php +++ b/src/Mixins/StoreCollectionMixin.php @@ -14,7 +14,7 @@ class StoreCollectionMixin */ public function storeExcel() { - return function (string $filePath, string $disk = null, string $writerType = null, $withHeadings = false) { + return function (string $filePath, ?string $disk = null, ?string $writerType = null, $withHeadings = false) { $export = new class($this, $withHeadings) implements FromCollection, WithHeadings { use Exportable; diff --git a/src/Mixins/StoreQueryMacro.php b/src/Mixins/StoreQueryMacro.php index 5afb304b2..84ed9ceda 100644 --- a/src/Mixins/StoreQueryMacro.php +++ b/src/Mixins/StoreQueryMacro.php @@ -12,7 +12,7 @@ class StoreQueryMacro { public function __invoke() { - return function (string $filePath, string $disk = null, string $writerType = null, $withHeadings = false) { + return function (string $filePath, ?string $disk = null, ?string $writerType = null, $withHeadings = false) { $export = new class($this, $withHeadings) implements FromQuery, WithHeadings { use Exportable; diff --git a/src/QueuedWriter.php b/src/QueuedWriter.php index a8c6a6699..86d2fa4c0 100644 --- a/src/QueuedWriter.php +++ b/src/QueuedWriter.php @@ -58,7 +58,7 @@ public function __construct(Writer $writer, TemporaryFileFactory $temporaryFileF * @param array|string $diskOptions * @return \Illuminate\Foundation\Bus\PendingDispatch */ - 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 = []) { $extension = pathinfo($filePath, PATHINFO_EXTENSION); $temporaryFile = $this->temporaryFileFactory->make($extension); diff --git a/src/Reader.php b/src/Reader.php index f6a70ba15..b2fbc1c2f 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -97,7 +97,7 @@ public function __wakeup() * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException * @throws Exception */ - public function read($import, $filePath, string $readerType = null, string $disk = null) + public function read($import, $filePath, ?string $readerType = null, ?string $disk = null) { $this->reader = $this->getReader($import, $filePath, $readerType, $disk); @@ -151,7 +151,7 @@ public function read($import, $filePath, string $readerType = null, string $disk * @throws NoTypeDetectedException * @throws Exceptions\SheetNotFoundException */ - public function toArray($import, $filePath, string $readerType = null, string $disk = null): array + public function toArray($import, $filePath, ?string $readerType = null, ?string $disk = null): array { $this->reader = $this->getReader($import, $filePath, $readerType, $disk); @@ -195,7 +195,7 @@ public function toArray($import, $filePath, string $readerType = null, string $d * @throws NoTypeDetectedException * @throws Exceptions\SheetNotFoundException */ - public function toCollection($import, $filePath, string $readerType = null, string $disk = null): Collection + public function toCollection($import, $filePath, ?string $readerType = null, ?string $disk = null): Collection { $this->reader = $this->getReader($import, $filePath, $readerType, $disk); $this->loadSpreadsheet($import); @@ -419,7 +419,7 @@ private function buildSheetImports($import): array * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception * @throws InvalidArgumentException */ - private function getReader($import, $filePath, string $readerType = null, string $disk = null): IReader + private function getReader($import, $filePath, ?string $readerType = null, ?string $disk = null): IReader { $shouldQueue = $import instanceof ShouldQueue; if ($shouldQueue && !$import instanceof WithChunkReading) { diff --git a/src/Row.php b/src/Row.php index cdd55a1c9..2261e6640 100644 --- a/src/Row.php +++ b/src/Row.php @@ -169,7 +169,7 @@ public function offsetUnset($offset) * * @internal */ - public function setPreparationCallback(Closure $preparationCallback = null) + public function setPreparationCallback(?Closure $preparationCallback = null) { $this->preparationCallback = $preparationCallback; } diff --git a/src/Sheet.php b/src/Sheet.php index 26d0b8f2a..37435a523 100644 --- a/src/Sheet.php +++ b/src/Sheet.php @@ -325,7 +325,7 @@ public function import($import, int $startRow = 1) * @param bool $formatData * @return array */ - public function toArray($import, int $startRow = null, $nullValue = null, $calculateFormulas = false, $formatData = false) + public function toArray($import, ?int $startRow = null, $nullValue = null, $calculateFormulas = false, $formatData = false) { if ($startRow > $this->worksheet->getHighestRow()) { return []; @@ -376,7 +376,7 @@ public function toArray($import, int $startRow = null, $nullValue = null, $calcu * @param bool $formatData * @return Collection */ - public function toCollection($import, int $startRow = null, $nullValue = null, $calculateFormulas = false, $formatData = false): Collection + public function toCollection($import, ?int $startRow = null, $nullValue = null, $calculateFormulas = false, $formatData = false): Collection { $rows = $this->toArray($import, $startRow, $nullValue, $calculateFormulas, $formatData); @@ -544,7 +544,7 @@ public function fromGenerator(FromGenerator $sheetExport) * @param string|null $startCell * @param bool $strictNullComparison */ - public function append(array $rows, string $startCell = null, bool $strictNullComparison = false) + public function append(array $rows, ?string $startCell = null, bool $strictNullComparison = false) { if (!$startCell) { $startCell = 'A1'; diff --git a/src/Writer.php b/src/Writer.php index 04f6afc43..1cbfbcf82 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -203,7 +203,7 @@ public function write($export, TemporaryFile $temporaryFile, string $writerType) * * @throws \PhpOffice\PhpSpreadsheet\Exception */ - public function addNewSheet(int $sheetIndex = null) + public function addNewSheet(?int $sheetIndex = null) { return new Sheet($this->spreadsheet->createSheet($sheetIndex)); }