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

TButtonTryAddIcon::tryAddIcon()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 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