Skip to content

Commit 887ba0b

Browse files
committed
added PHP 8 typehints
1 parent b0dc7c5 commit 887ba0b

24 files changed

+58
-115
lines changed

src/Application/LinkGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function link(string $dest, array $params = []): string
9090
}
9191

9292

93-
public function withReferenceUrl(string $url): self
93+
public function withReferenceUrl(string $url): static
9494
{
9595
return new self(
9696
$this->router,

src/Application/PresenterFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ public function getPresenterClass(string &$name): string
8383

8484
/**
8585
* Sets mapping as pairs [module => mask]
86-
* @return static
8786
*/
88-
public function setMapping(array $mapping)
87+
public function setMapping(array $mapping): static
8988
{
9089
foreach ($mapping as $module => $mask) {
9190
if (is_string($mask)) {

src/Application/Request.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ public function __construct(
7272

7373
/**
7474
* Sets the presenter name.
75-
* @return static
7675
*/
77-
public function setPresenterName(string $name)
76+
public function setPresenterName(string $name): static
7877
{
7978
$this->name = $name;
8079
return $this;
@@ -92,9 +91,8 @@ public function getPresenterName(): string
9291

9392
/**
9493
* Sets variables provided to the presenter.
95-
* @return static
9694
*/
97-
public function setParameters(array $params)
95+
public function setParameters(array $params): static
9896
{
9997
$this->params = $params;
10098
return $this;
@@ -112,19 +110,17 @@ public function getParameters(): array
112110

113111
/**
114112
* Returns a parameter provided to the presenter.
115-
* @return mixed
116113
*/
117-
public function getParameter(string $key)
114+
public function getParameter(string $key): mixed
118115
{
119116
return $this->params[$key] ?? null;
120117
}
121118

122119

123120
/**
124121
* Sets variables provided to the presenter via POST.
125-
* @return static
126122
*/
127-
public function setPost(array $params)
123+
public function setPost(array $params): static
128124
{
129125
$this->post = $params;
130126
return $this;
@@ -134,9 +130,8 @@ public function setPost(array $params)
134130
/**
135131
* Returns a variable provided to the presenter via POST.
136132
* If no key is passed, returns the entire array.
137-
* @return mixed
138133
*/
139-
public function getPost(string $key = null)
134+
public function getPost(string $key = null): mixed
140135
{
141136
return func_num_args() === 0
142137
? $this->post
@@ -146,9 +141,8 @@ public function getPost(string $key = null)
146141

147142
/**
148143
* Sets all uploaded files.
149-
* @return static
150144
*/
151-
public function setFiles(array $files)
145+
public function setFiles(array $files): static
152146
{
153147
$this->files = $files;
154148
return $this;
@@ -166,9 +160,8 @@ public function getFiles(): array
166160

167161
/**
168162
* Sets the method.
169-
* @return static
170163
*/
171-
public function setMethod(?string $method)
164+
public function setMethod(?string $method): static
172165
{
173166
$this->method = $method;
174167
return $this;
@@ -195,9 +188,8 @@ public function isMethod(string $method): bool
195188

196189
/**
197190
* Sets the flag.
198-
* @return static
199191
*/
200-
public function setFlag(string $flag, bool $value = true)
192+
public function setFlag(string $flag, bool $value = true): static
201193
{
202194
$this->flags[$flag] = $value;
203195
return $this;

src/Application/Responses/JsonResponse.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public function __construct($payload, string $contentType = null)
3131
}
3232

3333

34-
/**
35-
* @return mixed
36-
*/
37-
public function getPayload()
34+
public function getPayload(): mixed
3835
{
3936
return $this->payload;
4037
}

src/Application/Responses/TextResponse.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,13 @@ final class TextResponse implements Nette\Application\Response
2222
private mixed $source;
2323

2424

25-
/**
26-
* @param mixed $source
27-
*/
28-
public function __construct($source)
25+
public function __construct(mixed $source)
2926
{
3027
$this->source = $source;
3128
}
3229

3330

34-
/**
35-
* @return mixed
36-
*/
37-
public function getSource()
31+
public function getSource(): mixed
3832
{
3933
return $this->source;
4034
}

src/Application/Routers/RouteList.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,15 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri
6464
/**
6565
* @param string $mask e.g. '<presenter>/<action>/<id \d{1,3}>'
6666
* @param array|string|\Closure $metadata default values or metadata or callback for NetteModule\MicroPresenter
67-
* @return static
6867
*/
69-
public function addRoute(string $mask, $metadata = [], int $flags = 0)
68+
public function addRoute(string $mask, array|string|\Closure $metadata = [], int $flags = 0): static
7069
{
7170
$this->add(new Route($mask, $metadata), $flags);
7271
return $this;
7372
}
7473

7574

76-
/**
77-
* @return static
78-
*/
79-
public function withModule(string $module)
75+
public function withModule(string $module): static
8076
{
8177
$router = new static;
8278
$router->module = $module . ':';
@@ -108,11 +104,9 @@ public function offsetSet($index, $router): void
108104

109105
/**
110106
* @param int $index
111-
* @return mixed
112107
* @throws Nette\OutOfRangeException
113108
*/
114-
#[\ReturnTypeWillChange]
115-
public function offsetGet($index)
109+
public function offsetGet($index): mixed
116110
{
117111
if (!$this->offsetExists($index)) {
118112
throw new Nette\OutOfRangeException('Offset invalid or out of range');

src/Application/UI/Component.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa
3434

3535
/**
3636
* Returns the presenter where this component belongs to.
37-
* @return Presenter
3837
*/
3938
public function getPresenter(): Presenter
4039
{
@@ -90,7 +89,6 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void
9089

9190
/**
9291
* Calls public method if exists.
93-
* @return bool does method exist?
9492
*/
9593
protected function tryCall(string $method, array $params): bool
9694
{
@@ -181,9 +179,8 @@ public function saveState(array &$params): void
181179

182180
/**
183181
* Returns component param.
184-
* @return mixed
185182
*/
186-
final public function getParameter(string $name, $default = null)
183+
final public function getParameter(string $name, $default = null): mixed
187184
{
188185
return $this->params[$name] ?? $default;
189186
}

src/Application/UI/ComponentReflection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ private static function convertSingleType(&$val, string $type): bool
251251

252252
/**
253253
* Returns an annotation value.
254-
* @param \ReflectionClass|\ReflectionMethod $ref
255254
*/
256255
public static function parseAnnotation(\Reflector $ref, string $name): ?array
257256
{
@@ -301,9 +300,8 @@ public function hasAnnotation(string $name): bool
301300

302301
/**
303302
* Returns an annotation value.
304-
* @return mixed
305303
*/
306-
public function getAnnotation(string $name)
304+
public function getAnnotation(string $name): mixed
307305
{
308306
$res = self::parseAnnotation($this, $name);
309307
return $res ? end($res) : null;

src/Application/UI/Control.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ public function templatePrepareFilters(Template $template): void
9797

9898
/**
9999
* Saves the message to template, that can be displayed after redirect.
100-
* @param string|\stdClass|Nette\HtmlStringable $message
101100
*/
102-
public function flashMessage($message, string $type = 'info'): \stdClass
101+
public function flashMessage(string|\stdClass|Nette\HtmlStringable $message, string $type = 'info'): \stdClass
103102
{
104103
$id = $this->getParameterId('flash');
105104
$flash = $message instanceof \stdClass ? $message : (object) [

src/Application/UI/Link.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ public function getDestination(): string
5858

5959
/**
6060
* Changes link parameter.
61-
* @return static
6261
*/
63-
public function setParameter(string $key, $value)
62+
public function setParameter(string $key, $value): static
6463
{
6564
$this->params[$key] = $value;
6665
return $this;
@@ -69,9 +68,8 @@ public function setParameter(string $key, $value)
6968

7069
/**
7170
* Returns link parameter.
72-
* @return mixed
7371
*/
74-
public function getParameter(string $key)
72+
public function getParameter(string $key): mixed
7573
{
7674
return $this->params[$key] ?? null;
7775
}

0 commit comments

Comments
 (0)