Completed
Pull Request — develop (#462)
by ANTHONIUS
08:03
created

Job::unsetOrganization()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
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\ClonePropertiesTrait;
13
use Core\Entity\AttachableEntityTrait;
14
use Core\Entity\EntityInterface;
15
use Core\Entity\MetaDataProviderTrait;
16
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17
use Doctrine\Common\Collections\Collection;
18
use Auth\Entity\UserInterface;
19
use Core\Entity\Permissions;
20
use Core\Entity\PermissionsInterface;
21
use Organizations\Entity\OrganizationInterface;
22
use Core\Entity\DraftableEntityInterface;
23
use Core\Entity\Collection\ArrayCollection;
24
use Core\Entity\SnapshotGeneratorProviderInterface;
25
use Zend\I18n\Validator\DateTime;
26
27
/**
28
 * The job model
29
 *
30
 * @ODM\Document(collection="jobs", repositoryClass="Jobs\Repository\Job")
31
 * @ODM\Indexes({
32
 *     @ODM\Index(keys={"datePublishStart.date"="asc"})
33
 * })
34
 *
35
 * @author Mathias Gelhausen <[email protected]>
36
 * @author Mathias Weitz <[email protected]>
37
 * @author Carsten Bleek <[email protected]>
38
 * @since 0.29 add temporary isDeleted flag and corresponding delete() method.
39
 */
40
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...
41
                                        DraftableEntityInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
42
                                        SnapshotGeneratorProviderInterface
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 40 found
Loading history...
43
44
{
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line following the class declaration; found 1 line(s)
Loading history...
45
    use AttachableEntityTrait, MetaDataProviderTrait, ClonePropertiesTrait;
46
47
48
    private $cloneProperties = [
0 ignored issues
show
Unused Code introduced by
The property $cloneProperties is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
49
        'classifications', 'atsMode',
50
    ];
51
52
    /**
53
     * unique ID of a job posting used by applications to reference
54
     * a job
55
     *
56
     * @var String
57
     * @ODM\Field(type="string") @ODM\Index
58
     **/
59
    protected $applyId;
60
    
61
    /**
62
     * title of a job posting
63
     *
64
     * @var String
65
     * @ODM\Field(type="string")
66
     */
67
    protected $title;
68
    
69
70
    /**
71
     * name of the publishing company
72
     *
73
     * @var String
74
     * @ODM\Field(type="string")
75
     */
76
    protected $company;
77
    
78
    /**
79
     * publishing company
80
     *
81
     * @var OrganizationInterface
82
     * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", simple=true, inversedBy="jobs")
83
     * @ODM\Index
84
     */
85
    protected $organization;
86
    
87
    
88
    /**
89
     * Email Address, which is used to send notifications about e.g. new applications.
90
     *
91
     * @var String
92
     * @ODM\Field(type="string")
93
     **/
94
    protected $contactEmail;
95
    
96
    /**
97
     * the owner of a Job Posting
98
     *
99
     * @var UserInterface $user
100
     * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true)
101
     * @ODM\Index
102
     */
103
    protected $user;
104
    
105
    /**
106
     * all applications of a certain jobad
107
     *
108
     * @var Collection
109
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", simple=true, mappedBy="job",
110
     *                    repositoryMethod="loadApplicationsForJob")
111
     */
112
    protected $applications;
113
    
114
    /**
115
     * new applications
116
     *
117
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application",
118
     *                    repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job")
119
     * @var Int
120
     */
121
    protected $unreadApplications;
122
    
123
    /**
124
     * language of the job posting. Languages are ISO 639-1 coded
125
     *
126
     * @var String
127
     * @ODM\Field(type="string")
128
     */
129
    protected $language;
130
    
131
    /**
132
     * location of the job posting. This is a plain text, which describes the location in
133
     * search e.g. results.
134
     *
135
     * @var String
136
     * @ODM\Field(type="string")
137
     */
138
    protected $location;
139
140
    /**
141
     * locations of the job posting. This collection contains structured coordinates,
142
     * postal codes, city, region, and country names
143
     *
144
     * @var Collection
145
     * @ODM\EmbedMany(targetDocument="Location")
146
     */
147
    protected $locations;
148
    
149
    /**
150
     * Link which points to the job posting
151
     *
152
     * @var String
153
     * @ODM\Field(type="string")
154
     **/
155
    protected $link;
156
    
157
    /**
158
     * publishing date of a job posting
159
     *
160
     * @var String
161
     * @ODM\Field(type="tz_date")
162
     */
163
    protected $datePublishStart;
164
165
    /**
166
     * end date of a job posting
167
     *
168
     * @var String
169
     * @ODM\Field(type="tz_date")
170
     */
171
    protected $datePublishEnd;
172
    
173
    /**
174
     * Status of the job posting
175
     *
176
     * @var Status
177
     * @ODM\EmbedOne(targetDocument="Status")
178
     * @ODM\Index
179
     */
180
    protected $status;
181
182
    /**
183
     * History on an job posting
184
     *
185
     * @var Collection
186
     * @ODM\EmbedMany(targetDocument="History")
187
     */
188
    protected $history;
189
190
    /**
191
     * Flag, privacy policy is accepted or not.
192
     *
193
     * @var bool
194
     * @ODM\Boolean
195
     */
196
    protected $termsAccepted;
197
    
198
    /**
199
     * Reference of a job opening, on which an applicant can refer to.
200
     *
201
     * @var String
202
     * @ODM\Field(type="string")
203
     */
204
    protected $reference;
205
    
206
    /**
207
     * Unified Resource Locator to the company-Logo
208
     *
209
     * @var String
210
     * @ODM\Field(type="string")
211
     */
212
    protected $logoRef;
213
214
    /**
215
     * Template-Name
216
     *
217
     * @var String
218
     * @ODM\Field(type="string")
219
     */
220
    protected $template;
221
222
    /**
223
     * Application link.
224
     *
225
     * @var String
226
     * @ODM\Field(type="string")
227
     */
228
    protected $uriApply;
229
230
    /**
231
     * Unified Resource Locator the Yawik, which handled this job first - so
232
     * does know who is the one who has commited this job.
233
     *
234
     * @var String
235
     * @ODM\Field(type="string")
236
     */
237
    protected $uriPublisher;
238
239
    /**
240
     * @var
241
     * @ODM\EmbedMany(targetDocument="Publisher")
242
     */
243
    protected $publisher;
244
245
    /**
246
     * The ATS mode entity.
247
     *
248
     * @var AtsMode
249
     * @ODM\EmbedOne(targetDocument="AtsMode")
250
     */
251
    protected $atsMode;
252
253
    /**
254
     * this must be enabled to use applications forms etc. for this job or
255
     * to see number of applications in the list of applications
256
     *
257
     * @var Boolean
258
     *
259
     * @ODM\Boolean
260
     */
261
    protected $atsEnabled;
262
    
263
    /**
264
     * Permissions
265
     *
266
     * @var PermissionsInterface
267
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
268
     */
269
    protected $permissions;
270
271
    /**
272
     * The actual name of the organization.
273
     *
274
     * @var TemplateValues
275
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues")
276
     */
277
    protected $templateValues;
278
279
280
    /**
281
     * Can contain various Portals
282
     *
283
     * @var array
284
     * @ODM\Collection*/
285
    protected $portals = array();
286
287
    /**
288
     * Flag indicating draft state of this job.
289
     *
290
     * @var bool
291
     * @ODM\Boolean
292
     */
293
    protected $isDraft = false;
294
295
    /**
296
     * Classifications
297
     *
298
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\Classifications")
299
     * @var Classifications
300
     * @since 0.29
301
     */
302
    protected $classifications;
303
304
    /**
305
     * Delete flag.
306
     *
307
     * @internal
308
     *      This is meant as a temporary flag, until
309
     *      SoftDelete is implemented.
310
     *
311
     * @ODM\Field(type="boolean")
312
     * @var bool
313
     * @since 0.29
314
     */
315
    protected $isDeleted = false;
316
317
    /**
318
     *
319
     * @ODM\ReferenceMany(targetDocument="\Jobs\Entity\JobSnapshot", mappedBy="snapshotEntity", sort={"snapshotMeta.dateCreated"="desc"})
320
     * @var JobSnapshot
321
     */
322
    protected $snapshots;
323
324
    /**
325
     * @ODM\ReferenceOne(targetDocument="\Jobs\Entity\JobSnapshot", mappedBy="snapshotEntity", sort={"snapshotMeta.dateCreated"="desc"})
326
     *
327
     * @var JobSnapshot
328
     */
329
    protected $latestSnapshot;
330
331
332
    public function getSnapshots()
333
    {
334
        return $this->snapshots;
335
    }
336
337
    public function getLatestSnapshot()
338
    {
339
        return $this->latestSnapshot;
340
    }
341
342
    public function hasSnapshotDraft()
343
    {
344
        $snapshot = $this->getLatestSnapshot();
345
        return $snapshot && $snapshot->getSnapshotMeta()->hasStatus(JobSnapshotStatus::ACTIVE);
346
    }
347
348
    /**
349
     * @return string
350
     */
351
    public function getResourceId()
352
    {
353
        return 'Entity/Jobs/Job';
354
    }
355
356
    /**
357
     * @see \Jobs\Entity\JobInterface::setApplyId()
358
     * @param String $applyId
359
     * @return \Jobs\Entity\JobInterface
360
     */
361
    public function setApplyId($applyId)
362
    {
363
        $this->applyId = (string) $applyId;
364
        return $this;
365
    }
366
    /**
367
     * @see \Jobs\Entity\JobInterface::getApplyId()
368
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be string|\MongoId?

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...
369
     */
370
    public function getApplyId()
371
    {
372
        if (!isset($this->applyId)) {
373
            // take the entity-id as a default
374
            $this->applyId = $this->id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->id can also be of type object<MongoId>. However, the property $applyId is declared as type string. 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...
375
        }
376
        return $this->applyId;
377
    }
378
379
    /**
380
     * Gets the title of a job posting
381
     *
382
     * @return string
383
     */
384
    public function getTitle()
385
    {
386
        return $this->title;
387
    }
388
389
    /**
390
     * Sets the title of a job posting
391
     *
392
     * @see \Jobs\Entity\JobInterface::setTitle()
393
     * @param String $title
394
     * @return \Jobs\Entity\JobInterface
395
     */
396
    public function setTitle($title)
397
    {
398
        $this->title = (string) $title;
399
        return $this;
400
    }
401
    
402
    /**
403
     * Gets the name oof the company. If there is an organization assigned to the
404
     * job posting. Take the name of the organization.
405
     *
406
     * @param bool $useOrganizationEntity Get the name from the organization entity, if it is available.
407
     * @see \Jobs\Entity\JobInterface::getCompany()
408
     * @return string
409
     */
410
    public function getCompany($useOrganizationEntity = true)
411
    {
412
        if ($this->organization && $useOrganizationEntity) {
413
            return $this->organization->getOrganizationName()->getName();
414
        }
415
416
        return $this->company;
417
    }
418
419
    /**
420
     * (non-PHPdoc)
421
     * @see \Jobs\Entity\JobInterface::setCompany()
422
     */
423
    public function setCompany($company)
424
    {
425
        $this->company = $company;
426
        return $this;
427
    }
428
    
429
     /**
430
     * (non-PHPdoc)
431
     * @see \Jobs\Entity\JobInterface::getOrganization()
432
     */
433
    public function getOrganization()
434
    {
435
        return $this->organization;
436
    }
437
    
438
    /**
439
     * @inheritdoc
440
     */
441
    public function setOrganization(OrganizationInterface $organization = null)
442
    {
443
        $permissions = $this->getPermissions();
444
445
        if ($this->organization) {
446
            $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...
447
        }
448
        $this->organization = $organization;
449
        $permissions->grant($organization);
0 ignored issues
show
Bug introduced by
It seems like $organization defined by parameter $organization on line 441 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...
450
451
        return $this;
452
    }
453
454
455
456
    /**
457
     * (non-PHPdoc)
458
     * @see \Jobs\Entity\JobInterface::getContactEmail()
459
     */
460
    public function getContactEmail()
461
    {
462
        if (false !== $this->contactEmail && !$this->contactEmail) {
463
            $user = $this->getUser();
464
            $email = false;
465
            if (isset($user)) {
466
                $email = $user->getInfo()->getEmail();
467
            }
468
            $this->setContactEmail($email);
0 ignored issues
show
Security Bug introduced by
It seems like $email defined by false on line 464 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...
469
        }
470
        return $this->contactEmail;
471
    }
472
473
    /**
474
     * (non-PHPdoc)
475
     * @see \Jobs\Entity\JobInterface::setContactEmail()
476
     */
477
    public function setContactEmail($email)
478
    {
479
        $this->contactEmail = (string) $email;
480
        return $this;
481
    }
482
483
    /**
484
     * (non-PHPdoc)
485
     * @see \Jobs\Entity\JobInterface::setLanguage()
486
     */
487
    public function setLanguage($language)
488
    {
489
        $this->language = $language;
490
        return $this;
491
    }
492
    /**
493
     * (non-PHPdoc)
494
     * @see \Jobs\Entity\JobInterface::getLanguage()
495
     */
496
    public function getLanguage()
497
    {
498
        return $this->language;
499
    }
500
    /**
501
     * (non-PHPdoc)
502
     * @see \Jobs\Entity\JobInterface::setLocation()
503
     */
504
    public function setLocation($location)
505
    {
506
        $this->location = $location;
507
        return $this;
508
    }
509
    /**
510
     * (non-PHPdoc)
511
     * @see \Jobs\Entity\JobInterface::getLocation()
512
     */
513
    public function getLocation()
514
    {
515
        if (null === $this->location) {
516
            $array=[];
517
            if(null != $this->locations){
518
                foreach ($this->locations as $location) { /* @var \Core\Entity\LocationInterface $location */
519
                    $array[]=$location->getCity();
520
                }
521
                return implode(', ', $array);
522
            }
523
        }
524
        return $this->location;
525
    }
526
    /**
527
     * (non-PHPdoc)
528
     * @see \Jobs\Entity\JobInterface::setLocations()
529
     */
530
    public function setLocations($locations)
531
    {
532
        $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...
533
        return $this;
534
    }
535
    /**
536
     * (non-PHPdoc)
537
     * @see \Jobs\Entity\JobInterface::getLocations()
538
     */
539
    public function getLocations()
540
    {
541
        if (!$this->locations) {
542
            $this->setLocations(new ArrayCollection());
543
        }
544
        return $this->locations;
545
    }
546
    /**
547
     * (non-PHPdoc)
548
     * @see \Jobs\Entity\JobInterface::setUser()
549
     */
550 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...
551
    {
552
        if ($this->user) {
553
            $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...
554
        }
555
        $this->user = $user;
556
        $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL);
557
        return $this;
558
    }
559
    /**
560
     * (non-PHPdoc)
561
     * @see \Jobs\Entity\JobInterface::getUser()
562
     */
563
    public function getUser()
564
    {
565
        return $this->user;
566
    }
567
568 View Code Duplication
    public function unsetUser($removePermissions = true)
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...
569
    {
570
        if ($this->user) {
571
            if ($removePermissions) {
572
                $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL);
573
            }
574
            $this->user=null;
575
        }
576
577
        return $this;
578
    }
