Completed
Push — develop ( e970db...c13c79 )
by
unknown
15:28 queued 07:58
created

Job::getLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
6
 * @license   MIT
7
 */
8
9
namespace Jobs\Entity;
10
11
use Core\Entity\AbstractIdentifiableModificationDateAwareEntity as BaseEntity;
12
use Core\Entity\EntityInterface;
13
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
14
use Core\Repository\DoctrineMongoODM\Annotation as Cam;
15
use Doctrine\Common\Collections\Collection;
16
use Auth\Entity\UserInterface;
17
use Core\Entity\Permissions;
18
use Core\Entity\PermissionsInterface;
19
use Organizations\Entity\OrganizationInterface;
20
use Core\Entity\DraftableEntityInterface;
21
use Core\Entity\Collection\ArrayCollection;
22
use Core\Entity\SnapshotGeneratorProviderInterface;
23
use Zend\I18n\Validator\DateTime;
24
25
/**
26
 * The job model
27
 *
28
 * @ODM\Document(collection="jobs", repositoryClass="Jobs\Repository\Job")
29
 */
30
class Job extends BaseEntity implements JobInterface,
0 ignored issues
show
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
31
                                        DraftableEntityInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
32
                                        SnapshotGeneratorProviderInterface
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
33
{
34
35
    /**
36
     * unique ID of a job posting used by applications to reference
37
     * a job
38
     *
39
     * @var String
40
     * @ODM\Field(type="string") @ODM\Index
41
     **/
42
    protected $applyId;
43
    
44
    /**
45
     * title of a job posting
46
     *
47
     * @var String
48
     * @ODM\Field(type="string")
49
     */
50
    protected $title;
51
    
52
53
    /**
54
     * name of the publishing company
55
     *
56
     * @var String
57
     * @ODM\Field(type="string")
58
     */
59
    protected $company;
60
    
61
    /**
62
     * publishing company
63
     *
64
     * @var OrganizationInterface
65
     * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", simple=true, inversedBy="jobs")
66
     * @ODM\Index
67
     */
68
    protected $organization;
69
    
70
    
71
    /**
72
     * Email Address, which is used to send notifications about e.g. new applications.
73
     *
74
     * @var String
75
     * @ODM\Field(type="string")
76
     **/
77
    protected $contactEmail;
78
    
79
    /**
80
     * the owner of a Job Posting
81
     *
82
     * @var UserInterface $user
83
     * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true)
84
     * @ODM\Index
85
     */
86
    protected $user;
87
    
88
    /**
89
     * all applications of a certain jobad
90
     *
91
     * @var Collection
92
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", simple=true, mappedBy="job",
93
     *                    repositoryMethod="loadApplicationsForJob")
94
     */
95
    protected $applications;
96
    
97
    /**
98
     * new applications
99
     *
100
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application",
101
     *                    repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job")
102
     * @var Int
103
     */
104
    protected $unreadApplications;
105
    
106
    /**
107
     * language of the job posting. Languages are ISO 639-1 coded
108
     *
109
     * @var String
110
     * @ODM\Field(type="string")
111
     */
112
    protected $language;
113
    
114
    /**
115
     * location of the job posting. This is a plain text, which describes the location in
116
     * search e.g. results.
117
     *
118
     * @var String
119
     * @ODM\Field(type="string")
120
     */
121
    protected $location;
122
123
    /**
124
     * locations of the job posting. This collection contains structured coordinates,
125
     * postal codes, city, region, and country names
126
     *
127
     * @var Collection
128
     * @ODM\EmbedMany(targetDocument="Location")
129
     */
130
    protected $locations;
131
    
132
    /**
133
     * Link which points to the job posting
134
     *
135
     * @var String
136
     * @ODM\Field(type="string")
137
     **/
138
    protected $link;
139
    
140
    /**
141
     * publishing date of a job posting
142
     *
143
     * @var String
144
     * @ODM\Field(type="tz_date")
145
     */
146
    protected $datePublishStart;
147
148
    /**
149
     * end date of a job posting
150
     *
151
     * @var String
152
     * @ODM\Field(type="tz_date")
153
     */
154
    protected $datePublishEnd;
155
    
156
    /**
157
     * Status of the job posting
158
     *
159
     * @var Status
160
     * @ODM\EmbedOne(targetDocument="Status")
161
     * @ODM\Index
162
     */
163
    protected $status;
164
165
    /**
166
     * History on an job posting
167
     *
168
     * @var Collection
169
     * @ODM\EmbedMany(targetDocument="History")
170
     */
171
    protected $history;
172
173
    /**
174
     * Flag, privacy policy is accepted or not.
175
     *
176
     * @var bool
177
     * @ODM\Boolean
178
     */
179
    protected $termsAccepted;
180
    
181
    /**
182
     * Reference of a job opening, on which an applicant can refer to.
183
     *
184
     * @var String
185
     * @ODM\Field(type="string")
186
     */
187
    protected $reference;
188
    
189
    /**
190
     * Unified Resource Locator to the company-Logo
191
     *
192
     * @deprecated (use $organization->image->uri instead)
193
     * @var String
194
     * @ODM\Field(type="string")
195
     */
196
    protected $logoRef;
197
198
    /**
199
     * Template-Name
200
     *
201
     * @var String
202
     * @ODM\Field(type="string")
203
     */
204
    protected $template;
205
206
    /**
207
     * Application link.
208
     *
209
     * @var String
210
     * @ODM\Field(type="string")
211
     */
212
    protected $uriApply;
213
214
    /**
215
     * Unified Resource Locator the Yawik, which handled this job first - so
216
     * does know who is the one who has commited this job.
217
     *
218
     * @var String
219
     * @ODM\Field(type="string")
220
     */
221
    protected $uriPublisher;
222
223
    /**
224
     * @var
225
     * @ODM\EmbedMany(targetDocument="Publisher")
226
     */
227
    protected $publisher;
228
229
    /**
230
     * The ATS mode entity.
231
     *
232
     * @var AtsMode
233
     * @ODM\EmbedOne(targetDocument="AtsMode")
234
     */
235
    protected $atsMode;
236
237
    /**
238
     * this must be enabled to use applications forms etc. for this job or
239
     * to see number of applications in the list of applications
240
     *
241
     * @var Boolean
242
     *
243
     * @ODM\Boolean
244
     */
245
    protected $atsEnabled;
246
    
247
    /**
248
     * Permissions
249
     *
250
     * @var PermissionsInterface
251
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
252
     */
253
    protected $permissions;
254
255
    /**
256
     * The actual name of the organization.
257
     *
258
     * @var TemplateValues
259
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues")
260
     */
261
    protected $templateValues;
262
263
264
    /**
265
     * Can contain various Portals
266
     *
267
     * @var array
268
     * @ODM\Collection*/
269
    protected $portals = array();
270
271
    /**
272
     * Flag indicating draft state of this job.
273
     *
274
     * @var bool
275
     * @ODM\Boolean
276
     */
277
    protected $isDraft = false;
278
279
    /**
280
     * @return string
281
     */
282
    public function getResourceId()
283
    {
284
        return 'Entity/Jobs/Job';
285
    }
286
287
    /**
288
     * @see \Jobs\Entity\JobInterface::setApplyId()
289
     * @param String $applyId
290
     * @return \Jobs\Entity\JobInterface
291
     */
292
    public function setApplyId($applyId)
293
    {
294
        $this->applyId = (string) $applyId;
295
        return $this;
296
    }
297
    /**
298
     * @see \Jobs\Entity\JobInterface::getApplyId()
299
     * @return String
300
     */
301
    public function getApplyId()
302
    {
303
        if (!isset($this->applyId)) {
304
            // take the entity-id as a default
305
            $this->applyId = $this->id;
306
        }
307
        return $this->applyId;
308
    }
309
310
    /**
311
     * Gets the title of a job posting
312
     *
313
     * @return string
314
     */
315
    public function getTitle()
316
    {
317
        return $this->title;
318
    }
319
320
    /**
321
     * Sets the title of a job posting
322
     *
323
     * @see \Jobs\Entity\JobInterface::setTitle()
324
     * @param String $title
325
     * @return \Jobs\Entity\JobInterface
326
     */
327
    public function setTitle($title)
328
    {
329
        $this->title = (string) $title;
330
        return $this;
331
    }
332
    
333
    /**
334
     * Gets the name oof the company. If there is an organization assigned to the
335
     * job posting. Take the name of the organization.
336
     *
337
     * (non-PHPdoc)
338
     * @see \Jobs\Entity\JobInterface::getCompany()
339
     */
340
    public function getCompany()
341
    {
342
        if ($this->organization) {
343
            return $this->organization->getOrganizationName()->getName();
344
        }
345
        return $this->company;
346
    }
347
348
    /**
349
     * (non-PHPdoc)
350
     * @see \Jobs\Entity\JobInterface::setCompany()
351
     */
352
    public function setCompany($company)
353
    {
354
        $this->company = $company;
355
        return $this;
356
    }
357
    
358
     /**
359
     * (non-PHPdoc)
360
     * @see \Jobs\Entity\JobInterface::getOrganization()
361
     */
362
    public function getOrganization()
363
    {
364
        return $this->organization;
365
    }
366
    
367
    /**
368
     * @inheritdoc
369
     */
370
    public function setOrganization(OrganizationInterface $organization = null)
371
    {
372
        $permissions = $this->getPermissions();
373
374
        if ($this->organization) {
375
            $permissions->revoke($this->organization, null, false);
0 ignored issues
show
Unused Code introduced by
The call to PermissionsInterface::revoke() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
376
        }
377
        $this->organization = $organization;
378
        $permissions->grant($organization);
0 ignored issues
show
Bug introduced by
It seems like $organization defined by parameter $organization on line 370 can be null; however, Core\Entity\PermissionsInterface::grant() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
379
380
        return $this;
381
    }
382
383
    /**
384
     * (non-PHPdoc)
385
     * @see \Jobs\Entity\JobInterface::getContactEmail()
386
     */
387
    public function getContactEmail()
388
    {
389
        if (false !== $this->contactEmail && !$this->contactEmail) {
390
            $user = $this->getUser();
391
            $email = false;
392
            if (isset($user)) {
393
                $email = $user->getInfo()->getEmail();
394
            }
395
            $this->setContactEmail($email);
0 ignored issues
show
Security Bug introduced by
It seems like $email defined by false on line 391 can also be of type false; however, Jobs\Entity\Job::setContactEmail() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
396
        }
397
        return $this->contactEmail;
398
    }
399
400
    /**
401
     * (non-PHPdoc)
402
     * @see \Jobs\Entity\JobInterface::setContactEmail()
403
     */
404
    public function setContactEmail($email)
405
    {
406
        $this->contactEmail = (string) $email;
407
        return $this;
408
    }
409
410
    /**
411
     * (non-PHPdoc)
412
     * @see \Jobs\Entity\JobInterface::setLanguage()
413
     */
414
    public function setLanguage($language)
415
    {
416
        $this->language = $language;
417
        return $this;
418
    }
419
    /**
420
     * (non-PHPdoc)
421
     * @see \Jobs\Entity\JobInterface::getLanguage()
422
     */
423
    public function getLanguage()
424
    {
425
        return $this->language;
426
    }
427
    /**
428
     * (non-PHPdoc)
429
     * @see \Jobs\Entity\JobInterface::setLocation()
430
     */
431
    public function setLocation($location)
432
    {
433
        $this->location = $location;
434
        return $this;
435
    }
436
    /**
437
     * (non-PHPdoc)
438
     * @see \Jobs\Entity\JobInterface::getLocation()
439
     */
440
    public function getLocation()
441
    {
442
        return $this->location;
443
    }
444
    /**
445
     * (non-PHPdoc)
446
     * @see \Jobs\Entity\JobInterface::setLocations()
447
     */
448
    public function setLocations($locations)
449
    {
450
        $this->locations = $locations;
0 ignored issues
show
Documentation Bug introduced by
It seems like $locations of type string is incompatible with the declared type object<Doctrine\Common\Collections\Collection> of property $locations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
451
        return $this;
452
    }
453
    /**
454
     * (non-PHPdoc)
455
     * @see \Jobs\Entity\JobInterface::getLocations()
456
     */
457
    public function getLocations()
458
    {
459
        if (!$this->locations) {
460
            $this->setLocations(new ArrayCollection());
461
        }
462
        return $this->locations;
463
    }
464
    /**
465
     * (non-PHPdoc)
466
     * @see \Jobs\Entity\JobInterface::setUser()
467
     */
468 View Code Duplication
    public function setUser(UserInterface $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
469
    {
470
        if ($this->user) {
471
            $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false);
0 ignored issues
show
Unused Code introduced by
The call to PermissionsInterface::revoke() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
472
        }
473
        $this->user = $user;
474
        $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL);
475
        return $this;
476
    }
