Completed
Push — sf/improvement-coverage ( b3937e...01a837 )
by Kiyotaka
51:20 queued 45:08
created

TokenProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 13 3
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Log\Processor;
15
16
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
17
18
class TokenProcessor
19
{
20
    /**
21
     * @var TokenStorageInterface
22
     */
23
    protected $tokenStorage;
24
25 1331
    public function __construct(TokenStorageInterface $tokenStorage)
26
    {
27 1331
        $this->tokenStorage = $tokenStorage;
28
    }
29
30 1331
    public function __invoke(array $records)
31
    {
32 1331
        $records['extra']['user_id'] = 'N/A';
33
34 1331
        if (null !== $token = $this->tokenStorage->getToken()) {
35 435
            $user = $token->getUser();
36 435
            $records['extra']['user_id'] = is_object($user)
37 352
                ? $user->getId()
38 145
                : $user;
39
        }
40
41 1331
        return $records;
42
    }
43
}
44