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

TokenProcessor::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
ccs 8
cts 8
cp 1
crap 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