Passed
Push — master ( 700b0f...aafb0a )
by Björn
18:25 queued 10s
created

Clients::setInputFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * BB's Zend Framework 2 Components
4
 * 
5
 * AdminModule
6
 *
7
 * @package   [MyApplication]
8
 * @package   BB's Zend Framework 2 Components
9
 * @package   AdminModule
10
 * @author    Björn Bartels <[email protected]>
11
 * @link      https://gitlab.bjoernbartels.earth/groups/zf2
12
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
13
 * @copyright copyright (c) 2016 Björn Bartels <[email protected]>
14
 */
15
16
namespace Admin\Model;
17
18
use Zend\Crypt\Password\Bcrypt;
19
use Zend\InputFilter\InputFilter;
20
use Zend\InputFilter\Factory as InputFactory;
21
use Zend\InputFilter\InputFilterAwareInterface;
22
use Zend\InputFilter\InputFilterInterface;
23
use Zend\ServiceManager\ServiceLocatorInterface;
24
use Zend\ServiceManager\ServiceLocatorAwareInterface;
25
26
class Clients implements InputFilterAwareInterface, ServiceLocatorAwareInterface
27
{
28
    public $clients_id;
29
    public $scope;
30
    public $ref_id;
31
    public $type;
32
    public $name;
33
    public $value;
34
35
    protected $inputFilter;
36
    protected $userService;
37
    protected $serviceManager;
38
    protected $serviceLocator;
39
    
40
    public function exchangeArray($data)
41
    {
42
        $this->clients_id    = (isset($data['clients_id'])) ? $data['clients_id'] : null;
43
        $this->name            = (isset($data['name'])) ? $data['name'] : null;
44
        $this->extraname    = (isset($data['extraname'])) ? $data['extraname'] : null;
0 ignored issues
show
Bug introduced by
The property extraname 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...
45
        $this->homepage        = (isset($data['homepage'])) ? $data['homepage'] : null;
0 ignored issues
show
Bug introduced by
The property homepage 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...
46
        $this->email        = (isset($data['email'])) ? $data['email'] : null;
0 ignored issues
show
Bug introduced by
The property email 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...
47
        $this->contact        = (isset($data['contact'])) ? $data['contact'] : null;
0 ignored issues
show
Bug introduced by
The property contact 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...
48
        $this->phone        = (isset($data['phone'])) ? $data['phone'] : null;
0 ignored issues
show
Bug introduced by
The property phone 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...
49
        $this->statistics    = (isset($data['statistics'])) ? $data['statistics'] : null;
0 ignored issues
show
Bug introduced by
The property statistics 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...
50
    }
51
52
    public function getArrayCopy()
53
    {
54
        return get_object_vars($this);
55
    }
56
    
57
    public function setInputFilter(InputFilterInterface $inputFilter)
58
    {
59
        throw new \Exception("Not used");
60
    }
61
62
    public function getInputFilter()
63
    {
64
        if (!$this->inputFilter) {
65
            $inputFilter = new InputFilter();
66
            $factory     = new InputFactory();
67
68
            $inputFilter->add(
69
                $factory->createInput(
70
                    array(
71
                    'name'     => 'clients_id',
72
                    'required' => true,
73
                    'filters'  => array(
74
                    array('name' => 'Int'),
75
                    ),
76
                    )
77
                )
78
            );
79
80
            $inputFilter->add(
81
                $factory->createInput(
82
                    array(
83
                    'name'     => 'name',
84
                    'required' => true,
85
                    'filters'  => array(
86
                    array('name' => 'StripTags'),
87
                    array('name' => 'StringTrim'),
88
                    ),
89
                    'validators' => array(
90
                    array(
91
                    'name'    => 'StringLength',
92
                    'options' => array(
93
                            'encoding' => 'UTF-8',
94
                            'min'      => 1,
95
                            'max'      => 255,
96
                    ),
97
                    ),
98
                    ),
99
                    )
100
                )
101
            );
102
103
            $inputFilter->add(
104
                $factory->createInput(
105
                    array(
106
                    'name'     => 'extraname',
107
                    'required' => false,
108
                    'filters'  => array(
109
                    array('name' => 'StripTags'),
110
                    array('name' => 'StringTrim'),
111
                    ),
112
                    'validators' => array(
113
                    array(
114
                    'name'    => 'StringLength',
115
                    'options' => array(
116
                            'encoding' => 'UTF-8',
117
                            'min'      => 1,
118
                            'max'      => 255,
119
                    ),
120
                    ),
121
                    ),
122
                    )
123
                )
124
            );
125
126
            $inputFilter->add(
127
                $factory->createInput(
128
                    array(
129
                    'name'     => 'homepage',
130
                    'required' => false,
131
                    'filters'  => array(
132
                    array('name' => 'StripTags'),
133
                    array('name' => 'StringTrim'),
134
                    ),
135
                    'validators' => array(
136
                    array(
137
                    'name'    => 'StringLength',
138
                    'options' => array(
139
                            'encoding' => 'UTF-8',
140
                            'min'      => 1,
141
                            'max'      => 255,
142
                    ),
143
                    ),
144
                    ),
145
                    )
146
                )
147
            );
148
149
            $inputFilter->add(
150
                $factory->createInput(
151
                    array(
152
                    'name'     => 'email',
153
                    'required' => false,
154
                    'filters'  => array(
155
                    array('name' => 'StripTags'),
156
                    array('name' => 'StringTrim'),
157
                    ),
158
                    'validators' => array(
159
                    array(
160
                    'name'    => 'StringLength',
161
                    'options' => array(
162
                            'encoding' => 'UTF-8',
163
                            'min'      => 1,
164
                            'max'      => 255,
165
                    ),
166
                    ),
167
                    ),
168
                    )
169
                )
170
            );
171
172
            $inputFilter->add(
173
                $factory->createInput(
174
                    array(
175
                    'name'     => 'contact',
176
                    'required' => false,
177
                    'filters'  => array(
178
                    array('name' => 'StripTags'),
179
                    array('name' => 'StringTrim'),
180
                    ),
181
                    'validators' => array(
182
                    array(
183
                    'name'    => 'StringLength',
184
                    'options' => array(
185
                            'encoding' => 'UTF-8',
186
                            'min'      => 1,
187
                            'max'      => 255,
188
                    ),
189
                    ),
190
                    ),
191
                    )
192
                )
193
            );
194
195
            $inputFilter->add(
196
                $factory->createInput(
197
                    array(
198
                    'name'     => 'phone',
199
                    'required' => false,
200
                    'filters'  => array(
201
                    array('name' => 'StripTags'),
202
                    array('name' => 'StringTrim'),
203
                    ),
204
                    'validators' => array(
205
                    array(
206
                    'name'    => 'StringLength',
207
                    'options' => array(
208
                            'encoding' => 'UTF-8',
209
                            'min'      => 1,
210
                            'max'      => 255,
211
                    ),
212
                    ),
213
                    ),
214
                    )
215
                )
216
            );
217
218
            $inputFilter->add(
219
                $factory->createInput(
220
                    array(
221
                    'name'     => 'statistics',
222
                    'required' => false,
223
                    'filters'  => array(
224
                    array('name' => 'StripTags'),
225
                    array('name' => 'StringTrim'),
226
                    ),
227
                    'validators' => array(
228
                    array(
229
                    'name'    => 'StringLength',
230
                    'options' => array(
231
                            'encoding' => 'UTF-8',
232
                            'min'      => 1,
233
                            'max'      => 255,
234
                    ),
235
                    ),
236
                    ),
237
                    )
238
                )
239
            );
240
241
            $inputFilter->add(
242
                $factory->createInput(
243
                    array(
244
                    'name'     => 'value',
245
                    'required' => false,
246
                    'filters'  => array(
247
                    array('name' => 'StripTags'),
248
                    array('name' => 'StringTrim'),
249
                    ),
250
                    'validators' => array(
251
                    ),
252
                    )
253
                )
254
            );
255
256
            $this->inputFilter = $inputFilter;
257
        }
258
259
        return $this->inputFilter;
260
    }
261
    /**
262
     * Getters/setters for DI stuff
263
     */
264
265
    public function getUserService()
266
    {
267
        if (!$this->userService) {
268
            $this->userService = $this->getServiceManager()->get('zfcuser_user_service');
269
        }
270
        return $this->userService;
271
    }
272
273
    public function setUserService(UserService $userService)
274
    {
275
        $this->userService = $userService;
276
        return $this;
277
    }
278
279
    /**
280
     * Retrieve service manager instance
281
     *
282
     * @return ServiceManager 
283
     */
284
    public function getServiceManager()
285
    {
286
        return $this->serviceManager;
287
    }
288
289
    /**
290
     * Set service manager instance
291
     *
292
     * @param  ServiceManager $serviceManager
293
     * @return User
294
     */
295
    public function setServiceManager(ServiceManager $serviceManager)
296
    {
297
        $this->serviceManager = $serviceManager;
298
        return $this;
299
    }
300
301
    /**
302
     * Set serviceManager instance
303
     *
304
     * @param  ServiceLocatorInterface $serviceLocator
305
     * @return void
306
     */
307
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
308
    {
309
        $this->serviceLocator = $serviceLocator;
310
    }
311
312
    /**
313
     * Retrieve serviceManager instance
314
     *
315
     * @return ServiceLocatorInterface
316
     */
317
    public function getServiceLocator()
318
    {
319
        return $this->serviceLocator;
320
    }
321
322
}