Sentry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 4 4 1
A __construct() 5 5 1
A getUserFieldValue() 6 6 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Sofa\Revisionable\Adapters;
2
3
use Sofa\Revisionable\UserProvider;
4
use Cartalyst\Sentry\Sentry as SentryProvider;
5
6 View Code Duplication
class Sentry implements UserProvider
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
{
8
    /**
9
     * Auth provider instance.
10
     *
11
     * @var \Cartalyst\Sentry\Sentry
12
     */
13
    protected $provider;
14
    
15
    /**
16
     * Field from the user to be saved as author of the action.
17
     *
18
     * @var string
19
     */
20
    protected $field;
21
    
22
    /**
23
     * Create adapter instance for Sentry.
24
     *
25
     * @param SentryProvider $provider
26
     * @param string $field
27
     */
28
    public function __construct(SentryProvider $provider, $field = null)
29
    {
30
        $this->provider = $provider;
31
        $this->field    = $field;
32
    }
33
34
    /**
35
     * Get identifier of the currently logged in user.
36
     *
37
     * @return string|null
38
     */
39
    public function getUser()
40
    {
41
        return $this->getUserFieldValue();
42
    }
43
44
    /**
45
     * Get value from the user to be saved as the author.
46
     *
47
     * @return string|null
48
     */
49
    protected function getUserFieldValue()
50
    {
51
        if ($user = $this->provider->getUser()) {
52
            return ($field = $this->field) ? (string) $user->{$field} : $user->getLogin();
53
        }
54
    }
55
}
56