Passed
Push — master ( 38c83e...e008f3 )
by Petr
03:05
created

Link::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
crap 6
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 int
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
    public function __construct(string $url, string $description = null, HashGenerator $hashGenerator = null)
42
    {
43
        $hashGenerator = $hashGenerator ?: new HashGenerator();
44
        $this->id = $hashGenerator::generate(self::ID_HASH_LENGTH);
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type integer, but $hashGenerator::generate(self::ID_HASH_LENGTH) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
45
        $this->url = $url;
46
        $this->description = $description;
47
    }
48
}
49