JournalMove::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 12
cp 0
rs 9.2568
c 0
b 0
f 0
cc 5
nc 3
nop 5
crap 30
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Entity\Accounting;
12
13
use App\Entity\EntityInterface;
14
use App\Entity\Parking\Member;
15
use App\Entity\Traits;
16
use Doctrine\ORM\Mapping as ORM;
17
use PascalDeVink\ShortUuid\ShortUuid;
18
use Symfony\Component\Validator\Constraints as Assert;
19
20
/**
21
 * @ORM\Entity()
22
 * @ORM\Table(name="accounting_journal_moves")
23
 */
24
class JournalMove implements EntityInterface
25
{
26
    use Traits\PropertyIdGeneratedTrait;
27
28
    /**
29
     * @var int
30
     * @ORM\Column(name="given_points", type="integer", nullable=false)
31
     *
32
     * @Assert\PositiveOrZero()
33
     */
34
    private $givenPoints;
35
36
    /**
37
     * @var int
38
     * @ORM\Column(name="received_points", type="string", length=255, nullable=false)
39
     *
40
     * @Assert\PositiveOrZero()
41
     */
42
    private $receivedPoints;
43
44
    /**
45
     * @var \DateTimeImmutable
46
     * @ORM\Column(name="date", type="date_immutable", nullable=false)
47
     *
48
     * @Assert\Date()
49
     */
50
    private $date;
51
52
    //-------------------------------------------------------------------------------------------
53
54
    /**
55
     * @var Member
56
     * @ORM\ManyToOne(targetEntity="App\Entity\Parking\Member")
57
     * @ORM\JoinColumn(name="member_id", referencedColumnName="id", nullable=false)
58
     *
59
     * @Assert\NotNull()
60
     */
61
    private $member;
62
63
    /**
64
     * @var Journal
65
     * @ORM\ManyToOne(targetEntity="App\Entity\Accounting\Journal", inversedBy="journalMoves")
66
     * @ORM\JoinColumn(name="journal_id", referencedColumnName="id", nullable=false)
67
     *
68
     * @Assert\NotNull()
69
     */
70
    private $journal;
71
72
    //-------------------------------------------------------------------------------------------
73
74
    public function __construct(
75
        Journal $journal,
76
        Member $member,
77
        \DateTimeImmutable $date,
78
        int $givenPoints,
79
        int $receivedPoints
80
    ) {
81
        $this->id = ShortUuid::uuid4();
82
        $this->journal = $journal;
83
        $this->member = $member;
84
        $this->date = $date;
85
        $this->givenPoints = $givenPoints;
86
        $this->receivedPoints = $receivedPoints;
87
88
        if (0 === $givenPoints && 0 === $receivedPoints) {
89
            throw new \InvalidArgumentException('Given and Received points are 0');
90
        }
91
92
        if (0 !== $givenPoints && 0 !== $receivedPoints) {
93
            throw new \InvalidArgumentException('Given and Received points are not 0');
94
        }
95
    }
96
}
97