GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TbButtonColumn   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 65
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 31.03%

Importance

Changes 0
Metric Value
dl 10
loc 65
rs 10
c 0
b 0
f 0
ccs 9
cts 29
cp 0.3103
wmc 19
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B initDefaultButtons() 6 11 7
C renderButton() 4 27 12

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * TbButtonColumn class file.
4
 * @author Christoffer Niska <[email protected]>
5
 * @copyright  Copyright &copy; Christoffer Niska 2011-
6
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7
 * @package bootstrap.widgets
8
 * @since 0.9.8
9
 */
10
11 1
Yii::import('zii.widgets.grid.CButtonColumn');
12
13
/**
14
 * Bootstrap button column widget.
15
 * Used to set buttons to use Glyphicons instead of the defaults images.
16
 */
17
class TbButtonColumn extends CButtonColumn
18
{
19
	/**
20
	 * @var string the view button icon (defaults to 'eye-open').
21
	 */
22
	public $viewButtonIcon = 'eye-open';
23
	/**
24
	 * @var string the update button icon (defaults to 'pencil').
25
	 */
26
	public $updateButtonIcon = 'pencil';
27
	/**
28
	 * @var string the delete button icon (defaults to 'trash').
29
	 */
30
	public $deleteButtonIcon = 'trash';
31
32
	/**
33
	 * Initializes the default buttons (view, update and delete).
34
	 */
35 1
	protected function initDefaultButtons()
36
	{
37 1
		parent::initDefaultButtons();
38
39 1 View Code Duplication
		if ($this->viewButtonIcon !== false && !isset($this->buttons['view']['icon']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40 1
			$this->buttons['view']['icon'] = $this->viewButtonIcon;
41 1 View Code Duplication
		if ($this->updateButtonIcon !== false && !isset($this->buttons['update']['icon']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42 1
			$this->buttons['update']['icon'] = $this->updateButtonIcon;
43 1 View Code Duplication
		if ($this->deleteButtonIcon !== false && !isset($this->buttons['delete']['icon']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44 1
			$this->buttons['delete']['icon'] = $this->deleteButtonIcon;
45 1
	}
46
47
	/**
48
	 * Renders a link button.
49
	 * @param string $id the ID of the button
50
	 * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
51
	 * @param integer $row the row number (zero-based)
52
	 * @param mixed $data the data object associated with the row
53
	 */
54
	protected function renderButton($id, $button, $row, $data)
55
	{
56
		if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row'=>$row, 'data'=>$data)))
57
			return;
58
59
		$label = isset($button['label']) ? $button['label'] : $id;
60
		$url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data'=>$data, 'row'=>$row)) : '#';
61
		$options = isset($button['options']) ? $button['options'] : array();
62
63
		if (!isset($options['title']))
64
			$options['title'] = $label;
65
66
		if (!isset($options['rel']))
67
			$options['rel'] = 'tooltip';
68
69
		if (isset($button['icon']))
70
		{
71
			if (strpos($button['icon'], 'icon') === false)
72
				$button['icon'] = 'icon-'.implode(' icon-', explode(' ', $button['icon']));
73
74
			echo CHtml::link('<i class="'.$button['icon'].'"></i>', $url, $options);
75
		}
76 View Code Duplication
		else if (isset($button['imageUrl']) && is_string($button['imageUrl']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
			echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
78
		else
79
			echo CHtml::link($label, $url, $options);
80
	}
81
}
82