Completed
Push — develop ( 7b602d...d209d7 )
by
unknown
16:15 queued 08:21
created

Job::getDescription()   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-2015 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
24
/**
25
 * The job model
26
 *
27
 * @ODM\Document(collection="jobs", repositoryClass="Jobs\Repository\Job")
28
 */
29
class Job extends BaseEntity implements JobInterface, DraftableEntityInterface, SnapshotGeneratorProviderInterface
30
{
31
32
    /**
33
     * unique ID of a job posting used by applications to reference
34
     * a job
35
     *
36
     * @var String
37
     * @ODM\String @ODM\Index
38
     **/
39
    protected $applyId;
40
    
41
    /**
42
     * title of a job posting
43
     *
44
     * @var String
45
     * @ODM\String
46
     */
47
    protected $title;
48
    
49
50
    /**
51
     * name of the publishing company
52
     *
53
     * @var String
54
     * @ODM\String
55
     */
56
    protected $company;
57
    
58
    /**
59
     * publishing company
60
     *
61
     * @var OrganizationInterface
62
     * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", simple=true, inversedBy="jobs")
63
     * @ODM\Index
64
     */
65
    protected $organization;
66
    
67
    
68
    /**
69
     * Email Address, which is used to send notifications about e.g. new applications.
70
     *
71
     * @var String
72
     * @ODM\String
73
     **/
74
    protected $contactEmail;
75
    
76
    /**
77
     * the owner of a Job Posting
78
     *
79
     * @var UserInterface $user
80
     * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true)
81
     * @ODM\Index
82
     */
83
    protected $user;
84
    
85
    /**
86
     * all applications of a certain jobad
87
     *
88
     * @var Collection
89
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", simple=true, mappedBy="job",
90
     *                    repositoryMethod="loadApplicationsForJob")
91
     */
92
    protected $applications;
93
    
94
    /**
95
     * new applications
96
     *
97
     * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application",
98
     *                    repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job")
99
     * @var Int
100
     */
101
    protected $unreadApplications;
102
    
103
    /**
104
     * language of the job posting. Languages are ISO 639-1 coded
105
     *
106
     * @var String
107
     * @ODM\String
108
     */
109
    protected $language;
110
    
111
    /**
112
     * location of the job posting. This is a plain text, which describes the location in
113
     * search e.g. results.
114
     *
115
     * @var String
116
     * @ODM\String
117
     */
118
    protected $location;
119
120
    /**
121
     * locations of the job posting. This collection contains structured coordinates,
122
     * postal codes, city, region, and country names
123
     *
124
     * @var Collection
125
     * @ODM\EmbedMany(targetDocument="Location")
126
     */
127
    protected $locations;
128
    
129
    /**
130
     * Link which points to the job posting
131
     *
132
     * @var String
133
     * @ODM\String
134
     **/
135
    protected $link;
136
    
137
    /**
138
     * publishing date of a job posting
139
     *
140
     * @var String
141
     * @ODM\Field(type="tz_date")
142
     */
143
    protected $datePublishStart;
144
    
145
    /**
146
     * Status of the job posting
147
     *
148
     * @var Status
149
     * @ODM\EmbedOne(targetDocument="Status")
150
     * @ODM\Index
151
     */
152
    protected $status;
153
154
    /**
155
     * History on an job posting
156
     *
157
     * @var Collection
158
     * @ODM\EmbedMany(targetDocument="History")
159
     */
160
    protected $history;
161
162
    /**
163
     * Flag, privacy policy is accepted or not.
164
     *
165
     * @var bool
166
     * @ODM\Boolean
167
     */
168
    protected $termsAccepted;
169
    
170
    /**
171
     * Reference of a job opening, on which an applicant can refer to.
172
     *
173
     * @var String
174
     * @ODM\String
175
     */
176
    protected $reference;
177
    
178
    /**
179
     * Unified Resource Locator to the company-Logo
180
     *
181
     * @deprecated (use $organization->image->uri instead)
182
     * @var String
183
     * @ODM\String
184
     */
185
    protected $logoRef;
186
187
    /**
188
     * Template-Name
189
     *
190
     * @var String
191
     * @ODM\String
192
     */
193
    protected $template;
194
195
    /**
196
     * Application link.
197
     *
198
     * @var String
199
     * @ODM\String
200
     */
201
    protected $uriApply;
202
203
    /**
204
     * Unified Resource Locator the Yawik, which handled this job first - so
205
     * does know who is the one who has commited this job.
206
     *
207
     * @var String
208
     * @ODM\String
209
     */
210
    protected $uriPublisher;
211
212
    /**
213
     * @var
214
     * @ODM\EmbedMany(targetDocument="Publisher")
215
     */
216
    protected $publisher;
217
218
    /**
219
     * The ATS mode entity.
220
     *
221
     * @var AtsMode
222
     * @ODM\EmbedOne(targetDocument="AtsMode")
223
     */
224
    protected $atsMode;
225
226
    /**
227
     * this must be enabled to use applications forms etc. for this job or
228
     * to see number of applications in the list of applications
229
     *
230
     * @var Boolean
231
     *
232
     * @ODM\Boolean
233
     */
234
    protected $atsEnabled;
235
    
236
    /**
237
     * stores a list of lowercase keywords. This array can be regenerated by
238
     *   bin/cam jobs generatekeywords
239
     *
240
     * @ODM\Collection
241
     */
242
    protected $keywords;
243
    
244
    
245
    /**
246
     * Permissions
247
     *
248
     * @var PermissionsInterface
249
     * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions")
250
     */
251
    protected $permissions;
252
253
    /**
254
     * The actual name of the organization.
255
     *
256
     * @var TemplateValues
257
     * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues")
258
     */
259
    protected $templateValues;
260
261
262
    /**
263
     * Can contain various Portals
264
     *
265
     * @var array
266
     * @ODM\Collection*/
267
    protected $portals = array();
268
269
    /**
270
     * Flag indicating draft state of this job.
271
     *
272
     * @var bool
273
     * @ODM\Boolean
274
     */
275
    protected $isDraft = false;
276
277
    /**
278
     * Is this needed?
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
     * (non-PHPdoc)
335
     * @see \Jobs\Entity\JobInterface::getCompany()
336
     */
337
    public function getCompany()
338
    {
339
        if ($this->organization) {
340
            return $this->organization->getOrganizationName()->getName();
341
        }
342
        return $this->company;
343
    }
344
345
    /**
346
     * (non-PHPdoc)
347
     * @see \Jobs\Entity\JobInterface::setCompany()
348
     */
349
    public function setCompany($company)
350
    {
351
        $this->company = $company;
352
        return $this;
353
    }
354
    
355
     /**
356
     * (non-PHPdoc)
357
     * @see \Jobs\Entity\JobInterface::getOrganization()
358
     */
359
    public function getOrganization()
360
    {
361
        return $this->organization;
362
    }
363
    
364
    /**
365
     * @inheritdoc
366
     */
367
    public function setOrganization(OrganizationInterface $organization = null)
368
    {
369
        $permissions = $this->getPermissions();
370
371
        if ($this->organization) {
372
            $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...
373
        }
374
        $this->organization = $organization;
375
        $permissions->grant($organization);
0 ignored issues
show
Bug introduced by
It seems like $organization defined by parameter $organization on line 367 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...
376
377
        return $this;
378
    }
379
    
380
    
381
    /**
382
     * (non-PHPdoc)
383
     * @see \Jobs\Entity\JobInterface::getContactEmail()
384
     */
385
    public function getContactEmail()
386
    {
387
        if (false !== $this->contactEmail && !$this->contactEmail) {
388
            $user = $this->getUser();
389
            $email = false;
390
            if (isset($user)) {
391
                $email = $user->getInfo()->getEmail();
392
            }
393
            $this->setContactEmail($email);
0 ignored issues
show
Security Bug introduced by
It seems like $email defined by false on line 389 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...
394
        }
395
        return $this->contactEmail;
396
    }
397
    /**
398
     * (non-PHPdoc)
399
     * @see \Jobs\Entity\JobInterface::setContactEmail()
400
     */
401
    public function setContactEmail($email)
402
    {
403
        $this->contactEmail = (string) $email;
404
        return $this;
405
    }
406
    /**
407
     * (non-PHPdoc)
408
     * @see \Jobs\Entity\JobInterface::setLanguage()
409
     */
410
    public function setLanguage($language)
411
    {
412
        $this->language = $language;
413
        return $this;
414
    }
415
    /**
416
     * (non-PHPdoc)
417
     * @see \Jobs\Entity\JobInterface::getLanguage()
418
     */
419
    public function getLanguage()
420
    {
421
        return $this->language;
422
    }
423
    /**
424
     * (non-PHPdoc)
425
     * @see \Jobs\Entity\JobInterface::setLocation()
426
     */
427
    public function setLocation($location)
428
    {
429
        $this->location = $location;
430
        return $this;
431
    }
432
    /**
433
     * (non-PHPdoc)
434
     * @see \Jobs\Entity\JobInterface::getLocation()
435
     */
436
    public function getLocation()
437
    {
438
        return $this->location;
439
    }
440
    /**
441
     * (non-PHPdoc)
442
     * @see \Jobs\Entity\JobInterface::setLocations()
443
     */
444
    public function setLocations($locations)
445
    {
446
        $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...
447
        return $this;
448
    }
449
    /**
450
     * (non-PHPdoc)
451
     * @see \Jobs\Entity\JobInterface::getLocations()
452
     */
453
    public function getLocations()
454
    {
455
        if (!$this->locations) {
456
            $this->setLocations(new ArrayCollection());
457
        }
458
        return $this->locations;
459
    }
460
    /**
461
     * (non-PHPdoc)
462
     * @see \Jobs\Entity\JobInterface::setUser()
463
     */
464 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...
465
    {
466
        if ($this->user) {
467
            $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...
468
        }
469
        $this->user = $user;
470
        $this->getPermissions()->grant($user, Permissions::PERMISSION_ALL);
471
        return $this;
472
    }
473
    /**
474
     * (non-PHPdoc)
475
     * @see \Jobs\Entity\JobInterface::getUser()
476
     */
477
    public function getUser()
478
    {
479
        return $this->user;
480
    }
481
482
    public function unsetUser($removePermissions = true)
483
    {
484
        if ($this->user) {
485
            if ($removePermissions) {
486
                $this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL);
487
            }
488
            $this->user=null;
489
        }
490
491
        return $this;
492
    }