477
    /**
478
     * (non-PHPdoc)
479
     * @see \Jobs\Entity\JobInterface::getUser()
480
     */
481
    public function getUser()
482
    {
483
        return $this->user;
484
    }
485
486
    public function unsetUser($removePermissions = true)
487
    {
488
        if ($this->user) {
489
            if ($removePermissions) {
490
                $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL);
491
            }
492
            $this->user=null;
493
        }
494
495
        return $this;
496
    }
497
498
    /**
499
     * (non-PHPdoc)
500
     * @see \Jobs\Entity\JobInterface::setApplications()
501
     */
502
    public function setApplications(Collection $applications)
503
    {
504
        $this->applications = $applications;
505
        return $this;
506
    }
507
508
    /**
509
     * (non-PHPdoc)
510
     * @see \Jobs\Entity\JobInterface::getApplications()
511
     */
512
    public function getApplications()
513
    {
514
        return $this->applications;
515
    }
516
517
    /**
518
     * Gets the number of unread applications
519
     * @return Collection
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
520
     */
521
    public function getUnreadApplications()
522
    {
523
        return $this->unreadApplications;
524
    }
525
    /**
526
     * (non-PHPdoc)
527
     * @see \Jobs\Entity\JobInterface::getLink()
528
     */
529
    public function getLink()
