Completed
Pull Request — master (#6)
by
unknown
02:35
created

AzineMailgunCockpitService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
4
namespace Azine\MailgunWebhooksBundle\Services;
5
6
use Azine\MailgunWebhooksBundle\Entity\Repositories\MailgunEventRepository;
7
8
class AzineMailgunCockpitService
9
{
10
    private $emailDomain;
11
    private $eventRepository;
12
    private $twig;
13
    
14
    private $cachedLastKnownIp;
15
    
16
    public function __construct(MailgunEventRepository $eventRepository, \Twig_Environment $twig, $emailDomain)
17
    {
18
        $this->emailDomain = $emailDomain;
19
        $this->eventRepository = $eventRepository;
20
        $this->twig = $twig;
21
    }
22
23
    public function getLastKnownSenderIp()
24
    {
25
        if (is_null($this->cachedLastKnownIp)) {                    
26
            $lastKnownIp = $this->eventRepository->getLastKnownSenderIp();
27
            $this->cachedLastKnownIp = $lastKnownIp;
28
        } else {
29
            $lastKnownIp = $this->cachedLastKnownIp;
30
        }
31
        return $this->getValueOrEmptyString($lastKnownIp);
32
    }
33
34
    public function getEmailDomain()
35
    {
36
        return $this->getValueOrEmptyString($this->emailDomain);
37
    }
38
39
    public function getCockpitDataAsArray()
40
    {
41
        return array(
42
            'lastKnownIp' => $this->getLastKnownSenderIp(),
43
            'emailDomain' => $this->getEmailDomain()
44
        );
45
    }
46
47
    private function getValueOrEmptyString($value)
48
    {
49
        return is_null($value) ? '' : $value;
50
    }
51
}