579
580 View Code Duplication
    public function unsetOrganization($removePermissions = true)
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...
581
    {
582
        if($this->organization && $removePermissions){
583
            $this->getPermissions()->revoke($this->organization,Permissions::PERMISSION_ALL);
584
        }
585
586
        $this->organization = null;
587
588
        return $this;
589
    }
590
591
    /**
592
     * (non-PHPdoc)
593
     * @see \Jobs\Entity\JobInterface::setApplications()
594
     */
595
    public function setApplications(Collection $applications)
596
    {
597
        $this->applications = $applications;
598
        return $this;
599
    }
600
601
    /**
602
     * (non-PHPdoc)
603
     * @see \Jobs\Entity\JobInterface::getApplications()
604
     */
605
    public function getApplications()
606
    {
607
        return $this->applications;
608
    }
609
610
    /**
611
     * Gets the number of unread applications
612
     * @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...
613
     */
614
    public function getUnreadApplications()
615
    {
616
        return $this->unreadApplications;
617
    }
618
    /**
619
     * (non-PHPdoc)
620
     * @see \Jobs\Entity\JobInterface::getLink()
621
     */
622
    public function getLink()
623
    {
624
        return $this->link;
625
    }
626
    /**
627
     * (non-PHPdoc)
628
     * @see \Jobs\Entity\JobInterface::setLink()
629
     */