530
    {
531
        return $this->link;
532
    }
533
    /**
534
     * (non-PHPdoc)
535
     * @see \Jobs\Entity\JobInterface::setLink()
536
     */
537
    public function setLink($link)
538
    {
539
        $this->link = $link;
540
        return $this;
541
    }
542
    /**
543
     * (non-PHPdoc)
544
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
545
     */
546
    public function getDatePublishStart()
547
    {
548
        return $this->datePublishStart;
549
    }
550
    /**
551
     * (non-PHPdoc)
552
     * @param string $datePublishStart
0 ignored issues
show
Documentation introduced by
Should the type for parameter $datePublishStart not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
553
     * @see \Jobs\Entity\JobInterface::setDatePublishStart()
554
     * @return $this
555
     */
556 View Code Duplication
    public function setDatePublishStart($datePublishStart = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
557
    {
558
        if (!isset($datePublishStart) || is_string($datePublishStart)) {
559
            $datePublishStart = new \DateTime($datePublishStart);
560
        } else if (!$datePublishStart instanceOf \DateTime) {
561
            throw new \InvalidArgumentException('Expected object of type \DateTime');
562
        }
563
564
        $this->datePublishStart = $datePublishStart;
0 ignored issues
show
Documentation Bug introduced by
It seems like $datePublishStart of type object<DateTime> is incompatible with the declared type string of property $datePublishStart.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
565
        return $this;
566
    }
567
568
    /**
569
     * (non-PHPdoc)
570
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
571
     */
572
    public function getDatePublishEnd()
573
    {
574
        return $this->datePublishEnd;
575
    }
576
    /**
577
     * (non-PHPdoc)
578
     * @param string $datePublishEnd
0 ignored issues
show
Documentation introduced by
Should the type for parameter $datePublishEnd not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
579
     * @see \Jobs\Entity\JobInterface::setDatePublishEnd()
580
     * @return $this
581
     */
582 View Code Duplication
    public function setDatePublishEnd($datePublishEnd = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
583
    {
584
        if (is_string($datePublishEnd)) {
585
            $datePublishEnd = new \DateTime($datePublishEnd);
586
        } else if (!$datePublishEnd instanceOf \DateTime) {
587
            throw new \InvalidArgumentException('Expected object of type \DateTime');
588
        }
589
590
        $this->datePublishEnd = $datePublishEnd;
0 ignored issues
show
Documentation Bug introduced by
It seems like $datePublishEnd of type object<DateTime> is incompatible with the declared type string of property $datePublishEnd.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
591
        return $this;
592
    }
593
594
    /**
595
     * Modifies the state of an application.
596
     *
597
     * Creates a history entry.
598
     *
599
     * @param StatusInterface|string $status
600
     * @param string $message
601
     * @return Job
602
     */
603 View Code Duplication
    public function changeStatus($status, $message = '[System]')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
604
    {
605
        $this->setStatus($status);
0 ignored issues
show
Bug introduced by
It seems like $status defined by parameter $status on line 603 can also be of type object<Jobs\Entity\StatusInterface>; however, Jobs\Entity\Job::setStatus() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
606
        $status = $this->getStatus(); // ensure StatusEntity
607
608
        $history = new History($status, $message);
609
610
        $this->getHistory()->add($history);
611
        return $this;
612
    }
613
614
    /**
615
     * (non-PHPdoc)
616
     * @see \Jobs\Entity\JobInterface::getStatus()
617
     */
618
    public function getStatus()
619
    {
620
        return $this->status;
621
    }
622
    /**
623
     * (non-PHPdoc)
624
     * @see \Jobs\Entity\JobInterface::setStatus()
625
     */
626
    public function setStatus($status)
627
    {
628
        if (!$status instanceof Status) {
629
            $status = new Status($status);
630
        }
631
        $this->status = $status;
632
    }
633
634
    /**
635
     * {@inheritDoc}
636
     * @see JobInterface::setHistory()
637
     * @return Job
638
     */
639
    public function setHistory(Collection $history)
640
    {
641
        $this->history = $history;
642
        return $this;
643
    }
644
645
    /**
646
     * {@inheritDoc}
647
     * @see JobInterface::getHistory()
648
     */
649
    public function getHistory()
650
    {
651
        if (null == $this->history) {
652
            $this->setHistory(new ArrayCollection());
653
        }
654
        return $this->history;
655
    }
656
657
    /**
658
     * {@inheritDoc}
659
     * @see JobInterface::setTermsAccepted()
660
     * @return self
661
     */
662
    public function setTermsAccepted($termsAccepted)
663
    {
664
        $this->termsAccepted = $termsAccepted;
665
        return $this;
666
    }
667
668
    /**
669
     * {qinheritDoc}
670
     * @see JobInterface::getTermsAccepted()
671
     */
672
    public function getTermsAccepted()
673
    {
674
        return $this->termsAccepted;
675
    }
676
677
    /**
678
     * (non-PHPdoc)
679
     * @see JobInterface::getReference()
680
     */
681
    public function getReference()
682
    {
683
        return $this->reference;
684
    }
685
    /**
686
     * (non-PHPdoc)
687
     * @see JobInterface::setReference()
688
     */
689
    public function setReference($reference)
690
    {
691
        $this->reference = $reference;
692
        return $this;
693
    }
694
695
    public function setAtsMode(AtsMode $mode)
696
    {
697
        $this->atsMode = $mode;
698
699
        return $this;
700
    }
701
702
    public function getAtsMode()
703
    {
704
        if (!$this->atsMode) {
705
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
706
        }
707
708
        return $this->atsMode;
709
    }
710
711
712
    /**
713
     * checks, weather a job is enabled for getting applications
714
     * @return boolean
715
     */
716
    public function getAtsEnabled()
717
    {
718
        return $this->atsEnabled;
719
    }
720
    /**
721
     * enables a job add to receive applications
722
     *
723
     * @param boolean $atsEnabled
724
     * @return \Jobs\Entity\Job
725
     */
726
    public function setAtsEnabled($atsEnabled)
727
    {
728
        $this->atsEnabled = $atsEnabled;
729
        return $this;
730
    }
731
    /**
732
     * returns an uri to the organization logo
733
     *
734
     * @deprecated
735
     * @return string
736
     */
737
    public function getLogoRef()
738
    {
739
        /** @var $organization \Organizations\Entity\Organization */
740
        $organization = $this->organization;
741
        if (isset($organization) && isset($organization->image)) {
0 ignored issues
show
Documentation introduced by
The property $image is declared protected in Organizations\Entity\Organization. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
742
            $organizationImage = $organization->image;
0 ignored issues
show
Documentation introduced by
The property $image is declared protected in Organizations\Entity\Organization. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
743
            return "/file/Organizations.OrganizationImage/" . $organizationImage->id;
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in Core\Entity\AbstractIdentifiableEntity. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
744
        }
745
        return $this->logoRef;
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Job::$logoRef has been deprecated with message: (use $organization->image->uri instead)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
746
    }
747
    /**
748
     * Set the uri to the organisations logo
749
     *
750
     * @deprecated
751
     * @param string $logoRef
752
     * @return \Jobs\Entity\Job
753
     */
754
    public function setLogoRef($logoRef)
755
    {
756
        $this->logoRef = $logoRef;
0 ignored issues
show
Deprecated Code introduced by
The property Jobs\Entity\Job::$logoRef has been deprecated with message: (use $organization->image->uri instead)

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
757
        return $this;
758
    }
759
760
    /**
761
     *
762
     *
763
     * @return string
764
     */
765
    public function getTemplate()
766
    {
767
        $template = $this->template;
768
        if (empty($template)) {
769
            $template = 'default';
770
        }
771
        return $template;
772
    }
773
    /**
774
     *
775
     *
776
     * @param string $template name of the Template
777
     * @return \Jobs\Entity\Job
778
     */
779
    public function setTemplate($template)
780
    {
781
        $this->template = $template;
782
        return $this;
783
    }
784
785
786
787
    /**
788
     * Gets the uri of an application link
789
     *
790
     * @return String
791
     */
792
    public function getUriApply()
793
    {
794
        return $this->uriApply;
795
    }
796
797
    /**
798
     * Sets the uri of an application link
799
     *
800
     * @param String $uriApply
801
     * @return \Jobs\Entity\Job
802
     */
803
    public function setUriApply($uriApply)
804
    {
805
        $this->uriApply = $uriApply;
806
        return $this;
807
    }
808
809
    /**
810
     * Gets the uri of a publisher
811
     *
812
     * @return String
813
     */
814
    public function getUriPublisher()
815
    {
816
        return $this->uriPublisher;
817
    }
818
    /**
819
     *
820
     * @param String $uriPublisher
821
     * @return \Jobs\Entity\Job
822
     */
823
    public function setUriPublisher($uriPublisher)
824
    {
825
        $this->uriPublisher = $uriPublisher;
826
        return $this;
827
    }
828
829
    /**
830
     * @param $key
831
     * @return mixed
832
     */
833
    public function getPublisher($key)
834
    {
835
        $result = null;
836
        foreach ($this->publisher as $publisher) {
837
            if ($publisher->host == $key) {
838
                $result = $publisher;
839
            }
840
        }
841
        if (!isset($result)) {
842
            $result = new Publisher();
843
            $result->host = $key;
0 ignored issues
show
Documentation introduced by
The property $host is declared protected in Jobs\Entity\Publisher. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
844
            $this->publisher[] = $result;
845
        }
846
        return $result;
847
    }
848
849
    public function setPublisherReference($key, $reference)
0 ignored issues
show
Unused Code introduced by
The parameter $reference is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
850
    {
851
        $publisher = $this->getPublisher($key);
852
        $publisher->reference;
853
        return $this;
854
    }
855
856
    
857
    /**
858
     * (non-PHPdoc)
859
     * @see \Core\Entity\PermissionsAwareInterface::getPermissions()
860
     */
861
    public function getPermissions()
862
    {
863
        if (!$this->permissions) {
864
            $permissions = new Permissions('Job/Permissions');
865
            if ($this->user) {
866
                $permissions->grant($this->user, Permissions::PERMISSION_ALL);
0 ignored issues
show
Documentation introduced by
$this->user is of type object<Auth\Entity\UserInterface>, but the function expects a string|object<Core\Entit...sionsResourceInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
867
            }
868
            $this->setPermissions($permissions);
869
        }
870
871
        return $this->permissions;
872
    }
873
    
874
    /**
875
     * (non-PHPdoc)
876
     * @see \Core\Entity\PermissionsAwareInterface::setPermissions()
877
     */
878
    public function setPermissions(PermissionsInterface $permissions)
879
    {
880
        $this->permissions = $permissions;
881
        return $this;
882
    }
883
884
    /**
885
     * Gets the Values of a job template
886
     *
887
     * @return TemplateValues
888
     */
889
    public function getTemplateValues()
890
    {
891
        if (!$this->templateValues instanceof TemplateValues) {
892
            $this->templateValues = new TemplateValues();
893
        }
894
        return $this->templateValues;
895
    }
896
897
    /**
898
     * {@inheritdoc}
899
     */
900
    public function setTemplateValues(EntityInterface $templateValues = null)
901
    {
902
        if (!$templateValues instanceof TemplateValues) {
903
            $templateValues = new TemplateValues($templateValues);
0 ignored issues
show
Unused Code introduced by
The call to TemplateValues::__construct() has too many arguments starting with $templateValues.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
904
        }
905
        $this->templateValues = $templateValues;
906
        return $this;
907
    }
908
909
    /**
910
     * Sets the list of channels where a job opening should be published
911
     *
912
     * @param Array
913
     * {@inheritdoc}
914
     */
915
    public function setPortals(array $portals)
916
    {
917
        $this->portals = $portals;
918
        return $this;
919
    }
920
921
    /**
922
     * Gets the list of channels where the job opening should be published
923
     *
924
     * {@inheritdoc}
925
     * @return Array
926
     */
927
    public function getPortals()
928
    {
929
        return $this->portals;
930
    }
931
932
    /**
933
     * Gets the flag indicating the draft state.
934
     *
935
     * @return bool
936
     */
937
    public function isDraft()
938
    {
939
        return $this->isDraft;
940
    }
941
942
    /**
943
     * Sets the flag indicating the draft state.
944
     *
945
     * @param boolean $flag
946
     * @return DraftableEntityInterface
947
     */
948
    public function setIsDraft($flag)
949
    {
950
        $this->isDraft = (bool) $flag;
951
        return $this;
952
    }
953
954
    /**
955
     * Gets the status and checks it against 'active'
956
     *
957
     * @return bool
958
     */
959
    public function isActive()
960
    {
961
        return !$this->isDraft && $this->status->name == 'active';
0 ignored issues
show
Documentation introduced by
The property $name is declared protected in Jobs\Entity\Status. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
962
    }
963
964
    /**
965
     * @return Job
0 ignored issues
show
Documentation introduced by
Should the return type not be JobSnapshot?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
966
     */
967
    public function makeSnapshot()
968
    {
969
        $snapshot = new JobSnapshot($this);
0 ignored issues
show
Unused Code introduced by
The call to JobSnapshot::__construct() has too many arguments starting with $this.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
970
        return $snapshot;
971
    }
972
973
    /**
974
     * @return array|mixed
975
     */
976
    public function getSnapshotGenerator()
977
    {
978
        $generator = array(
979
            'hydrator' => '',
980
            'target' => 'Jobs\Entity\JobSnapshot',
981
            'exclude' => array('permissions', 'history')
982
        );
983
        return $generator;
984
    }
985
}
986