Sentinel::getUserFieldValue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 6
loc 6
rs 9.4285
cc 3
eloc 3
nc 3
nop 0
1
<?php namespace Sofa\Revisionable\Adapters;
2
3
use Sofa\Revisionable\UserProvider;
4
use Cartalyst\Sentinel\Sentinel as SentinelProvider;
5
6 View Code Duplication
class Sentinel 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\Sentinel\Sentinel
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 Sentinel.
24
     *
25
     * @param SentinelProvider $provider
26
     * @param string $field
27
     */
28
    public function __construct(SentinelProvider $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