Completed
Push — master ( 49a6f0...9c36f0 )
by ARCANEDEV
04:39
created

User::firstHashedOrFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use Arcanedev\LaravelAuth\Models\User as BaseUserModel;
4
5
/**
6
 * Class     User
7
 *
8
 * @package  Arcanesoft\Auth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  string  gravatar
12
 */
13
class User extends BaseUserModel
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Getters & Setters
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Get the user hash id.
21
     *
22
     * @return string
23
     */
24
    public function getHashedIdAttribute()
25
    {
26
        return hasher()->encode($this->id);
27
    }
28
29
    /**
30
     * Get the gravatar attribute.
31
     *
32
     * @return string
33
     */
34
    public function getGravatarAttribute()
35
    {
36
        return gravatar()
37
            ->setDefaultImage('mm')->setSize(160)
38
            ->src($this->email);
39
    }
40
41
    /* ------------------------------------------------------------------------------------------------
42
     |  Main Function
43
     | ------------------------------------------------------------------------------------------------
44
     */
45
    /**
46
     * Get a user from a hashed id or fail if not found.
47
     *
48
     * @param  string  $hashedId
49
     *
50
     * @return self
51
     *
52
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
53
     */
54
    public static function firstHashedOrFail($hashedId)
55
    {
56
        $id = head(hasher()->decode($hashedId));
57
58
        return self::where('id', $id)->firstOrFail();
59
    }
60
}
61