Passed
Push — master ( da72f5...6369ee )
by Jan
04:43
created

AbstractNamedDBElement::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20
 */
21
22
declare(strict_types=1);
23
24
namespace App\Entity\Base;
25
26
use App\Entity\Contracts\NamedElementInterface;
27
use Doctrine\ORM\Mapping as ORM;
28
use Symfony\Component\Serializer\Annotation\Groups;
29
use Symfony\Component\Validator\Constraints as Assert;
30
31
/**
32
 * All subclasses of this class have an attribute "name".
33
 *
34
 * @ORM\MappedSuperclass(repositoryClass="App\Repository\UserRepository")
35
 * @ORM\HasLifecycleCallbacks()
36
 */
37
abstract class AbstractNamedDBElement extends AbstractDBElement implements NamedElementInterface
38
{
39
    use TimestampTrait;
40
41
    /**
42
     * @var string The name of this element.
43
     * @ORM\Column(type="string")
44
     * @Assert\NotBlank()
45
     * @Groups({"simple", "extended", "full"})
46
     */
47
    protected $name = '';
48
49
    /******************************************************************************
50
     *
51
     * Helpers
52
     *
53
     ******************************************************************************/
54
55
    public function __toString()
56
    {
57
        return $this->getName();
58
    }
59
60
    /********************************************************************************
61
     *
62
     *   Getters
63
     *
64
     *********************************************************************************/
65
66
    /**
67
     * Get the name of this element.
68
     *
69
     * @return string the name of this element
70
     */
71
    public function getName(): string
72
    {
73
        return $this->name;
74
    }
75
76
    /********************************************************************************
77
     *
78
     *   Setters
79
     *
80
     *********************************************************************************/
81
82
    /**
83
     * Change the name of this element.
84
     *
85
     * @param string $new_name the new name
86
     *
87
     * @return self
88
     */
89
    public function setName(string $new_name): self
90
    {
91
        $this->name = $new_name;
92
93
        return $this;
94
    }
95
}
96