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

AzineMailgunCockpitService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getLastKnownSenderIp() 0 10 2
A getEmailDomain() 0 4 1
A getValueOrEmptyString() 0 4 2
A getCockpitDataAsArray() 0 7 1
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
}