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

LinkRenderPresenterAction::isApplicable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
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
?>