Skip to content

Commit ed2e92c

Browse files
committed
promoted readonly properties
1 parent 6f6782d commit ed2e92c

File tree

7 files changed

+25
-55
lines changed

7 files changed

+25
-55
lines changed

src/Application/Application.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,14 @@ class Application
4848
/** @var Request[] */
4949
private array $requests = [];
5050
private ?IPresenter $presenter = null;
51-
private Nette\Http\IRequest $httpRequest;
52-
private Nette\Http\IResponse $httpResponse;
53-
private IPresenterFactory $presenterFactory;
54-
private Router $router;
5551

5652

5753
public function __construct(
58-
IPresenterFactory $presenterFactory,
59-
Router $router,
60-
Nette\Http\IRequest $httpRequest,
61-
Nette\Http\IResponse $httpResponse,
54+
private readonly IPresenterFactory $presenterFactory,
55+
private readonly Router $router,
56+
private readonly Nette\Http\IRequest $httpRequest,
57+
private readonly Nette\Http\IResponse $httpResponse,
6258
) {
63-
$this->httpRequest = $httpRequest;
64-
$this->httpResponse = $httpResponse;
65-
$this->presenterFactory = $presenterFactory;
66-
$this->router = $router;
6759
}
6860

6961

src/Application/Responses/FileResponse.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,20 @@
1919
final class FileResponse implements Nette\Application\Response
2020
{
2121
public bool $resuming = true;
22-
private string $file;
23-
private string $contentType;
24-
private string $name;
25-
private bool $forceDownload;
22+
private readonly string $name;
2623

2724

2825
public function __construct(
29-
string $file,
26+
private readonly string $file,
3027
?string $name = null,
31-
?string $contentType = null,
32-
bool $forceDownload = true,
28+
private readonly string $contentType = 'application/octet-stream',
29+
private readonly bool $forceDownload = true,
3330
) {
3431
if (!is_file($file) || !is_readable($file)) {
3532
throw new Nette\Application\BadRequestException("File '$file' doesn't exist or is not readable.");
3633
}
3734

38-
$this->file = $file;
3935
$this->name = $name ?? basename($file);
40-
$this->contentType = $contentType ?? 'application/octet-stream';
41-
$this->forceDownload = $forceDownload;
4236
}
4337

4438

src/Application/Responses/ForwardResponse.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
*/
1818
final class ForwardResponse implements Nette\Application\Response
1919
{
20-
private Nette\Application\Request $request;
21-
22-
23-
public function __construct(Nette\Application\Request $request)
24-
{
25-
$this->request = $request;
20+
public function __construct(
21+
private readonly Nette\Application\Request $request,
22+
) {
2623
}
2724

2825

src/Application/Responses/JsonResponse.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717
*/
1818
final class JsonResponse implements Nette\Application\Response
1919
{
20-
private mixed $payload;
21-
private string $contentType;
22-
23-
24-
public function __construct(mixed $payload, ?string $contentType = null)
25-
{
26-
$this->payload = $payload;
27-
$this->contentType = $contentType ?? 'application/json';
20+
public function __construct(
21+
private readonly mixed $payload,
22+
private readonly string $contentType = 'application/json',
23+
) {
2824
}
2925

3026

src/Application/Responses/RedirectResponse.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818
*/
1919
final class RedirectResponse implements Nette\Application\Response
2020
{
21-
private string $url;
22-
private int $httpCode;
23-
24-
25-
public function __construct(string $url, int $httpCode = Http\IResponse::S302_Found)
26-
{
27-
$this->url = $url;
28-
$this->httpCode = $httpCode;
21+
public function __construct(
22+
private readonly string $url,
23+
private readonly int $httpCode = Http\IResponse::S302_Found,
24+
) {
2925
}
3026

3127

src/Application/Responses/TextResponse.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
*/
1818
final class TextResponse implements Nette\Application\Response
1919
{
20-
private mixed $source;
21-
22-
23-
public function __construct(mixed $source)
24-
{
25-
$this->source = $source;
20+
public function __construct(
21+
private readonly mixed $source,
22+
) {
2623
}
2724

2825

src/Application/Routers/CliRouter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ final class CliRouter implements Nette\Routing\Router
2020
{
2121
private const PresenterKey = 'action';
2222

23-
private array $defaults;
2423

25-
26-
public function __construct(array $defaults = [])
27-
{
28-
$this->defaults = $defaults;
24+
public function __construct(
25+
private readonly array $defaults = [],
26+
) {
2927
}
3028

3129

0 commit comments

Comments
 (0)