GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Cell::render()   B
last analyzed

Complexity

Conditions 10
Paths 30

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 7.6666
c 0
b 0
f 0
cc 10
nc 30
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * ZfTable ( Module for Zend Framework 2)
4
 *
5
 * @copyright Copyright (c) 2013 Piotr Duda [email protected]
6
 * @license   MIT License
7
 */
8
9
namespace ZfTable;
10
11
use ZfTable\AbstractElement;
12
use ZfTable\Decorator\DecoratorFactory;
13
14
class Cell extends AbstractElement
15
{
16
17
    /**
18
     * Header object
19
     * @var Header
20
     */
21
    protected $header;
22
23
    /**
24
     *
25
     * @param Header $header
26
     */
27
    public function __construct($header)
28
    {
29
        $this->header = $header;
30
    }
31
32
    /**
33
     *
34
     * @param string $name type
35
     * @param array  $options type
36
     * @return Decorator\AbstractDecorator
37
     */
38
    public function addDecorator($name, $options = array())
39
    {
40
        $decorator = DecoratorFactory::factoryCell($name, $options);
41
        $decorator->setCell($this);
42
        $this->attachDecorator($decorator);
43
        return $decorator;
44
    }
45
46
    /**
47
     * Get header object
48
     * @return Header
49
     */
50
    public function getHeader()
51
    {
52
        return $this->header;
53
    }
54
55
    /**
56
     * Set header object
57
     *
58
     * @param Header $header
59
     * @return $this
60
     */
61
    public function setHeader($header)
62
    {
63
        $this->header = $header;
64
        return $this;
65
    }
66
67
    /**
68
     * Get actual row
69
     *
70
     * @return array
71
     */
72
    public function getActualRow()
73
    {
74
        return $this->getTable()->getRow()->getActualRow();
75
    }
76
77
    /**
78
     * Rendering single cell
79
     *
80
     * @return string
81
     */
82
    public function render($type = 'html')
83
    {
84
        $row = $this->getTable()->getRow()->getActualRow();
85
86
        $value = '';
87
88
        if (is_array($row) || $row instanceof \ArrayAccess) {
89
            $value = (isset($row[$this->getHeader()->getName()])) ? $row[$this->getHeader()->getName()] : '';
90
        } elseif (is_object($row)) {
91
            $headerName = $this->getHeader()->getName();
92
            $methodName = 'get' . ucfirst($headerName);
93
            if (method_exists($row, $methodName)) {
94
                $value = $row->$methodName();
95
            } else {
96
                $value = (property_exists($row, $headerName)) ? $row->$headerName : '';
97
            }
98
        }
99
100
        foreach ($this->decorators as $decorator) {
101
            if ($decorator->validConditions()) {
102
                $value = $decorator->render($value);
103
            }
104
        }
105
106
        if ($type == 'html') {
107
            $ret = sprintf("<td %s>%s</td>", $this->getAttributes(), $value);
108
            $this->clearVar();
109
            return $ret;
110
111
        } else {
112
            return $value;
113
        }
114
    }
115
}
116