630
    public function setLink($link)
631
    {
632
        $this->link = $link;
633
        return $this;
634
    }
635
    /**
636
     * (non-PHPdoc)
637
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
638
     */
639
    public function getDatePublishStart()
640
    {
641
        return $this->datePublishStart;
642
    }
643
    /**
644
     * (non-PHPdoc)
645
     * @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...
646
     * @see \Jobs\Entity\JobInterface::setDatePublishStart()
647
     * @return $this
648
     */
649 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...
650
    {
651
        if (!isset($datePublishStart) || is_string($datePublishStart)) {
652
            $datePublishStart = new \DateTime($datePublishStart);
653
        } else if (!$datePublishStart instanceOf \DateTime) {
654
            throw new \InvalidArgumentException('Expected object of type \DateTime');
655
        }
656
657
        $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...
658
        return $this;
659
    }
660
661
    /**
662
     * (non-PHPdoc)
663
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
664
     */
665
    public function getDatePublishEnd()
666
    {
667
        return $this->datePublishEnd;
668
    }
669
    /**
670
     * (non-PHPdoc)
671
     * @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...
672
     * @see \Jobs\Entity\JobInterface::setDatePublishEnd()
673
     * @return $this
674
     */
675 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...
676
    {
677
        if (is_string($datePublishEnd)) {
678
            $datePublishEnd = new \DateTime($datePublishEnd);
679
        } else if (!$datePublishEnd instanceOf \DateTime) {
680
            throw new \InvalidArgumentException('Expected object of type \DateTime');
681
        }
682
683
        $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...
684
        return $this;
685
    }
