Failed Conditions
Push — master ( 5fbadf...673c47 )
by Adrien
07:14
created

AccountingDocument::setTransaction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 5
cp 0
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Doctrine\ORM\Mapping as ORM;
8
9
/**
10
 * A document attesting an expense claim
11
 *
12
 * @ORM\HasLifecycleCallbacks
13
 * @ORM\Entity(repositoryClass="Application\Repository\AccountingDocumentRepository")
14
 */
15
class AccountingDocument extends AbstractFile
16
{
17 3
    protected function getBasePath(): string
18
    {
19 3
        return 'data/accounting/';
20
    }
21
22 1
    protected function getAcceptedMimeTypes(): array
23
    {
24
        return [
25 1
            'image/bmp',
26
            'image/gif',
27
            'image/jpeg',
28
            'image/pjpeg',
29
            'image/png',
30
            'image/webp',
31
            'application/pdf',
32
            'application/x-pdf',
33
        ];
34
    }
35
36
    /**
37
     * @var ExpenseClaim
38
     *
39
     * @ORM\ManyToOne(targetEntity="ExpenseClaim", inversedBy="accountingDocuments")
40
     * @ORM\JoinColumns({
41
     *     @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
42
     * })
43
     */
44
    private $expenseClaim;
45
46
    /**
47
     * @var Transaction
48
     *
49
     * @ORM\ManyToOne(targetEntity="Transaction", inversedBy="accountingDocuments")
50
     * @ORM\JoinColumns({
51
     *     @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
52
     * })
53
     */
54
    private $transaction;
55
56
    /**
57
     * @param null|ExpenseClaim $expenseClaim
58
     */
59 7
    public function setExpenseClaim(?ExpenseClaim $expenseClaim): void
60
    {
61 7
        if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) {
62 1
            $this->expenseClaim->accountingDocumentRemoved($this);
63
        }
64
65 7
        $this->expenseClaim = $expenseClaim;
66 7
        $expenseClaim->accountingDocumentAdded($this);
0 ignored issues
show
Bug introduced by
The method accountingDocumentAdded() does not exist on null. ( Ignorable by Annotation )

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

66
        $expenseClaim->/** @scrutinizer ignore-call */ 
67
                       accountingDocumentAdded($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67 7
    }
68
69
    /**
70
     * @return null|ExpenseClaim
71
     */
72 4
    public function getExpenseClaim(): ?ExpenseClaim
73
    {
74 4
        return $this->expenseClaim;
75
    }
76
77
    /**
78
     * @param null|Transaction $transaction
79
     */
80
    public function setTransaction(?Transaction $transaction): void
81
    {
82
        if ($this->transaction && $transaction !== $this->transaction) {
83
            $this->transaction->accountingDocumentRemoved($this);
84
        }
85
86
        $this->transaction = $transaction;
87
        $transaction->accountingDocumentAdded($this);
0 ignored issues
show
Bug introduced by
The method accountingDocumentAdded() does not exist on null. ( Ignorable by Annotation )

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

87
        $transaction->/** @scrutinizer ignore-call */ 
88
                      accountingDocumentAdded($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
    }
89
90
    /**
91
     * @return null|Transaction
92
     */
93
    public function getTransaction(): ?Transaction
94
    {
95
        return $this->transaction;
96
    }
97
}
98