Completed
Push — master ( 392d04...e48b3d )
by Pavel
02:16
created

TButtonTryAddIcon   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A tryAddIcon() 0 10 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 Nette\Utils\Html;
13
use Ublaboo\DataGrid\Row;
14
15
trait TButtonTryAddIcon
16
{
17
18
	/**
19
	 * Should the element has an icon?
20
	 * @param  Html            $el
21
	 * @param  string|null     $icon
22
	 * @param  string          $name
23
	 * @return void
24
	 */
25
	public function tryAddIcon(Html $el, $icon, $name)
26
	{
27
		if ($icon) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $icon of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
28
			$el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix.$icon));
29
30
			if (strlen($name)) {
31
				$el->addHtml('&nbsp;');
32
			}
33
		}
34
	}
35
36
}
37