Passed
Pull Request — master (#5)
by Paweł
03:08
created

Course::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Entity;
4
5
use App\Model\CourseInterface;
6
use App\Model\TimeLimitedAwareTrait;
7
use App\Model\TimestampableAwareTrait;
8
use App\Model\VisibilityAwareTrait;
9
use Symfony\Component\HttpFoundation\File\File;
10
11
class Course implements CourseInterface
12
{
13
    use TimestampableAwareTrait, VisibilityAwareTrait, TimeLimitedAwareTrait;
14
15
    private $id;
16
17
    private $title;
18
19
    private $description;
20
21
    private $coverImageName;
22
23
    /**
24
     * Hack for PropertyInfo issues with File.
25
     *
26
     * @var null
27
     */
28
    private $coverImageFile;
29
30
    public function __construct()
31
    {
32
        $this->visible = true;
33
    }
34
35
    public function getId(): ?int
36
    {
37
        return $this->id;
38
    }
39
40
    public function getTitle(): ?string
41
    {
42
        return $this->title;
43
    }
44
45
    public function setTitle(string $title): void
46
    {
47
        $this->title = $title;
48
    }
49
50
    public function getDescription(): ?string
51
    {
52
        return $this->description;
53
    }
54
55
    public function setDescription(string $description): void
56
    {
57
        $this->description = $description;
58
    }
59
60
    public function getCoverImageName(): ?string
61
    {
62
        return $this->coverImageName;
63
    }
64
65
    public function setCoverImageName(?string $coverImageName): void
66
    {
67
        $this->coverImageName = $coverImageName;
68
    }
69
70
    public function setCoverImageFile(?File $coverImageFile = null): void
71
    {
72
        $this->coverImageFile = $coverImageFile;
0 ignored issues
show
Documentation Bug introduced by
It seems like $coverImageFile can also be of type Symfony\Component\HttpFoundation\File\File. However, the property $coverImageFile is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
73
        $this->updated = new \DateTime();
74
    }
75
76
    public function getCoverImageFile(): ?File
77
    {
78
        return $this->coverImageFile;
79
    }
80
81
    public function __toString()
82
    {
83
        return (string) $this->title;
84
    }
85
}
86