Completed
Push — master ( 546114...e895bf )
by Pavel
03:26
created

TLink   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createLink() 0 16 3
1
<?php
2
3
/**
4
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
5
 * @author      Pavel Janda <[email protected]>
6
 * @package     Ublaboo
7
 */
8
9
namespace Ublaboo\DataGrid\Traits;
10
11
use Ublaboo\DataGrid\DataGrid;
12
use Ublaboo\DataGrid\Exception\DataGridHasToBeAttachedToPresenterComponentException;
13
14
trait TLink
15
{
16
17
	/**
18
	 * Create link to custom destination
19
	 * @param  DataGrid $grid
20
	 * @param  string   $href
21
	 * @param  array    $params
22
	 * @return string
23
	 * @throws DataGridHasToBeAttachedToPresenterComponentException
24
	 * @throws \InvalidArgumentException
25
	 */
26
	protected function createLink(DataGrid $grid, $href, $params)
27
	{
28
		try {
29
			$parent = $grid->getParent();
30
31
			return $parent->link($href, $params);
32
		} catch (DataGridHasToBeAttachedToPresenterComponentException $e) {
33
			$parent = $grid->getPresenter();
34
35
		} catch (\InvalidArgumentException $e) {
36
			$parent = $grid->getPresenter();
37
38
		}
39
40
		return $parent->link($href, $params);
41
	}
42
43
}
44