686
687
    /**
688
     * Modifies the state of an application.
689
     *
690
     * Creates a history entry.
691
     *
692
     * @param StatusInterface|string $status
693
     * @param string $message
694
     * @return Job
695
     */
696 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...
697
    {
698
        $this->setStatus($status);
0 ignored issues
show
Bug introduced by
It seems like $status defined by parameter $status on line 696 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...
699
        $status = $this->getStatus(); // ensure StatusEntity
700
701
        $history = new History($status, $message);
702
703
        $this->getHistory()->add($history);
704
        return $this;
705
    }
706
707
    /**
708
     * (non-PHPdoc)
709
     * @see \Jobs\Entity\JobInterface::getStatus()
710
     */
711
    public function getStatus()
712
    {
713
        return $this->status;
714
    }
715
    /**
716
     * (non-PHPdoc)
717
     * @see \Jobs\Entity\JobInterface::setStatus()
718
     */
719
    public function setStatus($status)
720
    {
721
        if (!$status instanceof Status) {
722
            $status = new Status($status);
723
        }
724
        $this->status = $status;
725
    }
726
727
    /**
728
     * {@inheritDoc}
729
     * @see JobInterface::setHistory()
730
     * @return Job
731
     */
732
    public function setHistory(Collection $history)
733
    {
734
        $this->history = $history;
735
        return $this;
736
    }
