Skip to content

Commit 8c9ac35

Browse files
committed
Component::link() & etc uses variadic parameter
1 parent 2e67846 commit 8c9ac35

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/Application/UI/Component.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ public static function formatSignalMethod(string $signal): string
249249
/**
250250
* Generates URL to presenter, action or signal.
251251
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
252-
* @param array|mixed $args
252+
* @param mixed ...$args
253253
* @throws InvalidLinkException
254254
*/
255-
public function link(string $destination, $args = []): string
255+
public function link(string $destination, ...$args): string
256256
{
257257
try {
258-
$args = func_num_args() < 3 && is_array($args)
259-
? $args
260-
: array_slice(func_get_args(), 1);
258+
$args = count($args) === 1 && is_array($args[0] ?? null)
259+
? $args[0]
260+
: $args;
261261
return $this->getPresenter()->createRequest($this, $destination, $args, 'link');
262262

263263
} catch (InvalidLinkException $e) {
@@ -269,29 +269,29 @@ public function link(string $destination, $args = []): string
269269
/**
270270
* Returns destination as Link object.
271271
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
272-
* @param array|mixed $args
272+
* @param mixed ...$args
273273
*/
274-
public function lazyLink(string $destination, $args = []): Link
274+
public function lazyLink(string $destination, ...$args): Link
275275
{
276-
$args = func_num_args() < 3 && is_array($args)
277-
? $args
278-
: array_slice(func_get_args(), 1);
276+
$args = count($args) === 1 && is_array($args[0] ?? null)
277+
? $args[0]
278+
: $args;
279279
return new Link($this, $destination, $args);
280280
}
281281

282282

283283
/**
284284
* Determines whether it links to the current page.
285285
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
286-
* @param array|mixed $args
286+
* @param mixed ...$args
287287
* @throws InvalidLinkException
288288
*/
289-
public function isLinkCurrent(?string $destination = null, $args = []): bool
289+
public function isLinkCurrent(?string $destination = null, ...$args): bool
290290
{
291291
if ($destination !== null) {
292-
$args = func_num_args() < 3 && is_array($args)
293-
? $args
294-
: array_slice(func_get_args(), 1);
292+
$args = count($args) === 1 && is_array($args[0] ?? null)
293+
? $args[0]
294+
: $args;
295295
$this->getPresenter()->createRequest($this, $destination, $args, 'test');
296296
}
297297

@@ -302,15 +302,15 @@ public function isLinkCurrent(?string $destination = null, $args = []): bool
302302
/**
303303
* Redirect to another presenter, action or signal.
304304
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
305-
* @param array|mixed $args
305+
* @param mixed ...$args
306306
* @return never
307307
* @throws Nette\Application\AbortException
308308
*/
309-
public function redirect(string $destination, $args = []): void
309+
public function redirect(string $destination, ...$args): void
310310
{
311-
$args = func_num_args() < 3 && is_array($args)
312-
? $args
313-
: array_slice(func_get_args(), 1);
311+
$args = count($args) === 1 && is_array($args[0] ?? null)
312+
? $args[0]
313+
: $args;
314314
$presenter = $this->getPresenter();
315315
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'));
316316
}
@@ -319,15 +319,15 @@ public function redirect(string $destination, $args = []): void
319319
/**
320320
* Permanently redirects to presenter, action or signal.
321321
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
322-
* @param array|mixed $args
322+
* @param mixed ...$args
323323
* @return never
324324
* @throws Nette\Application\AbortException
325325
*/
326-
public function redirectPermanent(string $destination, $args = []): void
326+
public function redirectPermanent(string $destination, ...$args): void
327327
{
328-
$args = func_num_args() < 3 && is_array($args)
329-
? $args
330-
: array_slice(func_get_args(), 1);
328+
$args = count($args) === 1 && is_array($args[0] ?? null)
329+
? $args[0]
330+
: $args;
331331
$presenter = $this->getPresenter();
332332
$presenter->redirectUrl(
333333
$presenter->createRequest($this, $destination, $args, 'redirect'),

0 commit comments

Comments
 (0)