Text::getColumnConfig()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
/**
3
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid\View\Helper\JqGrid\Column;
8
9
use Zend\View\Helper\AbstractHelper;
10
use Nnx\DataGrid\Column\ColumnInterface;
11
use Zend\View\Renderer\PhpRenderer;
12
13
/**
14
 * Class Column
15
 * @package Nnx\DataGrid\View\Helper
16
 */
17
class Text extends AbstractHelper
18
{
19
    /**
20
     * @param ColumnInterface $column
21
     * @return string
22
     */
23
    public function __invoke(ColumnInterface $column)
24
    {
25
        $config = $this->getColumnConfig($column);
26
        $config = array_merge($config, $column->getAttributes());
27
        return (object)$config;
28
    }
29
30
    /**
31
     * Возвращает конфигурацию колонки
32
     * @param ColumnInterface $column
33
     * @return array
34
     */
35
    protected function getColumnConfig(ColumnInterface $column)
36
    {
37
        /** @var PhpRenderer $view */
38
        $view = $this->getView();
39
        /** @var \Zend\View\Helper\EscapeHtml $escape */
40
        $escape = $view->plugin('escapeHtml');
41
        $name = $escape($column->getName());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
        $header = $column->getHeader();
43
        $config = [
44
            'label' => $header ? $escape($header->getTitle()) : null,
45
            'index' => strtolower($name),
46
            'name' => strtolower($name),
47
        ];
48
        return $config;
49
    }
50
51
    protected function getAttrValue($key, $attributes, $default = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
52
    {
53
        return array_key_exists($key, $attributes) ? $attributes[$key] : $default;
54
    }
55
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
56