Text   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTruncate() 0 8 1
A formatValue() 0 11 2
1
<?php
2
3
/**
4
 * This file is part of the Grido (https://github.com/o5/grido)
5
 *
6
 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE.md that was distributed with this source code.
10
 */
11
12
namespace Grido\Components\Columns;
13
14
/**
15
 * Text column.
16
 *
17
 * @package     Grido
18
 * @subpackage  Components\Columns
19
 * @author      Petr Bugyík
20
 */
21
class Text extends Editable
22 1
{
23
    /** @var \Closure */
24
    protected $truncate;
25
26
    /**
27
     * @param string $maxLen UTF-8 encoding
28
     * @param string $append UTF-8 encoding
29
     * @return Column
30
     */
31
    public function setTruncate($maxLen, $append = "\xE2\x80\xA6")
32
    {
33 1
        $this->truncate = function($string) use ($maxLen, $append) {
34 1
            return \Nette\Utils\Strings::truncate($string, $maxLen, $append);
35
        };
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * @param mixed $value
42
     * @return mixed
43
     */
44
    protected function formatValue($value)
45
    {
46 1
        $value = parent::formatValue($value);
47
48 1
        if ($this->truncate) {
49 1
            $truncate = $this->truncate;
50 1
            $value = $truncate($value);
51 1
        }
52
53 1
        return $value;
54
    }
55
}
56