Passed
Push — main ( ccc364...bce7d4 )
by Karl
06:19
created

Journal::removeOrganization()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
namespace App\Entity;
4
5
use ApiPlatform\Metadata\ApiResource;
6
use App\Repository\JournalRepository;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\DBAL\Types\Types;
10
use Doctrine\ORM\Mapping as ORM;
11
12
#[ORM\Entity(repositoryClass: JournalRepository::class)]
13
#[ApiResource]
14
class Journal
15
{
16
    #[ORM\Id]
17
    #[ORM\GeneratedValue]
18
    #[ORM\Column]
19
    private ?int $id = null;
20
21
    #[ORM\Column(type: Types::DATE_MUTABLE)]
22
    private ?\DateTimeInterface $FirstDay = null;
23
24
    #[ORM\Column(type: Types::DATE_MUTABLE)]
25
    private ?\DateTimeInterface $LastDay = null;
26
27
    #[ORM\Column(length: 255, nullable: true)]
28
    private ?string $ChartOfAccount = null;
29
30
    /**
31
     * @var Collection<int, JournalEntry>
32
     */
33
    #[ORM\OneToMany(targetEntity: JournalEntry::class, mappedBy: 'Journal', orphanRemoval: true)]
34
    private Collection $journalEntries;
35
36
    /**
37
     * @var Collection<int, Organization>
38
     */
39
    #[ORM\ManyToOne(targetEntity: Organization::class, inversedBy: 'journals')]
40
    private ?Organization $organization = null;
41
42
    public function __construct()
43
    {
44
        $this->journalEntries = new ArrayCollection();
45
    }
46
47
    public function getId(): ?int
48
    {
49
        return $this->id;
50
    }
51
52
    public function getFirstDay(): ?\DateTimeInterface
53
    {
54
        return $this->FirstDay;
55
    }
56
57
    public function setFirstDay(\DateTimeInterface $FirstDay): static
58
    {
59
        $this->FirstDay = $FirstDay;
60
61
        return $this;
62
    }
63
64
    public function getLastDay(): ?\DateTimeInterface
65
    {
66
        return $this->LastDay;
67
    }
68
69
    public function setLastDay(\DateTimeInterface $LastDay): static
70
    {
71
        $this->LastDay = $LastDay;
72
73
        return $this;
74
    }
75
76
    public function getChartOfAccount(): ?string
77
    {
78
        return $this->ChartOfAccount;
79
    }
80
81
    public function setChartOfAccount(?string $ChartOfAccount): static
82
    {
83
        $this->ChartOfAccount = $ChartOfAccount;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return Collection<int, JournalEntry>
90
     */
91
    public function getJournalEntries(): Collection
92
    {
93
        return $this->journalEntries;
94
    }
95
96
    public function addJournalEntry(JournalEntry $journalEntry): static
97
    {
98
        if (!$this->journalEntries->contains($journalEntry)) {
99
            $this->journalEntries->add($journalEntry);
100
            $journalEntry->setJournal($this);
101
        }
102
103
        return $this;
104
    }
105
106
    public function removeJournalEntry(JournalEntry $journalEntry): static
107
    {
108
        if ($this->journalEntries->removeElement($journalEntry)) {
109
            // set the owning side to null (unless already changed)
110
            if ($journalEntry->getJournal() === $this) {
111
                $journalEntry->setJournal(null);
112
            }
113
        }
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return Collection<int, Organization>
120
     */
121
    public function getOrganization(): Collection
122
    {
123
        return $this->organization;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->organization returns the type App\Entity\Organization|null which is incompatible with the type-hinted return Doctrine\Common\Collections\Collection.
Loading history...
124
    }
125
126
    public function setOrganization(?Organization $organization): void
127
    {
128
        $this->organization = $organization;
0 ignored issues
show
Documentation Bug introduced by
It seems like $organization can also be of type App\Entity\Organization. However, the property $organization is declared as type Doctrine\Common\Collections\Collection. 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...
129
    }
130
}
131