Completed
Push — develop ( d809fa...f2a1ed )
by
unknown
08:20
created

OrganizationReference::getImages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Organizations\Entity;
12
13
use Auth\Entity\UserInterface;
14
use Core\Entity\EntityInterface;
15
use Core\Entity\PermissionsInterface;
16
use Doctrine\Common\Collections\Collection;
17
use Organizations\Repository\Organization as OrganizationRepository;
18
use Zend\Hydrator\HydratorInterface;
19
20
21
/**
22
 * Manages reference to an organization.
23
 *
24
 * As OrganizationInterface is also implemented (and all methods are proxied to the "real" organization
25
 * object), this class can be used as an organization.
26
 *
27
 * @author Mathias Gelhausen <[email protected]>
28
 * @todo update test
29
 */
30
class OrganizationReference implements
0 ignored issues
show
Coding Style introduced by
The property $_userId is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $_repository is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $_organization is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $_type is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
31
    OrganizationInterface,
32
    OrganizationReferenceInterface
33
{
34
    /*
35
     * Note: We start property names with an underscore to prevent
36
     * name collisions with the OrganizationInterface.
37
     */
38
39
    /**
40
     * The user id of the parent document.
41
     *
42
     * @var string
43
     */
44
    protected $_userId;
0 ignored issues
show
Coding Style introduced by
$_userId does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
45
46
    /**
47
     * The organization repository.
48
     *
49
     * @var \Organizations\Repository\Organization
50
     */
51
    protected $_repository;
0 ignored issues
show
Coding Style introduced by
$_repository does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
52
53
    /**
54
     * The organization
55
     *
56
     * @var Organization
57
     */
58
    protected $_organization;
0 ignored issues
show
Coding Style introduced by
$_organization does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
59
60
    /**
61
     * Reference type.
62
     *
63
     * @internal
64
     *      Initial value is null, so we can determine in {@link load()} if it has already run once.
65
     *
66
     * @var string
67
     */
68
    protected $_type;
0 ignored issues
show
Coding Style introduced by
$_type does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
69
70
    /**
71
     * Creates an instance.
72
     *
73
     * @param string                 $userId
74
     * @param OrganizationRepository $repository
75
     */
76
    public function __construct($userId, OrganizationRepository $repository)
77
    {
78
        $this->_userId = $userId;
79
        $this->_repository = $repository;
80
    }
81
82
    public function isOwner()
83
    {
84
        $this->load();
85
86
        return self::TYPE_OWNER == $this->_type;
87
    }
88
89
    public function isEmployee()
90
    {
91
        $this->load();
92
93
        return self::TYPE_EMPLOYEE == $this->_type;
94
    }
95
96
    public function hasAssociation()
97
    {
98
        $this->load();
99
100
        return self::TYPE_NONE != $this->_type;
101
    }
102
103
    public function getOrganization()
104
    {
105
        $this->load();
106
107
        return $this->_organization;
108
    }
109
110
    /**
111
     * Loads the organization from the database and sets the reference type.
112
     */
113
    protected function load()
114
    {
115
        if (null !== $this->_type) {
116
            return;
117
        }
118
119
        // Is the user the owner of the referenced organization?
120
        $org = $this->_repository->findByUser($this->_userId);
121
122
        if ($org) {
123
            $this->_type = self::TYPE_OWNER;
124
            $this->_organization = $org;
0 ignored issues
show
Documentation Bug introduced by
It seems like $org can also be of type array. However, the property $_organization is declared as type object<Organizations\Entity\Organization>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
125
126
            return;
127
        }
128
129
        // Is the user employed by the referenced organization?
130
        $org = $this->_repository->findByEmployee($this->_userId);
131
132
        if ($org) {
133
            $this->_type = self::TYPE_EMPLOYEE;
134
            $this->_organization = $org;
135
136
            return;
137
        }
138
139
        // It seems the user is not associated with an organization.
140
        $this->_type = self::TYPE_NONE;
141
    }
142
143
144
    /**
145
     * Executes a proxy call to the associated organization entity.
146
     *
147
     * Does nothing, if no organization is available.
148
     *
149
     * Call it like:
150
     * <pre>
151
     *   $this->proxy($method[, $arg1[, $arg2[, ...]]]);
152
     * </pre>
153
     *
154
     * @param $method
155
     *
156
     * @return self|mixed
157
     */
158
    protected function proxy($method)
159
    {
160
        if (!$this->hasAssociation()) {
161
            return $this;
162
        }
163
164
        $args = array_slice(func_get_args(), 1);
165
166
        $return = call_user_func_array(array($this->_organization, $method), $args);
167
168
        return ($return === $this->_organization) ? $this : $return;
169
    }
170
171
    /*
172
     * We need to implement each method of OrganizationInterface because we want to proxy
173
     * to a concrete instance of Organization and therefor cannot simply extend.
174
     */
175
176
    /**#@+
177
     * Proxies to the concrete Organization instance.
178
     *
179
     * {@inheritDoc}
180
     */
181
182
183
    public function __get($property)
184
    {
185
        return $this->proxy('__get', $property);
186
    }
187
188
    public function __set($property, $value)
189
    {
190
        return $this->proxy('__set', $property, $value);
191
    }
192
193
    public function __isset($property)
194
    {
195
        return $this->proxy('__isset', $property);
196
    }
197
198
    public function notEmpty($property, array $args=[])
199
    {
200
        return $this->proxy('notEmpty', $args);
201
    }
202
203
    public function hasProperty($property, $mode = self::PROPERTY_STRICT)
204
    {
205
        return $this->proxy('hasProperty', $mode);
206
    }
207
208
    public function setHydrator(HydratorInterface $hydrator)
209
    {
210
        return $this->proxy('setHydrator', $hydrator);
211
    }
212
213
    public function getHydrator()
214
    {
215
        return $this->proxy('getHydrator');
216
    }
217
218
    public function setId($id)
219
    {
220
        return $this->proxy('setId', $id);
221
    }
222
223
    public function getId()
224
    {
225
        return $this->proxy('getId');
226
    }
227
228
    public function setDateCreated($date)
229
    {
230
        return $this->proxy('setDateCreated', $date);
231
    }
232
233
    public function getDateCreated()
234
    {
235
        return $this->proxy('getDateCreated');
236
    }
237
238
    public function setDateModified($date)
239
    {
240
        return $this->proxy('setDateModified', $date);
241
    }
242
243
    public function getDateModified()
244
    {
245
        return $this->proxy('getDateModified');
246
    }
247
248
    public function setParent(OrganizationInterface $parent)
249
    {
250
        return $this->proxy('setParent', $parent);
251
    }
252
253
    public function getParent($returnSelf = false)
254
    {
255
        return $this->proxy('getParent', $returnSelf);
256
    }
257
258
    public function setContact(EntityInterface $contact = null)
259
    {
260
        return $this->proxy('setContact', $contact);
261
    }
262
263
    public function getContact()
264
    {
265
        return $this->proxy('getContact');
266
    }
267
268
    public function isHiringOrganization()
269
    {
270
        return $this->proxy('isHiringOrganization');
271
    }
272
273
    public function getHiringOrganizations()
274
    {
275
        return $this->proxy('getHiringOrganizations');
276
    }
277
278
    public function setImage(OrganizationImage $image)
279
    {
280
        return $this->proxy('setImage', $image);
281
    }
282
283
    public function getImage()
284
    {
285
        return $this->proxy('getImage');
286
    }
287
288
    public function getImages()
289
    {
290
        return $this->proxy('getImages');
291
    }
292
293
    public function setImages(\Core\Entity\ImageSet $images)
294
    {
295
        return $this->proxy('setImages',$images);
296
    }
297
298
    public function setOrganizationName(OrganizationName $organizationNames)
299
    {
300
        return $this->proxy('setOrganizationName', $organizationNames);
301
    }
302
303
    public function getOrganizationName()
304
    {
305
        return $this->proxy('getOrganizationName');
306
    }
307
308
    public function getDescription()
309
    {
310
        return $this->proxy('getDescription');
311
    }
312
313
    public function setDescription($description)
314
    {
315
        return $this->proxy('setDescription', $description);
316
    }
317
318
    public function setEmployees(Collection $employees)
319
    {
320
        return $this->proxy('setEmployees', $employees);
321
    }
322
323
    public function getEmployees()
324
    {
325
        return $this->proxy('getEmployees');
326
    }
327
328
    public function getEmployeesByRole($role)
329
    {
330
        return $this->proxy('getEmployeesByRole', $role);
331
    }
332
333
    public function getEmployee($userOrId)
334
    {
335
        return $this->proxy('getEmployee', $userOrId);
336
    }
337
338
    public function setExternalId($externalId)
339
    {
340
        return $this->proxy('setExternalId', $externalId);
341
    }
342
343
    public function getExternalId()
344
    {
345
        return $this->proxy('getExternalId');
346
    }
347
348
    public function getUser()
349
    {
350
        return $this->proxy('getUser');
351
    }
352
353
    public function setUser(UserInterface $user)
354
    {
355
        $this->_type = null; // force reload of references!
356
        return $this->proxy('setUser', $user);
357
    }
358
359
    public function getJobs()
360
    {
361
        return $this->proxy('getJobs');
362
    }
363
364
    public function getPermissions()
365
    {
366
        return $this->proxy('getPermissions');
367
    }
368
369
    public function setPermissions(PermissionsInterface $permissions)
370
    {
371
        return $this->proxy('setPermissions', $permissions);
372
    }
373
374
    public function getPermissionsResourceId()
375
    {
376
        return $this->proxy('getPermissionsResourceId');
377
    }
378
379
    public function getPermissionsUserIds($type = null)
380
    {
381
        return $this->proxy('getPermissionsUSerIds', $type);
382
    }
383
384
    public function getSearchableProperties()
385
    {
386
        return $this->proxy('getSearchableProperties');
387
    }
388
389
    public function setKeywords(array $keywords)
390
    {
391
        return $this->proxy('setKeywords', $keywords);
392
    }
393
394
    public function clearKeywords()
395
    {
396
        return $this->proxy('clearKeywords');
397
    }
398
399
    public function getTemplate()
400
    {
401
        return $this->proxy('getTemplate');
402
    }
403
404
    public function setTemplate(TemplateInterface $template)
405
    {
406
        return $this->proxy('setTemplate', $template);
407
    }
408
409
    public function getWorkflowSettings()
410
    {
411
        return $this->proxy('getWorkflowSettings');
412
    }
413
414
    public function setWorkflowSettings($workflowSettings)
415
    {
416
        return $this->proxy('setWorkflowSettings', $workflowSettings);
417
    }
418
419
    /**#@-*/
420
}
421