Completed
Push — master ( fdd157...c7fad4 )
by Wachter
15:08
created

UserObject::getSlug()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ElasticsearchActivityLogBundle\Document;
13
14
use Ferrandini\Urlizer;
15
use ONGR\ElasticsearchBundle\Annotation\Object;
16
use ONGR\ElasticsearchBundle\Annotation\Property;
17
use Sulu\Component\Security\Authentication\UserInterface;
18
19
/**
20
 * @Object
21
 */
22
class UserObject
23
{
24
    /**
25
     * @var int
26
     *
27
     * @Property(type="integer")
28
     */
29
    public $id;
30
31
    /**
32
     * @var string
33
     *
34
     * @Property(
35
     *     type="string",
36
     *     options={
37
     *         "fields":{
38
     *            "raw":{"type":"string", "index":"not_analyzed"},
39
     *            "folded":{"type":"string", "analyzer":"folding"},
40
     *            "value":{"type":"string"}
41
     *         }
42
     *     }
43
     * )
44
     */
45
    public $username;
46
47
    /**
48
     * Set data.
49
     *
50
     * @param UserInterface $user
51
     *
52
     * @return $this
53
     */
54
    public function setData(UserInterface $user)
55
    {
56
        $this->id = $user->getId();
57
        $this->username = $user->getUsername();
58
59
        return $this;
60
    }
61
62
    /**
63
     * Return username slug.
64
     *
65
     * @param string $fallback
66
     *
67
     * @return string
68
     */
69
    public function getSlug($fallback = 'user')
70
    {
71
        return Urlizer::urlize($this->username) ?: $fallback;
72
    }
73
74
    public function __toString()
75
    {
76
        return $this->username;
77
    }
78
}
79