Passed
Push — master ( 9bf05d...919c2e )
by Jan
04:43
created

getReplyToMailForDepartment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/*
3
 * Copyright (C) 2020  Jan Böhmer
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace App\Services;
20
21
use App\Entity\Department;
22
use App\Entity\PaymentOrder;
23
24
class ReplyEmailDecisonMaker
25
{
26
    private $fsb_email;
27
    private $hhv_email;
28
29
    public function __construct(string $fsb_email, string $hhv_email)
30
    {
31
        $this->fsb_email = $fsb_email;
32
        $this->hhv_email = $hhv_email;
33
    }
34
35
    /**
36
     * Returns the reply-to email address for the given department
37
     * @param  Department  $department
38
     * @return string
39
     */
40
    public function getReplyToMailForDepartment(Department $department): string
41
    {
42
        return $department->isFSR() ? $this->fsb_email : $this->hhv_email;
43
    }
44
45
    /**
46
     * Returns the reply-to email address for the given payment order
47
     * @param  PaymentOrder  $paymentOrder
48
     * @return string
49
     */
50
    public function getReplyToMailForPaymentOrder(PaymentOrder $paymentOrder): string
51
    {
52
        if ($paymentOrder->getDepartment() === null) {
53
            throw new \RuntimeException('$paymentOrder must have an department defined!');
54
        }
55
56
        return $this->getReplyToMailForDepartment($paymentOrder->getDepartment());
57
    }
58
59
}