Dating::setCard()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Repository\DatingRepository;
8
use Application\Utility;
9
use Cake\Chronos\Chronos;
0 ignored issues
show
Bug introduced by
The type Cake\Chronos\Chronos was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Doctrine\ORM\Mapping as ORM;
11
use GraphQL\Doctrine\Attribute as API;
12
13
/**
14
 * An exact dating period expressed in Julian Days and automatically computed
15
 * from an approximate, lose string value.
16
 *
17
 * Julian days are used instead of standard date format because MariaDB does not
18
 * support older year than 1000 and we are often much older than that (before Christ)
19
 */
20
#[ORM\Entity(DatingRepository::class)]
21
class Dating extends AbstractModel
22
{
23
    #[ORM\Column(name: '`from`', type: 'integer')]
24
    private int $from;
25
26
    #[ORM\Column(name: '`to`', type: 'integer')]
27
    private int $to;
28
29
    #[ORM\JoinColumn(onDelete: 'CASCADE', nullable: false)]
30
    #[ORM\ManyToOne(targetEntity: Card::class, inversedBy: 'datings')]
31
    private ?Card $card = null;
32
33
    /**
34
     * Return the automatically computed beginning of dating period.
35
     */
36 40
    public function getFrom(): Chronos
37
    {
38 40
        return Utility::julianToDate($this->from);
39
    }
40
41 41
    #[API\Exclude]
42
    public function setFrom(Chronos $from): void
43
    {
44 41
        $this->from = Utility::dateToJulian($from);
45
    }
46
47
    /**
48
     * Return the automatically computed end of dating period.
49
     */
50 39
    public function getTo(): Chronos
51
    {
52 39
        return Utility::julianToDate($this->to);
53
    }
54
55 41
    #[API\Exclude]
56
    public function setTo(Chronos $to): void
57
    {
58 41
        $this->to = Utility::dateToJulian($to);
59
    }
60
61 1
    public function getCard(): Card
62
    {
63 1
        return $this->card;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->card could return the type null which is incompatible with the type-hinted return Application\Model\Card. Consider adding an additional type-check to rule them out.
Loading history...
64
    }
65
66 4
    public function setCard(Card $card): void
67
    {
68 4
        if ($this->card) {
69 1
            $this->card->datingRemoved($this);
70
        }
71
72 4
        $this->card = $card;
73 4
        $this->card->datingAdded($this);
74
    }
75
}
76