493
494
    /**
495
     * (non-PHPdoc)
496
     * @see \Jobs\Entity\JobInterface::setApplications()
497
     */
498
    public function setApplications(Collection $applications)
499
    {
500
        $this->applications = $applications;
501
        return $this;
502
    }
503
    /**
504
     * (non-PHPdoc)
505
     * @see \Jobs\Entity\JobInterface::getApplications()
506
     */
507
    public function getApplications()
508
    {
509
        return $this->applications;
510
    }
511
    /**
512
     * Gets the number of unread applications
513
     * @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...
514
     */
515
    public function getUnreadApplications()
516
    {
517
        return $this->unreadApplications;
518
    }
519
    /**
520
     * (non-PHPdoc)
521
     * @see \Jobs\Entity\JobInterface::getLink()
522
     */
523
    public function getLink()
524
    {
525
        return $this->link;
526
    }
527
    /**
528
     * (non-PHPdoc)
529
     * @see \Jobs\Entity\JobInterface::setLink()
530
     */
531
    public function setLink($link)
532
    {
533
        $this->link = $link;
534
        return $this;
535
    }
536
    /**
537
     * (non-PHPdoc)
538
     * @see \Jobs\Entity\JobInterface::getDatePublishStart()
539
     */
540
    public function getDatePublishStart()
