Placeholder::decorate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Boduch\Grid\Decorators;
4
5
use Boduch\Grid\Cell;
6
7
class Placeholder extends Decorator
8
{
9
    /**
10
     * @var string|\Closure
11
     */
12
    protected $placeholder;
13
14
    /**
15
     * @param string|\Closure $placeholder
16
     */
17
    public function __construct($placeholder)
18
    {
19
        $this->placeholder = $placeholder;
20
    }
21
22
    /**
23
     * @param Cell $cell
24
     * @return bool
25
     */
26
    public function decorate(Cell $cell)
27
    {
28
        if (empty($cell->getUnescapedValue())) {
29
            if ($this->placeholder instanceof \Closure) {
30
                $cell->setValue($this->placeholder->call($cell->getColumn()->getGrid(), $cell->getData()));
31
            } else {
32
                $cell->setValue($this->placeholder);
33
            }
34
35
            return false;
36
        }
37
38
        return true;
39
    }
40
}
41