737
738
    /**
739
     * {@inheritDoc}
740
     * @see JobInterface::getHistory()
741
     */
742
    public function getHistory()
743
    {
744
        if (null == $this->history) {
745
            $this->setHistory(new ArrayCollection());
746
        }
747
        return $this->history;
748
    }
749
750
    /**
751
     * {@inheritDoc}
752
     * @see JobInterface::setTermsAccepted()
753
     * @return self
754
     */
755
    public function setTermsAccepted($termsAccepted)
756
    {
757
        $this->termsAccepted = $termsAccepted;
758
        return $this;
759
    }
760
761
    /**
762
     * {qinheritDoc}
763
     * @see JobInterface::getTermsAccepted()
764
     */
765
    public function getTermsAccepted()
766
    {
767
        return $this->termsAccepted;
768
    }
769
770
    /**
771
     * (non-PHPdoc)
772
     * @see JobInterface::getReference()
773
     */
774
    public function getReference()
775
    {
776
        return $this->reference;
777
    }
778
    /**
779
     * (non-PHPdoc)
780
     * @see JobInterface::setReference()
781
     */
782
    public function setReference($reference)
783
    {
784
        $this->reference = $reference;
785
        return $this;
786
    }
787
788
    public function setAtsMode(AtsMode $mode)
789
    {
790
        $this->atsMode = $mode;
791
792
        return $this;
793
    }
794
795
    public function getAtsMode()
796
    {
797
        if (!$this->atsMode) {
798
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
799
        }
800
801
        return $this->atsMode;
802
    }
803
804
805
    /**
806
     * checks, weather a job is enabled for getting applications
807
     * @return boolean
808
     */
809
    public function getAtsEnabled()
