| 1 | <?php |
||
| 2 | |||
| 3 | namespace Azine\MailgunWebhooksBundle\Services; |
||
| 4 | |||
| 5 | use Azine\MailgunWebhooksBundle\Entity\MailgunEvent; |
||
| 6 | use Azine\MailgunWebhooksBundle\Entity\Repositories\MailgunEventRepository; |
||
| 7 | use Symfony\Bridge\Doctrine\ManagerRegistry; |
||
| 8 | |||
| 9 | class AzineMailgunCockpitService |
||
| 10 | { |
||
| 11 | private $emailDomain; |
||
| 12 | /** @var ManagerRegistry */ |
||
| 13 | private $managerRegistry; |
||
| 14 | /** @var \Twig_Environment */ |
||
| 15 | private $twig; |
||
| 16 | |||
| 17 | private $cachedLastKnownIp; |
||
| 18 | |||
| 19 | public function __construct(ManagerRegistry $managerRegistry, \Twig_Environment $twig, $emailDomain) |
||
| 20 | { |
||
| 21 | $this->emailDomain = $emailDomain; |
||
| 22 | $this->managerRegistry = $managerRegistry; |
||
| 23 | $this->twig = $twig; |
||
| 24 | } |
||
| 25 | |||
| 26 | public function getLastKnownSenderIp() |
||
| 27 | { |
||
| 28 | if (is_null($this->cachedLastKnownIp)) { |
||
| 29 | /** @var MailgunEventRepository $eventRepository */ |
||
| 30 | $eventRepository = $this->managerRegistry->getRepository(MailgunEvent::class); |
||
| 31 | $lastKnownIp = null; |
||
| 32 | $ipAddressData = $eventRepository->getLastKnownSenderIpData(); |
||
|
0 ignored issues
–
show
|
|||
| 33 | |||
| 34 | if (isset($ipAddressData['id'])) { |
||
| 35 | $lastKnownIp = $ipAddressData['id']; |
||
| 36 | } |
||
| 37 | |||
| 38 | $this->cachedLastKnownIp = $lastKnownIp; |
||
| 39 | } else { |
||
| 40 | $lastKnownIp = $this->cachedLastKnownIp; |
||
| 41 | } |
||
| 42 | |||
| 43 | return $this->getValueOrEmptyString($lastKnownIp); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function getEmailDomain() |
||
| 47 | { |
||
| 48 | return $this->getValueOrEmptyString($this->emailDomain); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function getCockpitDataAsArray() |
||
| 52 | { |
||
| 53 | return array( |
||
| 54 | 'lastKnownIp' => $this->getLastKnownSenderIp(), |
||
| 55 | 'emailDomain' => $this->getEmailDomain(), |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | |||
| 59 | private function getValueOrEmptyString($value) |
||
| 60 | { |
||
| 61 | return is_null($value) ? '' : $value; |
||
| 62 | } |
||
| 63 | } |
||
| 64 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.