Completed
Push — develop ( a3bac5...6cab8d )
by
unknown
07:34
created

NewApplication::init()   C

Complexity

Conditions 9
Paths 25

Size

Total Lines 47
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 47
rs 5.2941
cc 9
eloc 26
nc 25
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** NewApplication.php */
11
namespace Applications\Mail;
12
13
use Jobs\Entity\JobInterface;
14
use Core\Mail\StringTemplateMessage;
15
16
/**
17
 * Sends Information about a new Application to the recruiter
18
 *
19
 * Class NewApplication
20
 * @package Applications\Mail
21
 */
22
class NewApplication extends StringTemplateMessage
23
{
24
    /**
25
     * Job posting
26
     *
27
     * @var \Jobs\Entity\Job $job
28
     */
29
    protected $job;
30
31
    /**
32
     * Owner of the job posting
33
     *
34
     * @var \Auth\Entity\User $user
35
     */
36
    protected $user;
37
38
    /**
39
     * Organization Admin
40
     *
41
     * @var bool|\Auth\Entity\User $admin
42
     */
43
    protected $admin;
44
45
    /**
46
     * @var bool
47
     */
48
    private $callInitOnSetJob = false;
49
50
    /**
51
     * @param array $options
52
     */
53
    public function __construct(array $options = array())
54
    {
55
        parent::__construct($options);
56
        $this->callInitOnSetJob = true;
57
    }
58
    
59
    public function init()
60
    {
61
        if (!$this->job) {
62
            return false;
63
        }
64
65
        $userInfo = $this->user->getInfo();
66
        $name = $userInfo->getDisplayName();
67
        if ('' == trim($name)) {
68
            $name = $userInfo->getEmail();
69
        }
70
        
71
        $variables = array(
72
            'name' => $name,
73
            'title' => $this->job->getTitle()
74
        );
75
        
76
        $this->setTo($userInfo->getEmail(), $name != $userInfo->getEmail() ? $name : null);
77
78
        if ($this->admin && $this->admin->getSettings('Applications')->getMailBCC()) {
79
            $this->addBcc($this->admin->info->email, $this->admin->info->displayName);
80
        }
81
82
        $this->setVariables($variables);
83
        $subject = /*@translate*/ 'New application for your vacancy "%s"';
84
85
        if ($this->isTranslatorEnabled()) {
86
            $subject = $this->getTranslator()->translate($subject);
87
        }
88
        $this->setSubject(sprintf($subject, $this->job->getTitle()));
89
        
90
        /* @todo settings retrieved from user entity is an array
91
         *       not an entity.
92
         */
93
        $settings = $this->user->getSettings('Applications');
94
95
        $body = $settings->getMailAccessText();
96
        if ('' == $body) {
97
            $body = /*@translate*/ "Hello ##name##,\n\nThere is a new application for your vacancy:\n\"##title##\"\n\n";
98
            if ($this->isTranslatorEnabled()) {
99
                $body = $this->getTranslator()->translate($body);
100
            }
101
        }
102
        
103
        $this->setBody($body);
104
        return $this;
105
    }
106
107
    /**
108
     * @param JobInterface $job
109
     * @param bool $init
110
     * @return $this
111
     */
112
    public function setJob(JobInterface $job, $init = true)
0 ignored issues
show
Unused Code introduced by
The parameter $init 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...
113
    {
114
        $this->job = $job;
0 ignored issues
show
Documentation Bug introduced by
$job is of type object<Jobs\Entity\JobInterface>, but the property $job was declared to be of type object<Jobs\Entity\Job>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
115
        if ($this->callInitOnSetJob) {
116
            $this->init();
117
        }
118
        return $this;
119
    }
120
121
    /**
122
     * @param \Auth\Entity\User $user
123
     * @return $this
124
     */
125
    public function setUser($user)
126
    {
127
        $this->user=$user;
128
        return $this;
129
    }
130
131
    /**
132
     * @param \Auth\Entity\User $admin
133
     * @return $this
134
     */
135
    public function setAdmin($admin)
136
    {
137
        $this->admin = $admin;
138
        return $this;
139
    }
140
}