810
    {
811
        return $this->atsEnabled;
812
    }
813
    /**
814
     * enables a job add to receive applications
815
     *
816
     * @param boolean $atsEnabled
817
     * @return \Jobs\Entity\Job
818
     */
819
    public function setAtsEnabled($atsEnabled)
820
    {
821
        $this->atsEnabled = $atsEnabled;
822
        return $this;
823
    }
824
    /**
825
     * returns an uri to the organization logo.
826
     *
827
     * @return string
828
     */
829
    public function getLogoRef()
830
    {
831
        /** @var $organization \Organizations\Entity\Organization */
832
        $organization = $this->organization;
833
        if (is_object($organization) && $organization->getImage()) {
0 ignored issues
show
Deprecated Code introduced by
The method Organizations\Entity\Organization::getImage() has been deprecated with message: since 0.29; use $this->getImages()->get()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
834
            $organizationImage = $organization->getImage();
0 ignored issues
show
Deprecated Code introduced by
The method Organizations\Entity\Organization::getImage() has been deprecated with message: since 0.29; use $this->getImages()->get()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
835
            return "/file/Organizations.OrganizationImage/" . $organizationImage->getId();
836
        }
837
        return $this->logoRef;
838
    }
839
    /**
840
     * Set the uri to the organisations logo
841
     *
842
     * @param string $logoRef
843
     * @return \Jobs\Entity\Job
844
     */
845
    public function setLogoRef($logoRef)
846
    {
847
        $this->logoRef = $logoRef;
848
        return $this;
849
    }
850
851
    /**
852
     *
853
     *
854
     * @return string
855
     */
856
    public function getTemplate()
857
    {
858
        $template = $this->template;
859
        if (empty($template)) {
860
            $template = 'default';
861
        }
862
        return $template;
863
    }
864
    /**
865
     *
866
     *
867
     * @param string $template name of the Template
868
     * @return \Jobs\Entity\Job
869
     */
870
    public function setTemplate($template)
871
    {
872
        $this->template = $template;
873
        return $this;
874
    }
875
876
877
878
    /**
879
     * Gets the uri of an application link
880
     *
881
     * @return String
882
     */
883
    public function getUriApply()
884
    {
885
        return $this->uriApply;
886
    }
887
888
    /**
889
     * Sets the uri of an application link
890
     *
891
     * @param String $uriApply
892
     * @return \Jobs\Entity\Job
893
     */
894
    public function setUriApply($uriApply)
895
    {
896
        $this->uriApply = $uriApply;
897
        return $this;
898
    }
899
900
    /**
901
     * Gets the uri of a publisher
902
     *
903
     * @return String
904
     */
905
    public function getUriPublisher()
906
    {
907
        return $this->uriPublisher;
908
    }
909
    /**
910
     *
911
     * @param String $uriPublisher
912
     * @return \Jobs\Entity\Job
913
     */
914
    public function setUriPublisher($uriPublisher)
915
    {
916
        $this->uriPublisher = $uriPublisher;
917
        return $this;
918
    }
919
920
    /**
921
     * @param $key
922
     * @return mixed
923
     */
924
    public function getPublisher($key)
925
    {
926
        $result = null;
927
        foreach ($this->publisher as $publisher) {
928
            if ($publisher->host == $key) {
929
                $result = $publisher;
930
            }
931
        }
932
        if (!isset($result)) {
933
            $result = new Publisher();
934
            $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...
935
            $this->publisher[] = $result;
936
        }
937
        return $result;
938
    }
939
940
    public function setPublisherReference($key, $reference)
941
    {
942
        $publisher = $this->getPublisher($key);
943
        $publisher->reference;
944
        return $this;
945
    }
946
947
    
948
    /**
949
     * (non-PHPdoc)
950
     * @see \Core\Entity\PermissionsAwareInterface::getPermissions()
951
     */
952
    public function getPermissions()
953
    {
954
        if (!$this->permissions) {
955
            $permissions = new Permissions('Job/Permissions');
956
            if ($this->user) {
957
                $permissions->grant($this->user, Permissions::PERMISSION_ALL);
958
            }
959
            $this->setPermissions($permissions);
960
        }
961
962
        return $this->permissions;
963
    }
964
    
965
    /**
966
     * (non-PHPdoc)
967
     * @see \Core\Entity\PermissionsAwareInterface::setPermissions()
968
     */
