Passed
Push — master ( 9f5a4d...eb071b )
by Jan
04:08
created

ElementDeletedLogEntry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOldName() 0 3 1
A __construct() 0 5 1
A setTargetElement() 0 7 2
A setOldName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
7
 *
8
 * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
23
 */
24
25
namespace App\Entity\LogSystem;
26
27
use App\Entity\Base\AbstractDBElement;
28
use App\Entity\Contracts\NamedElementInterface;
29
use Doctrine\ORM\Mapping as ORM;
30
31
/**
32
 * @ORM\Entity()
33
 */
34
class ElementDeletedLogEntry extends AbstractLogEntry
35
{
36
    protected $typeString = 'element_deleted';
37
38
    public function __construct(AbstractDBElement $deleted_element)
39
    {
40
        parent::__construct();
41
        $this->level = self::LEVEL_INFO;
42
        $this->setTargetElement($deleted_element);
43
    }
44
45
    /**
46
     * @inheritDoc
47
     * @return $this
48
     */
49
    public function setTargetElement(?AbstractDBElement $element): AbstractLogEntry
50
    {
51
        parent::setTargetElement($element);
52
        if ($element instanceof NamedElementInterface) {
53
            $this->setOldName($element->getName());
54
        }
55
        return $this;
56
    }
57
58
    public function setOldName(string $old_name): self
59
    {
60
        $this->extra['n'] = $old_name;
61
        return $this;
62
    }
63
64
    public function getOldName(): string
65
    {
66
        return $this->extra['n'];
67
    }
68
}
69