541
    {
542
        return $this->datePublishStart;
543
    }
544
    /**
545
     * (non-PHPdoc)
546
     * @param string $datePublishStart
547
     * @see \Jobs\Entity\JobInterface::setDatePublishStart()
548
     * @return $this
549
     */
550
    public function setDatePublishStart($datePublishStart)
551
    {
552
        $this->datePublishStart = $datePublishStart;
553
        return $this;
554
    }
555
556
    /**
557
     * Modifies the state of an application.
558
     *
559
     * Creates a history entry.
560
     *
561
     * @param StatusInterface|string $status
562
     * @param string $message
563
     * @return Job
564
     */
565 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...
566
    {
567
        $this->setStatus($status);
0 ignored issues
show
Bug introduced by
It seems like $status defined by parameter $status on line 565 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...
568
        $status = $this->getStatus(); // ensure StatusEntity
569
570
        $history = new History($status, $message);
571
572
        $this->getHistory()->add($history);
573
        return $this;
574
    }
575
576
    /**
577
     * (non-PHPdoc)
578
     * @see \Jobs\Entity\JobInterface::getStatus()
579
     */
580
    public function getStatus()
581
    {
582
        return $this->status;
583
    }
584
    /**
585
     * (non-PHPdoc)
586
     * @see \Jobs\Entity\JobInterface::setStatus()
587
     */
