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.

Template::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 4
nc 5
nop 1
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
10
namespace ZfTable\Decorator\Cell;
11
12
use ZfTable\Decorator\Exception;
13
14
class Template extends AbstractCellDecorator
15
{
16
17
    /**
18
     * Template
19
     * @var string
20
     */
21
    protected $template;
22
23
    /**
24
     * Array of variables
25
     * @var null | array
26
     */
27
    protected $vars;
28
29
    /**
30
     * Constructor
31
     *
32
     * @param array $options
33
     * @throws Exception\InvalidArgumentException
34
     */
35
    public function __construct(array $options = array())
36
    {
37
        if (!isset($options['template'])) {
38
            throw new Exception\InvalidArgumentException('path key in options argument requred');
39
        }
40
41
        $this->template = $options['template'];
42
        $this->vars = is_array($options['vars']) ? $options['vars'] : array($options['vars']);
0 ignored issues
show
Documentation Bug introduced by
It seems like is_array($options['vars'...array($options['vars']) of type array is incompatible with the declared type null of property $vars.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->place = (isset($options['place'])) ? $options['place'] : self::RESET_CONTEXT;
0 ignored issues
show
Bug introduced by
The property place does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
    }
45
46
    /**
47
     * Rendering decorator
48
     *
49
     * @param string $context
50
     * @return string
51
     */
52
    public function render($context)
53
    {
54
        $values = array();
55
56
        foreach ($this->vars as $var) {
0 ignored issues
show
Bug introduced by
The expression $this->vars of type null is not traversable.
Loading history...
57
            $actualRow = $this->getCell()->getActualRow();
58
            if (is_object($actualRow)) {
59
                $actualRow = $actualRow->getArrayCopy();
60
            }
61
            $values[] = $actualRow[$var];
62
        }
63
64
        $value = vsprintf($this->template, $values);
65
66
        if ($this->place == self::RESET_CONTEXT) {
67
            return $value;
68
        } else {
69
            return ($this->place == self::PRE_CONTEXT) ? $value . $context :  $context . $value;
70
        }
71
    }
72
}
73