Completed
Push — master ( 3a3759...49115f )
by Jakub
17:00
created

LinkRenderPresenterAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Menu;
5
6
use Nette\Application\LinkGenerator,
7
    Nette\Application\UI\InvalidLinkException;
8
9
/**
10
 * LinkRendererPresenterAction
11
 *
12
 * @author Jakub Konečný
13
 */
14 1
final class LinkRenderPresenterAction extends BaseLinkRender {
15
  protected $name = "presenterAction";
16
  
17
  /** @var LinkGenerator */
18
  private $linkGenerator;
19
  
20
  public function __construct(LinkGenerator $linkGenerator) {
21 1
    $this->linkGenerator = $linkGenerator;
22 1
  }
23
  
24
  public function isApplicable(string $link): bool {
25
    try {
26 1
      $this->linkGenerator->link($link);
27 1
      return true;
28 1
    } catch(InvalidLinkException $e) {
29 1
      return false;
30
    }
31
  }
32
  
33
  public function renderLink(string $link): string {
34
    try {
35 1
      return $this->linkGenerator->link($link);
36 1
    } catch(InvalidLinkException $e) {
37 1
      return "";
38
    }
39
  }
40
}
41
?>