HasRichTextName::getPlainName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Traits;
6
7
use Application\Utility;
8
use Doctrine\ORM\Mapping as ORM;
9
10
/**
11
 * Trait for all objects with a rich text name and an automatic plain version (to sort and filter on).
12
 */
13
trait HasRichTextName
14
{
15
    #[ORM\Column(type: 'string', length: 191)]
16
    private string $name = '';
17
18
    #[ORM\Column(type: 'string', length: 191, options: ['default' => ''])]
19
    private string $plainName = '';
20
21
    /**
22
     * @param string $name
23
     */
24
    public function __construct($name = '')
25
    {
26
        $this->setName($name);
27
    }
28
29
    /**
30
     * Set name.
31
     */
32 49
    public function setName(string $name): void
33
    {
34 49
        $this->name = Utility::sanitizeSingleLineRichText($name);
35 49
        $this->plainName = Utility::richTextToPlainText($this->name);
36
    }
37
38
    /**
39
     * Set plain name.
40
     */
41 7
    public function setPlainName(string $plainName): void
0 ignored issues
show
Unused Code introduced by
The parameter $plainName is not used and could be removed. ( Ignorable by Annotation )

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

41
    public function setPlainName(/** @scrutinizer ignore-unused */ string $plainName): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        // Do nothing, plain name is automatically generated from name.
44 7
    }
45
46
    /**
47
     * Get name.
48
     */
49 16
    public function getName(): string
50
    {
51 16
        return $this->name;
52
    }
53
54
    /**
55
     * Get plain name.
56
     */
57
    public function getPlainName(): string
58
    {
59
        return $this->plainName;
60
    }
61
}
62