HttpBasicUserProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 39
ccs 11
cts 13
cp 0.8462
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUser() 0 16 4
1
<?php
2
3
/*
4
 * This file is part of the "Kata 1" package.
5
 *
6
 * Copyright (c) Daniel González
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author Daniel González <[email protected]>
12
 */
13
14
namespace App\Security\Http;
15
16
use Component\Http\Request;
17
18
use App\Repository\UserRepository;
19
20
/**
21
 * HttpBasicUserProvider.
22
 */
23
class HttpBasicUserProvider
24
{
25
    /**
26
     * @var UserRepository
27
     */
28
    protected $repository;
29
30
    /**
31
     * HttpBasicUserProvider constructor.
32
     *
33
     * @param UserRepository $repository
34
     */
35 9
    public function __construct(UserRepository $repository)
36
    {
37 9
        $this->repository = $repository;
38 9
    }
39
40
    /**
41
     * @param Request|null $request
42
     *
43
     * @return \App\Model\User|false
44
     */
45 9
    public function getUser(Request $request = null)
46
    {
47 9
        if (!$request) {
48
            return;
49
        }
50 9
        $token = base64_decode($request->getHeader('Authorization'));
51 9
        if (!$token) {
52 4
            return;
53
        }
54 5
        if (!strpos($token, ':')) {
55
            return;
56
        }
57 5
        list($name, $password) = explode(':', $token);
58
59 5
        return $this->repository->findByNameAndPassword($name, $password);
60
    }
61
}
62