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

CustomerManager::getCurrentUserByApiKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 9.4285
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