Passed
Push — master ( 921011...5d9034 )
by Petr
04:49
created

Link::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use AppBundle\Service\HashGenerator;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * URL Link
10
 * @ORM\Table(name="links")
11
 * @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\LinkRepository")
12
 */
13
class Link
14
{
15
16
    const ID_HASH_LENGTH = 32;
17
18
    /**
19
     * @var string
20
     * @ORM\Column(name="id", type="string", length=32)
21
     * @ORM\Id
22
     */
23
    private $id;
24
25
    /**
26
     * @var string
27
     * @ORM\Column(name="url", type="string", length=255, unique=true)
28
     */
29
    private $url;
30
31
    /**
32
     * @var string
33
     * @ORM\Column(name="description", type="text", nullable=true)
34
     */
35
    private $description;
36
37
    /**
38
     * @param string $url
39
     * @param string $description
40
     */
41 2
    public function __construct(string $url, string $description = null, HashGenerator $hashGenerator = null)
42
    {
43 2
        $hashGenerator = $hashGenerator ?: new HashGenerator();
44 2
        $this->id = $hashGenerator::generate(self::ID_HASH_LENGTH);
45 2
        $this->url = $url;
46 2
        $this->description = $description;
47 2
    }
48
49 8
    public function getId(): string
50
    {
51 8
        return $this->id;
52
    }
53
54 7
    public function getUrl(): string
55
    {
56 7
        return $this->url;
57
    }
58
59
    /**
60
     * @return string|null
61
     */
62 7
    public function getDescription()
63
    {
64 7
        return $this->description;
65
    }
66
}
67