Completed
Push — develop ( 653438...89207c )
by
unknown
25:46 queued 13:01
created

Job::getAtsMode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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