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.

Comment::exchangeArray()   C
last analyzed

Complexity

Conditions 10
Paths 512

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 5.7204
c 0
b 0
f 0
cc 10
eloc 12
nc 512
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
namespace RbComment\Model;
3
4
use Zend\InputFilter\Factory as InputFactory;
5
use Zend\InputFilter\InputFilter;
6
use Zend\InputFilter\InputFilterAwareInterface;
7
use Zend\InputFilter\InputFilterInterface;
8
9
class Comment implements InputFilterAwareInterface
10
{
11
    /**
12
     * @var int
13
     */
14
    public $id;
15
16
    /**
17
     * @var string
18
     */
19
    public $thread;
20
21
    /**
22
     * @var string
23
     */
24
    public $uri;
25
26
    /**
27
     * @var string
28
     */
29
    public $author;
30
31
    /**
32
     * @var string
33
     */
34
    public $contact;
35
36
    /**
37
     *
38
     * @var string
39
     */
40
    public $content;
41
42
    /**
43
     * @var boolean
44
     */
45
    public $visible;
46
47
    /**
48
     * @var boolean
49
     */
50
    public $spam;
51
52
    /**
53
     * @var timestamp
54
     */
55
    public $published_on;
56
57
    /**
58
     * @var InputFilter
59
     */
60
    protected $inputFilter;
61
62
    public function exchangeArray($data)
63
    {
64
        $this->id       = (isset($data['id'])) ? $data['id'] : null;
65
        $this->thread   = (isset($data['thread'])) ? $data['thread'] : null;
66
        $this->uri      = (isset($data['uri'])) ? $data['uri'] : null;
67
        $this->author   = (isset($data['author'])) ? $data['author'] : null;
68
        $this->contact  = (isset($data['contact'])) ? $data['contact'] : null;
69
        $this->content  = (isset($data['content'])) ? $data['content'] : null;
70
        $this->visible  = (isset($data['visible'])) ? $data['visible'] : 0;
71
        $this->spam     = (isset($data['spam'])) ? $data['spam'] : 0;
72
        $this->published_on  = (isset($data['published_on']))
73
            ? $data['published_on']
74
            : null;
75
    }
76
77
    public function toArray()
78
    {
79
        return get_object_vars($this);
80
    }
81
82
    public function setInputFilter(InputFilterInterface $inputFilter)
83
    {
84
        throw new \Exception("Not used");
85
    }
86
87
    public function getInputFilter()
88
    {
89
        if (!$this->inputFilter) {
90
            $inputFilter = new InputFilter();
91
            $factory     = new InputFactory();
92
93
            $inputFilter->add($factory->createInput([
94
                'name'     => 'id',
95
                'required' => true,
96
                'filters'  => [
97
                    ['name' => 'Int'],
98
                ],
99
            ]));
100
101
            $inputFilter->add($factory->createInput([
102
                'name'     => 'thread',
103
                'required' => true,
104
                'filters'  => [
105
                    ['name' => 'Alnum'],
106
                ],
107
            ]));
108
109
            $inputFilter->add($factory->createInput([
110
                'name'     => 'author',
111
                'required' => true,
112
                'filters'  => [
113
                    ['name' => 'StripTags'],
114
                    ['name' => 'StringTrim'],
115
                ],
116
                'validators' => [
117
                    [
118
                        'name'    => 'StringLength',
119
                        'options' => [
120
                            'encoding' => 'UTF-8',
121
                            'min'      => 1,
122
                            'max'      => 150,
123
                        ],
124
                    ],
125
                ],
126
            ]));
127
128
            $inputFilter->add($factory->createInput([
129
                'name'     => 'contact',
130
                'required' => true,
131
                'filters'  => [
132
                    ['name' => 'StripTags'],
133
                    ['name' => 'StringTrim'],
134
                ],
135
                'validators' => [
136
                    [
137
                        'name' => 'EmailAddress',
138
                    ],
139
                    [
140
                        'name'    => 'StringLength',
141
                        'options' => [
142
                            'encoding' => 'UTF-8',
143
                            'min'      => 1,
144
                            'max'      => 200,
145
                        ],
146
                    ],
147
                ],
148
            ]));
149
150
            $inputFilter->add($factory->createInput([
151
                'name'     => 'content',
152
                'required' => true,
153
                'filters'  => [
154
                    ['name' => 'StripTags'],
155
                    ['name' => 'StringTrim'],
156
                ],
157
            ]));
158
159
            $this->inputFilter = $inputFilter;
160
        }
161
162
        return $this->inputFilter;
163
    }
164
}
165