588
    public function setStatus($status)
589
    {
590
        if (!$status instanceof Status) {
591
            $status = new Status($status);
592
        }
593
        $this->status = $status;
594
    }
595
596
    /**
597
     * {@inheritDoc}
598
     * @see JobInterface::setHistory()
599
     * @return Job
600
     */
601
    public function setHistory(Collection $history)
602
    {
603
        $this->history = $history;
604
        return $this;
605
    }
606
607
    /**
608
     * {@inheritDoc}
609
     * @see JobInterface::getHistory()
610
     */
611
    public function getHistory()
612
    {
613
        if (null == $this->history) {
614
            $this->setHistory(new ArrayCollection());
615
        }
616
        return $this->history;
617
    }
618
619
    /**
620
     * {@inheritDoc}
621
     * @see JobInterface::setTermsAccepted()
622
     * @return self
623
     */
624
    public function setTermsAccepted($termsAccepted)
625
    {
626
        $this->termsAccepted = $termsAccepted;
627
        return $this;
628
    }
629
630
    /**
631
     * {qinheritDoc}
632
     * @see JobInterface::getTermsAccepted()
633
     */
634
    public function getTermsAccepted()
635
    {
636
        return $this->termsAccepted;
637
    }
638
639
    /**
640
     * (non-PHPdoc)
641
     * @see JobInterface::getReference()
642
     */
643
    public function getReference()
644
    {
645
        return $this->reference;
646
    }
647
    /**
648
     * (non-PHPdoc)
649
     * @see JobInterface::setReference()
650
     */
651
    public function setReference($reference)
652
    {
653
        $this->reference = $reference;
654
        return $this;
655
    }
656
657
    public function setAtsMode(AtsMode $mode)
658
    {
659
        $this->atsMode = $mode;
660
661
        return $this;
662
    }
663
664
    public function getAtsMode()
665
    {
666
        if (!$this->atsMode) {
667
            $this->setAtsMode(new AtsMode(AtsMode::MODE_INTERN));
668
        }
669
670
        return $this->atsMode;
671
    }
672
673
674
    /**
675
     * checks, weather a job is enabled for getting applications
676
     * @return boolean
677
     */
678
    public function getAtsEnabled()
679
    {
680
        return $this->atsEnabled;
681
    }
682
    /**
683
     * enables a job add to receive applications
684
     *
685
     * @param boolean $atsEnabled
686
     * @return \Jobs\Entity\Job
687
     */
688
    public function setAtsEnabled($atsEnabled)
