Completed
Push — develop ( b559a4...dfd31d )
by
unknown
10:04
created

NewApplication::setReciptient()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
rs 8.2222
cc 7
eloc 12
nc 6
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 Auth\Entity\UserInterface;
14
use Jobs\Entity\JobInterface;
15
use Core\Mail\StringTemplateMessage;
16
use Organizations\Entity\EmployeeInterface;
17
18
/**
19
 * Sends Information about a new Application to the recruiter
20
 *
21
 * Class NewApplication
22
 * @package Applications\Mail
23
 */
24
class NewApplication extends StringTemplateMessage
25
{
26
    /**
27
     * Job posting
28
     *
29
     * @var \Jobs\Entity\Job $job
30
     */
31
    protected $job;
32
33
    /**
34
     * Owner of the job posting
35
     *
36
     * @var \Auth\Entity\User $user
37
     */
38
    protected $user;
39
40
    /**
41
     * Organization Admin
42
     *
43
     * @var bool|\Auth\Entity\User $admin
44
     */
45
    protected $admin;
46
47
    /**
48
     * @var bool
49
     */
50
    private $callInitOnSetJob = false;
51
52
    /**
53
     * @param array $options
54
     */
55
    public function __construct(array $options = array())
56
    {
57
        parent::__construct($options);
58
        $this->callInitOnSetJob = true;
59
    }
60
    
61
    public function init()
62
    {
63
        if (!$this->job) {
64
            return false;
65
        }
66
67
        /* @var \Auth\Entity\Info $userInfo */
68
        $userInfo = $this->user->getInfo();
69
        $name = $userInfo->getDisplayName();
70
        if ('' == trim($name)) {
71
            $name = $userInfo->getEmail();
72
        }
73
        
74
        $variables = [
75
            'name' => $name,
76
            'title' => $this->job->getTitle()
77
        ];
78
79
        $this->setTo($this->user->getInfo()->getEmail(), $this->user->getInfo()->getDisplayName());
80
81
        $this->setVariables($variables);
82
        $subject = /*@translate*/ 'New application for your vacancy "%s"';
83
84
        if ($this->isTranslatorEnabled()) {
85
            $subject = $this->getTranslator()->translate($subject);
86
        }
87
        $this->setSubject(sprintf($subject, $this->job->getTitle()));
88
        
89
        /* @var \Applications\Entity\Settings $settings */
90
        $settings = $this->user->getSettings('Applications');
91
92
        $body = $settings->getMailAccessText();
0 ignored issues
show
Documentation Bug introduced by
The method getMailAccessText does not exist on object<Applications\Entity\Settings>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
93
        if ('' == $body) {
94
            $body = /*@translate*/ "Hello ##name##,\n\nThere is a new application for your vacancy:\n\"##title##\"\n\n";
95
            if ($this->isTranslatorEnabled()) {
96
                $body = $this->getTranslator()->translate($body);
97
            }
98
        }
99
        
100
        $this->setBody($body);
101
        return $this;
102
    }
103
104
    /**
105
     * @param JobInterface $job
106
     * @param bool $init
107
     * @return $this
108
     */
109
    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...
110
    {
111
        $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...
112
        if ($this->callInitOnSetJob) {
113
            $this->init();
114
        }
115
        return $this;
116
    }
117
118
    /**
119
     * @param \Auth\Entity\User $user
120
     * @return $this
121
     */
122
    public function setUser($user)
123
    {
124
        $this->user=$user;
125
        return $this;
126
    }
127
}
128