HasRichTextName   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 47
ccs 7
cts 11
cp 0.6364
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A __construct() 0 3 1
A setName() 0 4 1
A setPlainName() 0 2 1
A getPlainName() 0 3 1
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