Test Failed
Push — develop ( 90366f...812a46 )
by Adrien
28:16
created

TextElement   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 10.26 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
dl 8
loc 78
ccs 12
cts 20
cp 0.6
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setText() 0 5 1
A getHashCode() 0 5 1
A __construct() 0 4 1
A __clone() 8 8 3
A getFont() 0 3 1
A getText() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\RichText;
4
5
class TextElement implements ITextElement
6
{
7
    /**
8
     * Text.
9
     *
10
     * @var string
11
     */
12
    private $text;
13
14
    /**
15
     * Create a new TextElement instance.
16
     *
17
     * @param string $pText Text
18
     */
19 24
    public function __construct($pText = '')
20
    {
21
        // Initialise variables
22 24
        $this->text = $pText;
23 24
    }
24
25
    /**
26
     * Get text.
27
     *
28
     * @return string Text
29
     */
30 34
    public function getText()
31
    {
32 34
        return $this->text;
33
    }
34
35
    /**
36
     * Set text.
37
     *
38
     * @param $text string Text
39
     *
40
     * @return ITextElement
41
     */
42 30
    public function setText($text)
43
    {
44 30
        $this->text = $text;
45
46 30
        return $this;
47
    }
48
49
    /**
50
     * Get font.
51
     *
52
     * @return \PhpOffice\PhpSpreadsheet\Style\Font
53
     */
54
    public function getFont()
55
    {
56
        return null;
57
    }
58
59
    /**
60
     * Get hash code.
61
     *
62
     * @return string Hash code
63
     */
64 8
    public function getHashCode()
65
    {
66 8
        return md5(
67 8
            $this->text .
68 8
            __CLASS__
69
        );
70
    }
71
72
    /**
73
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
74
     */
75 View Code Duplication
    public function __clone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $vars = get_object_vars($this);
78
        foreach ($vars as $key => $value) {
79
            if (is_object($value)) {
80
                $this->$key = clone $value;
81
            } else {
82
                $this->$key = $value;
83
            }
84
        }
85
    }
86
}
87