Skip to content

Commit 821a2db

Browse files
committed
type hinting
1 parent c0ccd18 commit 821a2db

11 files changed

Lines changed: 70 additions & 265 deletions

src/Exceptions/DownloadableImportValidationException.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@
99

1010
namespace Javaabu\Imports\Exceptions;
1111

12+
use Illuminate\Http\Response;
13+
use Illuminate\Http\RedirectResponse;
1214
use Javaabu\Imports\Exports\ErrorsExport;
13-
use Maatwebsite\Excel\Concerns\Exportable;
1415

1516
class DownloadableImportValidationException extends ImportValidationException
1617
{
17-
/**
18-
* @var Exportable
19-
*/
20-
protected $exportable;
18+
protected ErrorsExport $exportable;
2119

22-
/**
23-
* @var string
24-
*/
25-
protected $export_file_name;
20+
protected string $export_file_name;
2621

2722
/**
2823
* Constructor
@@ -38,30 +33,24 @@ public function __construct(ErrorsExport $exportable, $export_file_name, array $
3833

3934
/**
4035
* Get the exportable file name
41-
*
42-
* @return string
4336
*/
44-
public function getExportFileName()
37+
public function getExportFileName(): string
4538
{
4639
return $this->export_file_name;
4740
}
4841

4942
/**
5043
* Get the exportable
51-
*
52-
* @return Exportable
5344
*/
54-
public function getExportable()
45+
public function getExportable(): ErrorsExport
5546
{
5647
return $this->exportable;
5748
}
5849

5950
/**
6051
* Send json response
61-
*
62-
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
6352
*/
64-
protected function sendHttpResponse()
53+
protected function sendHttpResponse(): Response|RedirectResponse
6554
{
6655
return $this->getExportable()->download($this->getExportFileName());
6756
}

src/Exceptions/ImportValidationException.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,16 @@
99

1010
namespace Javaabu\Imports\Exceptions;
1111

12+
use Illuminate\Http\Response;
1213
use Illuminate\Http\JsonResponse;
14+
use Illuminate\Http\RedirectResponse;
1315
use Javaabu\Helpers\Exceptions\AppException;
1416

1517
class ImportValidationException extends AppException
1618
{
17-
/**
18-
* @var array
19-
*/
20-
protected $errors;
19+
protected ?array $errors;
2120

22-
/**
23-
* Constructor
24-
*
25-
* @param string $message
26-
* @param string $name
27-
*/
28-
public function __construct(array $errors, $message = 'Import data is invalid', $name = 'ImportValidationErrors')
21+
public function __construct(array $errors, ?string $message = 'Import data is invalid', ?string $name = 'ImportValidationErrors')
2922
{
3023
parent::__construct(422, $name, $message);
3124

@@ -34,30 +27,24 @@ public function __construct(array $errors, $message = 'Import data is invalid',
3427

3528
/**
3629
* Get the errors
37-
*
38-
* @return array
3930
*/
40-
public function getErrors()
31+
public function getErrors(): ?array
4132
{
4233
return $this->errors;
4334
}
4435

4536
/**
4637
* Send json response
47-
*
48-
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
4938
*/
50-
protected function sendHttpResponse()
39+
protected function sendHttpResponse(): Response|RedirectResponse
5140
{
5241
return back()->withErrors($this->getErrors(), 'import_errors');
5342
}
5443

5544
/**
5645
* Send json response
57-
*
58-
* @return JsonResponse
5946
*/
60-
protected function sendJsonResponse()
47+
protected function sendJsonResponse(): JsonResponse
6148
{
6249
return response()->json([
6350
'message' => $this->getMessage(),

src/Exceptions/TooManyRowsException.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,23 @@
99

1010
namespace Javaabu\Imports\Exceptions;
1111

12+
use Illuminate\Http\Response;
1213
use Illuminate\Http\JsonResponse;
14+
use Illuminate\Http\RedirectResponse;
1315
use Javaabu\Helpers\Exceptions\AppException;
1416

1517
class TooManyRowsException extends AppException
1618
{
17-
/**
18-
* @var int
19-
*/
20-
protected $count;
19+
protected int $count;
2120

22-
/**
23-
* @var string
24-
*/
25-
protected $file_name;
21+
protected ?string $file_name;
2622

27-
/**
28-
* Constructor
29-
*
30-
* @param string $file_name
31-
* @param string $message
32-
* @param string $name
33-
*/
34-
public function __construct(int $count, $file_name = '', $message = 'The import file contains too many rows to import in one go. The data would be imported in the background and you would be notified via email once the data is imported.', $name = 'TooManyRows')
35-
{
23+
public function __construct(
24+
int $count,
25+
?string $file_name = '',
26+
?string $message = 'The import file contains too many rows to import in one go. The data would be imported in the background and you would be notified via email once the data is imported.',
27+
?string $name = 'TooManyRows'
28+
) {
3629
parent::__construct(422, $name, $message);
3730

3831
$this->count = $count;
@@ -41,30 +34,24 @@ public function __construct(int $count, $file_name = '', $message = 'The import
4134

4235
/**
4336
* Get the count
44-
*
45-
* @return int
4637
*/
47-
public function getCount()
38+
public function getCount(): int
4839
{
4940
return $this->count;
5041
}
5142

5243
/**
5344
* Get the filename
54-
*
55-
* @return int
5645
*/
57-
public function getFileName()
46+
public function getFileName(): ?string
5847
{
5948
return $this->file_name;
6049
}
6150

6251
/**
6352
* Send json response
64-
*
65-
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
6653
*/
67-
protected function sendHttpResponse()
54+
protected function sendHttpResponse(): Response|RedirectResponse
6855
{
6956
return back()->with([
7057
'row_count' => $this->getCount(),
@@ -75,10 +62,8 @@ protected function sendHttpResponse()
7562

7663
/**
7764
* Send json response
78-
*
79-
* @return JsonResponse
8065
*/
81-
protected function sendJsonResponse()
66+
protected function sendJsonResponse(): JsonResponse
8267
{
8368
return response()->json([
8469
'message' => $this->getMessage(),

src/Exports/ErrorsExport.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,12 @@ class ErrorsExport implements WithMultipleSheets
1111
{
1212
use Exportable;
1313

14-
/**
15-
* @var array
16-
*/
17-
protected $headings;
18-
19-
/**
20-
* @var array
21-
*/
22-
protected $invalid_rows;
23-
24-
/**
25-
* @var array
26-
*/
27-
protected $valid_rows;
28-
29-
/**
30-
* Errors Export constructor.
31-
*/
14+
protected ?array $headings;
15+
16+
protected ?array $invalid_rows;
17+
18+
protected ?array $valid_rows;
19+
3220
public function __construct(array $valid_rows, array $invalid_rows, array $headings)
3321
{
3422
$this->valid_rows = $valid_rows;

src/Exports/ImportTemplate.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ class ImportTemplate implements FromArray, ShouldAutoSize, WithHeadings
1111
{
1212
use Exportable;
1313

14-
/**
15-
* @var array
16-
*/
17-
protected $headings;
18-
19-
/**
20-
* @var array
21-
*/
22-
protected $dummy_data;
23-
24-
/**
25-
* Create a new vendors export instance.
26-
*/
14+
protected ?array $headings;
15+
16+
protected ?array $dummy_data;
17+
2718
public function __construct(array $headings, array $dummy_data)
2819
{
2920
$this->headings = $headings;

src/Exports/Sheets/InvalidRowsSheet.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,10 @@ class InvalidRowsSheet implements FromArray, ShouldAutoSize, WithHeadings, WithT
1212
{
1313
use Exportable;
1414

15-
/**
16-
* @var array
17-
*/
18-
protected $headings;
19-
20-
/**
21-
* @var array
22-
*/
23-
protected $data;
24-
25-
/**
26-
* Create a new vendors export instance.
27-
*/
15+
protected ?array $headings;
16+
17+
protected ?array $data;
18+
2819
public function __construct(array $headings, array $data)
2920
{
3021
$this->headings = $headings;

src/Http/Requests/ImportsRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public function authorize(): bool
1616
public function rules(): array
1717
{
1818
return [
19-
'model' => 'string|required|in:'.implode(',', array_keys(ImportsRepository::getImportablesList($this->user()))),
20-
'import_file' => AllowedMimeTypes::getValidationRule('excel').'|required_unless:action,download_template',
21-
'action' => 'string|in:download_template',
19+
'model' => 'string|required|in:' . implode(',', array_keys(ImportsRepository::getImportablesList($this->user()))),
20+
'import_file' => AllowedMimeTypes::getValidationRule('excel') . '|required_unless:action,download_template',
21+
'action' => 'string|in:download_template',
2222
'overwrite_duplicates' => 'boolean',
23-
'error_handler' => 'in:download,display',
23+
'error_handler' => 'in:download,display',
2424
];
2525
}
2626
}

0 commit comments

Comments
 (0)