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

Applications   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 270
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 23
lcom 4
cbo 4
dl 0
loc 270
ccs 0
cts 66
cp 0
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
B exchangeArray() 0 10 8
A getArrayCopy() 0 4 1
A setInputFilter() 0 4 1
B getInputFilter() 0 150 2
A getClient() 0 12 2
A getUserService() 0 7 2
A setUserService() 0 5 1
A getServiceManager() 0 7 2
A setServiceManager() 0 5 1
A setServiceLocator() 0 5 1
A getServiceLocator() 0 7 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
use Zend\ServiceManager\ServiceManager;
26
use Zend\Di\ServiceLocator;
27
28
class Applications implements InputFilterAwareInterface, ServiceLocatorAwareInterface
29
{
30
    public $application_id;
31
    public $name;
32
    public $shortname;
33
    public $path;
34
    public $url;
35
    public $email;
36
    public $client_id;
37
38
    protected $inputFilter;
39
    protected $userService;
40
    protected $serviceManager;
41
    protected $serviceLocator;
42
    
43
    public function exchangeArray($data)
44
    {
45
        $this->application_id    = (isset($data['application_id'])) ? $data['application_id'] : $this->application_id;
46
        $this->name                = (isset($data['name'])) ? $data['name'] : $this->name;
47
        $this->shortname        = (isset($data['shortname'])) ? $data['shortname'] : $this->shortname;
48
        $this->path                = (isset($data['path'])) ? $data['path'] : $this->path;
49
        $this->url                = (isset($data['url'])) ? $data['url'] : $this->url;
50
        $this->email            = (isset($data['email'])) ? $data['email'] : $this->email;
51
        $this->client_id        = (isset($data['client_id'])) ? $data['client_id'] : $this->client_id;
52
    }
53
54
    public function getArrayCopy()
55
    {
56
        return get_object_vars($this);
57
    }
58
    
59
    public function setInputFilter(InputFilterInterface $inputFilter)
60
    {
61
        throw new \Exception("Not used");
62
    }
63
64
    public function getInputFilter()
65
    {
66
        if (!$this->inputFilter) {
67
            $inputFilter = new InputFilter();
68
            $factory     = new InputFactory();
69
70
            $inputFilter->add(
71
                $factory->createInput(
72
                    array(
73
                    'name'     => 'application_id',
74
                    'required' => true,
75
                    'filters'  => array(
76
                    array('name' => 'Int'),
77
                    ),
78
                    )
79
                )
80
            );
81
82
            $inputFilter->add(
83
                $factory->createInput(
84
                    array(
85
                    'name'     => 'name',
86
                    'required' => true,
87
                    'filters'  => array(
88
                    array('name' => 'StripTags'),
89
                    array('name' => 'StringTrim'),
90
                    ),
91
                    'validators' => array(
92
                    array(
93
                    'name'    => 'StringLength',
94
                    'options' => array(
95
                            'encoding' => 'UTF-8',
96
                            'min'      => 1,
97
                            'max'      => 255,
98
                    ),
99
                    ),
100
                    ),
101
                    )
102
                )
103
            );
104
105
            $inputFilter->add(
106
                $factory->createInput(
107
                    array(
108
                    'name'     => 'shortname',
109
                    'required' => false,
110
                    'filters'  => array(
111
                    array('name' => 'StripTags'),
112
                    array('name' => 'StringTrim'),
113
                    ),
114
                    'validators' => array(
115
                    array(
116
                    'name'    => 'StringLength',
117
                    'options' => array(
118
                            'encoding' => 'UTF-8',
119
                            'min'      => 1,
120
                            'max'      => 255,
121
                    ),
122
                    ),
123
                    ),
124
                    )
125
                )
126
            );
127
128
            $inputFilter->add(
129
                $factory->createInput(
130
                    array(
131
                    'name'     => 'path',
132
                    'required' => false,
133
                    'filters'  => array(
134
                    array('name' => 'StripTags'),
135
                    array('name' => 'StringTrim'),
136
                    ),
137
                    'validators' => array(
138
                    array(
139
                    'name'    => 'StringLength',
140
                    'options' => array(
141
                            'encoding' => 'UTF-8',
142
                            'min'      => 1,
143
                            'max'      => 1024,
144
                    ),
145
                    ),
146
                    ),
147
                    )
148
                )
149
            );
150
151
            $inputFilter->add(
152
                $factory->createInput(
153
                    array(
154
                    'name'     => 'url',
155
                    'required' => false,
156
                    'filters'  => array(
157
                    array('name' => 'StripTags'),
158
                    array('name' => 'StringTrim'),
159
                    ),
160
                    'validators' => array(
161
                    array(
162
                    'name'    => 'StringLength',
163
                    'options' => array(
164
                            'encoding' => 'UTF-8',
165
                            'min'      => 1,
166
                            'max'      => 1024,
167
                    ),
168
                    ),
169
                    ),
170
                    )
171
                )
172
            );
173
174
            $inputFilter->add(
175
                $factory->createInput(
176
                    array(
177
                    'name'     => 'email',
178
                    'required' => false,
179
                    'filters'  => array(
180
                    array('name' => 'StripTags'),
181
                    array('name' => 'StringTrim'),
182
                    ),
183
                    'validators' => array(
184
                    array(
185
                    'name'    => 'StringLength',
186
                    'options' => array(
187
                            'encoding' => 'UTF-8',
188
                            'min'      => 1,
189
                            'max'      => 255,
190
                    ),
191
                    ),
192
                    ),
193
                    )
194
                )
195
            );
196
197
            $inputFilter->add(
198
                $factory->createInput(
199
                    array(
200
                    'name'     => 'client_id',
201
                    'required' => true,
202
                    'filters'  => array(
203
                    array('name' => 'Int'),
204
                    ),
205
                    )
206
                )
207
            );
208
            
209
            $this->inputFilter = $inputFilter;
210
        }
211
212
        return $this->inputFilter;
213
    }
214
    
215
    public function getClient() 
216
    {
217
        /**
218
 * @var \Admin\Model\ClientsTable $clients 
219
*/
220
        if ($this->client_id) {
221
            $clients = \Application\Module::getService('AdminClientsTable');
222
            return $clients->getClients($this->client_id);
223
        } else {
224
            return null;
225
        }
226
    }
227
    
228
    
229
    /**
230
     * Getters/setters for DI stuff
231
     */
232
233
    public function getUserService()
234
    {
235
        if (!$this->userService) {
236
            $this->userService = $this->getServiceManager()->get('zfcuser_user_service');
237
        }
238
        return $this->userService;
239
    }
240
241
    public function setUserService(UserService $userService)
242
    {
243
        $this->userService = $userService;
244
        return $this;
245
    }
246
247
    /**
248
     * Retrieve service manager instance
249
     *
250
     * @return ServiceManager 
251
     */
252
    public function getServiceManager()
253
    {
254
        if (null === $this->serviceManager) {
255
            $this->serviceManager = new ServiceManager();
256
        }
257
        return $this->serviceManager;
258
    }
259
260
    /**
261
     * Set service manager instance
262
     *
263
     * @param  ServiceManager $serviceManager
264
     * @return void
265
     */
266
    public function setServiceManager(ServiceManager $serviceManager)
267
    {
268
        $this->serviceManager = $serviceManager;
269
        return $this;
270
    }
271
272
    /**
273
     * Set serviceLocator instance
274
     *
275
     * @param  ServiceLocatorInterface $serviceLocator
276
     * @return void
277
     */
278
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
279
    {
280
        $this->serviceLocator = $serviceLocator;
281
        return $this;
282
    }
283
284
    /**
285
     * Retrieve serviceManager instance
286
     *
287
     * @return ServiceLocatorInterface
288
     */
289
    public function getServiceLocator()
290
    {
291
        if (null === $this->serviceLocator) {
292
            $this->serviceLocator = new ServiceLocator();
293
        }
294
        return $this->serviceLocator;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->serviceLocator; of type Zend\Di\ServiceLocator|Z...ServiceLocatorInterface adds the type Zend\Di\ServiceLocator to the return on line 294 which is incompatible with the return type declared by the interface Zend\ServiceManager\Serv...face::getServiceLocator of type Zend\ServiceManager\ServiceLocatorInterface.
Loading history...
295
    }
296
297
}