689
    {
690
        $this->atsEnabled = $atsEnabled;
691
        return $this;
692
    }
693
    /**
694
     * returns an uri to the organization logo
695
     *
696
     * @deprecated
697
     * @return string
698
     */
699
    public function getLogoRef()
700
    {
701
        /** @var $organization \Organizations\Entity\Organization */
702
        $organization = $this->organization;
703
        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...
704
            $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...
705
            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...
706
        }
707
        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...
708
    }
709
    /**
710
     * Set the uri to the organisations logo
711
     *
712
     * @deprecated
713
     * @param string $logoRef
714
     * @return \Jobs\Entity\Job
715
     */
716
    public function setLogoRef($logoRef)
717
    {
718
        $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...
719
        return $this;
720
    }
721
722
    /**
723
     *
724
     *
725
     * @return string
726
     */
727
    public function getTemplate()
728
    {
729
        $template = $this->template;
730
        if (empty($template)) {
731
            $template = 'default';
732
        }
733
        return $template;
734
    }
735
    /**
736
     *
737
     *
738
     * @param string $template name of the Template
739
     * @return \Jobs\Entity\Job
740
     */
741
    public function setTemplate($template)
742
    {
743
        $this->template = $template;
744
        return $this;
745
    }
746
747
748
749
    /**
750
     * Gets the uri of an application link
751
     *
752
     * @return String
753
     */
754
    public function getUriApply()
755
    {
756
        return $this->uriApply;
757
    }
758
759
    /**
760
     * Sets the uri of an application link
761
     *
762
     * @param String $uriApply
763
     * @return \Jobs\Entity\Job
764
     */
765
    public function setUriApply($uriApply)
766
    {
767
        $this->uriApply = $uriApply;
768
        return $this;
769
    }
770
771
    /**
772
     * Gets the uri of a publisher
773
     *
774
     * @return String
775
     */
776
    public function getUriPublisher()
777
    {
778
        return $this->uriPublisher;
779
    }
780
    /**
781
     *
782
     * @param String $uriPublisher
783
     * @return \Jobs\Entity\Job
784
     */
785
    public function setUriPublisher($uriPublisher)
786
    {
787
        $this->uriPublisher = $uriPublisher;
788
        return $this;
789
    }
790
791
    /**
792
     * @param $key
793
     * @return mixed
794
     */
795
    public function getPublisher($key)
796
    {
797
        $result = null;
798
        foreach ($this->publisher as $publisher) {
799
            if ($publisher->host == $key) {
800
                $result = $publisher;
801
            }
802
        }
803
        if (!isset($result)) {
804
            $result = new Publisher();
805
            $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...
806
            $this->publisher[] = $result;
807
        }
808
        return $result;
809
    }
810
811
    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...
812
    {
813
        $publisher = $this->getPublisher($key);
814
        $publisher->reference;
815
        return $this;
816
    }
817
818
    /**
819
     * Get a list of fieldnames, which can be searched by keywords
820
     *
821
     * @return array
822
     */
823
    public function getSearchableProperties()
824
    {
825
        return array('title', 'company', 'location', 'applyId', 'reference');
826
    }
827
    
828
    /**
829
     * (non-PHPdoc)
830
     * @see \Core\Entity\SearchableEntityInterface::setKeywords()
831
     */
832
    public function setKeywords(array $keywords)
833
    {
834
        $this->keywords = $keywords;
835
        return $this;
836
    }
837
    
838
    /**
839
     * (non-PHPdoc)
840
     * @see \Core\Entity\SearchableEntityInterface::getKeywords()
841
     */
842
    public function getKeywords()
843
    {
844
        return $this->keywords;
845
    }
846
    
847
    /**
848
     * (non-PHPdoc)
849
     * @see \Core\Entity\SearchableEntityInterface::clearKeywords()
850
     */
851
    public function clearKeywords()
852
    {
853
        $this->keywords = array();
854
        return $this;
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