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.
Completed
Push — develop ( ee1b66...d8c12e )
by Borut
02:48
created

AbstractMeta::setKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Application\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * Abstract Meta
9
 *
10
 * Some default methods for a meta entity (id, key and value)
11
 *
12
 * @author Borut Balažek <[email protected]>
13
 */
14
class AbstractMeta
15
{
16
    /*** Id ***/
17
    /**
18
     * @return integer
19
     */
20
    public function getId()
21
    {
22
        return $this->id;
0 ignored issues
show
Bug introduced by
The property id 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...
23
    }
24
25
    /**
26
     * @param $id
27
     *
28
     * @return AbstractMeta
29
     */
30
    public function setId($id)
31
    {
32
        $this->id = $id;
33
34
        return $this;
35
    }
36
37
    /*** Key ***/
38
    /**
39
     * @return string
40
     */
41
    public function getKey()
42
    {
43
        return $this->key;
0 ignored issues
show
Bug introduced by
The property key 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
     * @param $key
48
     *
49
     * @return AbstractMeta
50
     */
51
    public function setKey($key)
52
    {
53
        $this->key = $key;
54
55
        return $this;
56
    }
57
58
    /*** Value ***/
59
    /**
60
     * @return string
61
     */
62
    public function getValue()
63
    {
64
        return $this->value;
0 ignored issues
show
Bug introduced by
The property value 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...
65
    }
66
67
    /**
68
     * @param $value
69
     *
70
     * @return AbstractMeta
71
     */
72
    public function setValue($value)
73
    {
74
        $this->value = $value;
75
76
        return $this;
77
    }
78
    
79
    /*** Time created ***/
80
    /**
81
     * @return \DateTime
82
     */
83
    public function getTimeCreated()
84
    {
85
        return $this->timeCreated;
0 ignored issues
show
Bug introduced by
The property timeCreated 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...
86
    }
87
88
    /**
89
     * @param \DateTime $timeCreated
90
     *
91
     * @return AbstractMeta
92
     */
93
    public function setTimeCreated(\DateTime $timeCreated)
94
    {
95
        $this->timeCreated = $timeCreated;
96
97
        return $this;
98
    }
99
100
    /*** Time updated ***/
101
    /**
102
     * @return \DateTime
103
     */
104
    public function getTimeUpdated()
105
    {
106
        return $this->timeUpdated;
0 ignored issues
show
Bug introduced by
The property timeUpdated 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...
107
    }
108
109
    /**
110
     * @param \DateTime $timeUpdated
111
     *
112
     * @return AbstractMeta
113
     */
114
    public function setTimeUpdated(\DateTime $timeUpdated)
115
    {
116
        $this->timeUpdated = $timeUpdated;
117
118
        return $this;
119
    }
120
121
    /**
122
     * Returns data in array
123
     *
124
     * @return array
125
     */
126
    public function toArray()
127
    {
128
        return array(
129
            'id' => $this->getId(),
130
            'key' => $this->getKey(),
131
            'value' => $this->getValue(),
132
            'time_created' => $this->getTimeCreated()->format(DATE_ATOM),
133
        );
134
    }
135
    
136
    /**
137
     * Converts the key and value to string
138
     *
139
     * @return string
140
     */
141
    public function __toString()
142
    {
143
        $key = $this->getKey();
144
        $value = $this->getValue();
145
146
        // Prevent double encoding
147
        if ($value[0] == '{' || $value[0] == '[') {
148
            $value = json_decode($value);
149
        }
150
151
        $data[$key] = $value;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
152
153
        return json_encode($data);
154
    }
155
}
156