969
    public function setPermissions(PermissionsInterface $permissions)
970
    {
971
        $this->permissions = $permissions;
972
        return $this;
973
    }
974
975
    /**
976
     * Gets the Values of a job template
977
     *
978
     * @return TemplateValues
979
     */
980
    public function getTemplateValues()
981
    {
982
        if (!$this->templateValues instanceof TemplateValues) {
983
            $this->templateValues = new TemplateValues();
984
        }
985
        return $this->templateValues;
986
    }
987
988
    /**
989
     * @param EntityInterface $templateValues
0 ignored issues
show
Documentation introduced by
Should the type for parameter $templateValues not be null|EntityInterface?

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...
990
     *
991
     * @return $this
992
     */
993
    public function setTemplateValues(EntityInterface $templateValues = null)
994
    {
995
        if (!$templateValues instanceof TemplateValues) {
996
            $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...
997
        }
998
        $this->templateValues = $templateValues;
999
        return $this;
1000
    }
1001
1002
    /**
1003
     * Sets the list of channels where a job opening should be published
1004
     *
1005
     * @param Array
1006
     * {@inheritdoc}
1007
     */
1008
    public function setPortals(array $portals)
1009
    {
1010
        $this->portals = $portals;
1011
        return $this;
1012
    }
1013
1014
    /**
1015
     * Gets the list of channels where the job opening should be published
1016
     *
1017
     * {@inheritdoc}
1018
     * @return array
1019
     */
1020
    public function getPortals()
1021
    {
1022
        return $this->portals;
1023
    }
1024
1025
    /**
1026
     * Gets the flag indicating the draft state.
1027
     *
1028
     * @return bool
1029
     */
1030
    public function isDraft()
1031
    {
1032
        return $this->isDraft;
1033
    }
1034
1035
    /**
1036
     * Sets the flag indicating the draft state.
1037
     *
1038
     * @param boolean $flag
1039
     * @return DraftableEntityInterface
1040
     */
1041
    public function setIsDraft($flag)
1042
    {
1043
        $this->isDraft = (bool) $flag;
1044
        return $this;
1045
    }
1046
1047
    /**
1048
     * Gets the status and checks it against 'active'
1049
     *
1050
     * @return bool
1051
     */
1052
    public function isActive()
1053
    {
1054
        return !$this->isDraft && is_object($this->status) && $this->status->getName() == 'active';
0 ignored issues
show
Deprecated Code introduced by
The method Jobs\Entity\Status::getName() has been deprecated with message: since 0,29, use __toString()

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
1055
    }
1056
1057
    /**
1058
     * @return Job
1059
     */
1060
    public function makeSnapshot()
1061
    {
1062
        $snapshot = new JobSnapshot($this);
1063
        return $snapshot;
1064
    }
1065
1066
    /**
1067
     * @return array|mixed
1068
     */
1069
    public function getSnapshotGenerator()
1070
    {
1071
        $generator = array(
1072
            'hydrator' => '',
1073
            'target' => 'Jobs\Entity\JobSnapshot',
1074
            'exclude' => array('permissions', 'history')
1075
        );
1076
        return $generator;
1077
    }
1078
1079
    /**
1080
     * @param \Jobs\Entity\Classifications $classifications
1081
     *
1082
     * @return self
1083
     */
1084
    public function setClassifications($classifications)
1085
    {
1086
        $this->classifications = $classifications;
1087
1088
        return $this;
1089
    }
1090
1091
    /**
1092
     * @return \Jobs\Entity\Classifications
1093
     */
1094
    public function getClassifications()
1095
    {
1096
        if (!$this->classifications) {
1097
            $this->setClassifications(new Classifications());
1098
        }
1099
1100
        return $this->classifications;
1101
    }
1102
1103
    /**
1104
     * Mark this job as deleted.
1105
     *
1106
     * @internal
1107
     *      This is meant as temporary solution, until
1108
     *      SoftDelete is implemented.
1109
     *
1110
     * @return self
1111
     * @since 0.29
1112
     */
1113
    public function delete()
1114
    {
1115
        $this->isDeleted = true;
1116
1117
        return $this;
1118
    }
1119
1120
    public function isDeleted()
1121
    {
1122
        return $this->isDeleted;
1123
    }
1124
1125
1126
}
1127