Completed
Push — master ( bcdba8...408d98 )
by Jan
03:54
created

NamedDBElement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 67
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A setName() 0 5 1
A getName() 0 6 1
1
<?php
2
/**
3
 *
4
 * part-db version 0.1
5
 * Copyright (C) 2005 Christoph Lechner
6
 * http://www.cl-projects.de/
7
 *
8
 * part-db version 0.2+
9
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
10
 * http://code.google.com/p/part-db/
11
 *
12
 * Part-DB Version 0.4+
13
 * Copyright (C) 2016 - 2019 Jan Böhmer
14
 * https://github.com/jbtronics
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
29
 *
30
 */
31
32
declare(strict_types=1);
33
/**
34
 * Part-DB Version 0.4+ "nextgen"
35
 * Copyright (C) 2016 - 2019 Jan Böhmer
36
 * https://github.com/jbtronics.
37
 *
38
 * This program is free software; you can redistribute it and/or
39
 * modify it under the terms of the GNU General Public License
40
 * as published by the Free Software Foundation; either version 2
41
 * of the License, or (at your option) any later version.
42
 *
43
 * This program is distributed in the hope that it will be useful,
44
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
 * GNU General Public License for more details.
47
 *
48
 * You should have received a copy of the GNU General Public License
49
 * along with this program; if not, write to the Free Software
50
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
51
 */
52
53
namespace App\Entity\Base;
54
55
use Doctrine\ORM\Mapping as ORM;
56
use Symfony\Component\Validator\Constraints as Assert;
57
use Symfony\Component\Serializer\Annotation\Groups;
58
59
/**
60
 * All subclasses of this class have an attribute "name".
61
 *
62
 * @ORM\MappedSuperclass()
63
 * @ORM\HasLifecycleCallbacks()
64
 */
65
abstract class NamedDBElement extends DBElement
66
{
67
68
    use TimestampTrait;
69
70
    /**
71
     * @var string The name of this element.
72
     * @ORM\Column(type="string")
73
     * @Assert\NotBlank()
74
     * @Groups({"simple", "extended", "full"})
75
     */
76
    protected $name = '';
77
78
    /********************************************************************************
79
     *
80
     *   Getters
81
     *
82
     *********************************************************************************/
83
84
    /**
85
     * Get the name.
86
     *
87
     * @return string the name of this element
88
     */
89
    public function getName(): string
90
    {
91
        /*
92
        //Strip HTML from Name, so no XSS injection is possible.
93
        return strip_tags($this->name); */
94
        return $this->name;
95
    }
96
97
    /********************************************************************************
98
     *
99
     *   Setters
100
     *
101
     *********************************************************************************/
102
103
    /**
104
     * Change the name of this element.
105
     *
106
     *     Spaces at the begin and at the end of the string will be removed
107
     *          automatically in NamedDBElement::check_values_validity().
108
     *          So you don't have to do this yourself.
109
     *
110
     * @param string $new_name the new name
111
     *
112
     * @return self
113
     */
114
    public function setName(string $new_name): self
115
    {
116
        $this->name = $new_name;
117
118
        return $this;
119
    }
120
121
    /******************************************************************************
122
     *
123
     * Helpers
124
     *
125
     ******************************************************************************/
126
127
128
129
    public function __toString()
130
    {
131
        return $this->getName();
132
    }
133
}
134