UserHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B buildUserData() 0 24 5
1
<?php
2
3
namespace Ftrrtf\RollbarBundle\Helper;
4
5
use Symfony\Component\Security\Core\User\UserInterface;
6
7
class UserHelper
8
{
9
    /**
10
     * Get current user info.
11
     *
12
     * @param string|UserInterface $user
13
     *
14
     * @return null|array
15
     */
16
    public function buildUserData($user)
17
    {
18
        if (is_string($user)) {
19
            return array(
20
                'id' => $user,
21
            );
22
        }
23
24
        if (!($user instanceof UserInterface)) {
25
            return array();
26
        }
27
28
        $userData['id'] = method_exists($user, 'getId')
29
            ? $user->getId()
30
            : $user->getUsername();
31
32
        $userData['username'] = $user->getUsername();
33
34
        if (method_exists($user, 'getEmail')) {
35
            $userData['email'] = $user->getEmail();
36
        }
37
38
        return $userData;
39
    }
40
}
41