LogEntriesAwareTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getLogEntries() 0 3 1
A addLogEntry() 0 8 2
A hasLogEntries() 0 3 1
A removeLogEntry() 0 8 2
A hasLogEntry() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusLogEntryPlugin\Model;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
10
trait LogEntriesAwareTrait
11
{
12
    /** @var Collection|LogEntryInterface[] */
13
    protected $logEntries;
14
15
    public function __construct()
16
    {
17
        $this->logEntries = new ArrayCollection();
18
    }
19
20
    public function getLogEntries(): Collection
21
    {
22
        return $this->logEntries;
23
    }
24
25
    public function hasLogEntries(): bool
26
    {
27
        return !$this->logEntries->isEmpty();
28
    }
29
30
    public function addLogEntry(LogEntryInterface $logEntry): void
31
    {
32
        if ($this->hasLogEntry($logEntry)) {
33
            return;
34
        }
35
36
        $this->logEntries->add($logEntry);
37
        $logEntry->setOwner($this);
0 ignored issues
show
Bug introduced by
$this of type Setono\SyliusLogEntryPlu...el\LogEntriesAwareTrait is incompatible with the type Setono\SyliusLogEntryPlu...riesAwareInterface|null expected by parameter $owner of Setono\SyliusLogEntryPlu...ryInterface::setOwner(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $logEntry->setOwner(/** @scrutinizer ignore-type */ $this);
Loading history...
38
    }
39
40
    public function removeLogEntry(LogEntryInterface $logEntry): void
41
    {
42
        if (!$this->hasLogEntry($logEntry)) {
43
            return;
44
        }
45
46
        $this->logEntries->removeElement($logEntry);
47
        $logEntry->setOwner(null);
48
    }
49
50
    public function hasLogEntry(LogEntryInterface $logEntry): bool
51
    {
52
        return $this->logEntries->contains($logEntry);
53
    }
54
}
55