Completed
Pull Request — master (#147)
by
unknown
15:03
created

CustomerManager   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 10
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCurrentUserByApiKey() 0 10 1
1
<?php
2
3
namespace AppBundle\Services;
4
5
use AppBundle\Entity\Customer;
6
use Symfony\Bridge\Doctrine\RegistryInterface;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
9
class CustomerManager
10
{
11
    protected $requestStack;
12
13
    protected $doctrine;
14
15
    public function __construct(RequestStack $requestStack, RegistryInterface $doctrine)
16
    {
17
        $this->requestStack = $requestStack;
18
        $this->doctrine = $doctrine;
19
    }
20
21
    /**
22
     * @return Customer
23
     */
24
    public function getCurrentUserByApiKey(): Customer
25
    {
26
        $em = $this->doctrine->getEntityManager();
27
        $apiKey = $this->requestStack->getCurrentRequest()->headers->get('API-Key-Token');
28
        $customer = $em
29
            ->getRepository('AppBundle:Customer')
30
            ->findOneBy(['apiKey' => $apiKey]);
31
32
        return $customer;
33
    }
34
}
35